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

    
    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=2048  ):
    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' ) )
