build.py: making ovf generation more generic
This commit is contained in:
+16
-12
@@ -158,7 +158,7 @@ def depend():
|
|||||||
run( 'sudo apt-get -y update' )
|
run( 'sudo apt-get -y update' )
|
||||||
run( 'sudo apt-get install -y'
|
run( 'sudo apt-get install -y'
|
||||||
' kvm cloud-utils genisoimage qemu-kvm qemu-utils'
|
' kvm cloud-utils genisoimage qemu-kvm qemu-utils'
|
||||||
' e2fsprogs dnsmasq'
|
' e2fsprogs dnsmasq curl'
|
||||||
' python-setuptools mtools zip' )
|
' python-setuptools mtools zip' )
|
||||||
run( 'sudo easy_install pexpect' )
|
run( 'sudo easy_install pexpect' )
|
||||||
|
|
||||||
@@ -457,16 +457,16 @@ def boot( cow, kernel, initrd, logfile, memory=1024 ):
|
|||||||
return vm
|
return vm
|
||||||
|
|
||||||
|
|
||||||
def login( vm ):
|
def login( vm, user='mininet', password='mininet' ):
|
||||||
"Log in to vm (pexpect object)"
|
"Log in to vm (pexpect object)"
|
||||||
log( '* Waiting for login prompt' )
|
log( '* Waiting for login prompt' )
|
||||||
vm.expect( 'login: ' )
|
vm.expect( 'login: ' )
|
||||||
log( '* Logging in' )
|
log( '* Logging in' )
|
||||||
vm.sendline( 'mininet' )
|
vm.sendline( user )
|
||||||
log( '* Waiting for password prompt' )
|
log( '* Waiting for password prompt' )
|
||||||
vm.expect( 'Password: ' )
|
vm.expect( 'Password: ' )
|
||||||
log( '* Sending password' )
|
log( '* Sending password' )
|
||||||
vm.sendline( 'mininet' )
|
vm.sendline( password )
|
||||||
log( '* Waiting for login...' )
|
log( '* Waiting for login...' )
|
||||||
|
|
||||||
|
|
||||||
@@ -628,9 +628,9 @@ OVFTemplate = """<?xml version="1.0"?>
|
|||||||
<Description>The nat network</Description>
|
<Description>The nat network</Description>
|
||||||
</Network>
|
</Network>
|
||||||
</NetworkSection>
|
</NetworkSection>
|
||||||
<VirtualSystem ovf:id="Mininet-VM">
|
<VirtualSystem ovf:id="%(vmname)s">
|
||||||
<Info>A Mininet Virtual Machine (%(name)s)</Info>
|
<Info>%(vminfo)s (%(name)s)</Info>
|
||||||
<Name>mininet-vm</Name>
|
<Name>%(vmname)s</Name>
|
||||||
<OperatingSystemSection ovf:id="%(osid)d">
|
<OperatingSystemSection ovf:id="%(osid)d">
|
||||||
<Info>The kind of installed guest operating system</Info>
|
<Info>The kind of installed guest operating system</Info>
|
||||||
<Description>%(osname)s</Description>
|
<Description>%(osname)s</Description>
|
||||||
@@ -640,10 +640,10 @@ OVFTemplate = """<?xml version="1.0"?>
|
|||||||
<Item>
|
<Item>
|
||||||
<rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
|
<rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
|
||||||
<rasd:Description>Number of Virtual CPUs</rasd:Description>
|
<rasd:Description>Number of Virtual CPUs</rasd:Description>
|
||||||
<rasd:ElementName>1 virtual CPU(s)</rasd:ElementName>
|
<rasd:ElementName>%(cpus)s virtual CPU(s)</rasd:ElementName>
|
||||||
<rasd:InstanceID>1</rasd:InstanceID>
|
<rasd:InstanceID>1</rasd:InstanceID>
|
||||||
<rasd:ResourceType>3</rasd:ResourceType>
|
<rasd:ResourceType>3</rasd:ResourceType>
|
||||||
<rasd:VirtualQuantity>1</rasd:VirtualQuantity>
|
<rasd:VirtualQuantity>%(cpus)s</rasd:VirtualQuantity>
|
||||||
</Item>
|
</Item>
|
||||||
<Item>
|
<Item>
|
||||||
<rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits>
|
<rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits>
|
||||||
@@ -694,19 +694,23 @@ OVFTemplate = """<?xml version="1.0"?>
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def generateOVF( name, osname, osid, diskname, disksize, mem=1024 ):
|
def generateOVF( name, osname, osid, diskname, disksize, mem=1024, cpus=1,
|
||||||
|
vmname='Mininet-VM', vminfo='A Mininet Virtual Machine' ):
|
||||||
"""Generate (and return) OVF file "name.ovf"
|
"""Generate (and return) OVF file "name.ovf"
|
||||||
name: root name of OVF file to generate
|
name: root name of OVF file to generate
|
||||||
osname: OS name for OVF (Ubuntu | Ubuntu 64-bit)
|
osname: OS name for OVF (Ubuntu | Ubuntu 64-bit)
|
||||||
osid: OS ID for OVF (93 | 94 )
|
osid: OS ID for OVF (93 | 94 )
|
||||||
diskname: name of disk file
|
diskname: name of disk file
|
||||||
disksize: size of virtual disk in bytes
|
disksize: size of virtual disk in bytes
|
||||||
mem: VM memory size in MB"""
|
mem: VM memory size in MB
|
||||||
|
cpus: # of virtual CPUs
|
||||||
|
vmname: Name for VM (default name when importing)
|
||||||
|
vmimfo: Brief description of VM for OVF"""
|
||||||
ovf = name + '.ovf'
|
ovf = name + '.ovf'
|
||||||
filesize = stat( diskname )[ ST_SIZE ]
|
filesize = stat( diskname )[ ST_SIZE ]
|
||||||
params = dict( osname=osname, osid=osid, diskname=diskname,
|
params = dict( osname=osname, osid=osid, diskname=diskname,
|
||||||
filesize=filesize, disksize=disksize, name=name,
|
filesize=filesize, disksize=disksize, name=name,
|
||||||
mem=mem )
|
mem=mem, cpus=cpus, vmname=vmname, vminfo=vminfo )
|
||||||
xmltext = OVFTemplate % params
|
xmltext = OVFTemplate % params
|
||||||
with open( ovf, 'w+' ) as f:
|
with open( ovf, 'w+' ) as f:
|
||||||
f.write( xmltext )
|
f.write( xmltext )
|
||||||
|
|||||||
Reference in New Issue
Block a user