#!/usr/bin/python

import os
import sys
import re
import argparse
from stat import ST_MODE, ST_SIZE
from subprocess import check_output

# Add the Mininet build script directory to the path, so we can import it
#TODO do a better job finding Mininet
path = os.path.join( '/home', 'mininet', 'mininet','util', 'vm' )
path = os.path.expanduser( path )
if os.path.isdir( path ):
    sys.path.append( path )
else:
    print 'Cannot find Mininet build script. Exiting...'
    sys.exit( 1 )

# Import required functions from the Mininet build script
from build import bootAndRun, Prompt, OVFOSNameID, generateOVF, log, build, run

def installONOS( vm, prompt=Prompt ):
    # start with sendline
    #TODO consider resizing the HDD
    url = 'https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.1;f=vm-setup.sh'
    vm.sendline( ' wget -O vm-setup.sh "%s" | bash' % url ) # space prefix is used to avoid entry in history
    vm.expect( prompt, timeout=20 )
    vm.sendline( 'bash vm-setup.sh' )
    vm.expect( prompt, timeout=3600 )
   
    url = 'https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.1;f=onos-setup.sh'
    vm.sendline( ' wget -O onos-setup.sh "%s" | bash' % url ) # space prefix is used to avoid entry in history
    vm.expect( prompt, timeout=20 )
    vm.sendline( 'bash onos-setup.sh' )
    vm.expect(prompt, timeout=3600)
    

def vmdk2size( vmdk ):
    "Return virtual disk size (in bytes) of vmdk image"
    output = check_output( [ 'file', vmdk ] )
    assert 'disk image' in output
    return os.stat( vmdk )[ ST_SIZE ]

def buildONOS( image, out, flavor='trusty64server', installMemory=2048, ovfMemory=4096  ):
    if not image:
        # build VM from flavor
        #build( flavor )
        pass

    bootAndRun( image, runFunction=installONOS, memory=installMemory, outputFile=out )

    size = vmdk2size( out + '.vmdk' ) # get vmdk size
    ovfname = out
    osname, osid = OVFOSNameID( flavor )
    print osname, osid

    ovf = generateOVF( name=ovfname, osname=osname, osid=osid,
                       diskname=out+'.vmdk', disksize=size, mem=ovfMemory, cpus=2,
                       vmname='ONOS-Tutorial', vminfo='ONOS Tutorial VM' )
    log( '* Generated OVF descriptor file', ovf )

if __name__ == '__main__':
    parser = argparse.ArgumentParser( description='Mininet Tutorial VM build script' )
    parser.add_argument( '-i', '--image', metavar='image', required=True,
                         help='Build from an existing VM image' )
    parser.add_argument( '-f', '--flavor', default='trusty64server',
                         help='VM flavor to build (e.g. trusty64server)' )
    parser.add_argument( 'scripts', nargs='*',
                         help='VM flavor(s) to build (e.g. trusty64server)' )
    parser.add_argument( '-z', '--zip', action='store_true',
                         help='archive .ovf and .vmdk into .zip file' )
    parser.add_argument( '-o', '--out', required=True,
                         help='output file for test image (vmdk)' )
    args = parser.parse_args()

    print args

    buildONOS( args.image, args.out )

    if args.zip:
        log( '* Generating .zip file' )
        run( 'zip %s-ovf.zip %s %s' % ( args.out, args.out + '.ovf', args.out + '.vmdk' ) )
