#!/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', 'admin' )
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 install( vm, scriptFileName='install-base.sh', 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=%s' % scriptFileName
    vm.sendline( ' wget -O %s "%s" | bash' % (scriptFileName, url) ) # space prefix is used to avoid entry in history
    vm.expect( prompt, timeout=20 )
    vm.sendline( 'bash %s' % scriptFileName )
    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 buildOnosVm( image, out, scriptFileName, vmname='ONOS', vminfo='ONOS VM', 
                 flavor='utopic64server', installMemory=4096, cpuCores=4, ovfMemory=4096  ):

    bootAndRun( image, runFunction=install, scriptFileName=scriptFileName, memory=installMemory, cpuCores=cpuCores, 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=vmname, vminfo=vminfo )
    log( '* Generated OVF descriptor file', ovf )

if __name__ == '__main__':
    parser = argparse.ArgumentParser( description='ONOS 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', required=True,
                         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)' )
    parser.add_argument( '-s', '--script', required=True,
                         help='Install script filename' )
    parser.add_argument( '--vmname', default='ONOS',
                         help='Name of the generated VM image')
    parser.add_argument( '--vminfo', default='ONOS VM',
                         help='Short description of the VM')
    args = parser.parse_args()

    print args

    buildOnosVm( args.image, args.out, args.script, vmname=args.vmname, vminfo=args.vminfo, flavor=args.flavor)

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