#!/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 )

onos_version='1.0.0'

# 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/new-onos-tutorial;f=vm-setup-lxc.sh'
    vm.sendline( ' wget -O vm-setup-lxc.sh "%s" | bash' % url ) # space prefix is used to avoid entry in history
    vm.expect( prompt, timeout=20 )
    vm.sendline( 'bash vm-setup-lxc.sh' )
    vm.expect( prompt, timeout=3600 )

    """
    vm.sendline('sudo su - tutorial1')
    vm.expect(prompt, timeout=20) 
    vm.sendline( 'git clone https://gerrit.onosproject.org/onos' )
    vm.expect( prompt, timeout=30 )
    vm.sendline( 'cd onos && git checkout %s && cd -' % onos_version )


    vm.expect( prompt, timeout=1200 )
  
     
    vm.sendline('ssh 127.0.0.1')
    vm.expect('.*connecting (yes/no)?')
    vm.sendline('yes')
    vm.expect(prompt, timeout=30)
    vm.sendline('exit')
    
    vm.expect( prompt, timeout=1200 )
   
    url = 'https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial;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)
    vm.sendline('exit')
    vm.expect(prompt, timeout=20) 
    """
    

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' ) )
