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