Revision 662fb712 util/vm/build.py

View differences:

util/vm/build.py
35 35
from subprocess import check_output, call, Popen
36 36
from tempfile import mkdtemp
37 37
from time import time, strftime, localtime
38
from lxml import etree
38 39
import argparse
39 40

  
40 41
pexpect = None  # For code check - imported dynamically
......
47 48
isoURLs = {
48 49
    'precise32server':
49 50
    'http://mirrors.kernel.org/ubuntu-releases/12.04/'
50
    'ubuntu-12.04-server-i386.iso',
51
    'ubuntu-12.04.3-server-i386.iso',
51 52
    'precise64server':
52 53
    'http://mirrors.kernel.org/ubuntu-releases/12.04/'
53
    'ubuntu-12.04-server-amd64.iso',
54
    'ubuntu-12.04.3-server-amd64.iso',
54 55
    'quetzal32server':
55 56
    'http://mirrors.kernel.org/ubuntu-releases/12.10/'
56 57
    'ubuntu-12.10-server-i386.iso',
......
125 126
    if not path.exists( iso ) or ( stat( iso )[ ST_MODE ] & 0777 != 0444 ):
126 127
        log( '* Retrieving', url )
127 128
        run( 'curl -C - -o %s %s' % ( iso, url ) )
129
        if 'ISO' not in run( 'file ' + iso ):
130
            os.remove( iso )
131
            raise Exception( 'findiso: could not download iso from ' + url )
128 132
        # Write-protect iso, signaling it is complete
129 133
        log( '* Write-protecting iso', iso)
130 134
        os.chmod( iso, 0444 )
......
310 314
    # Mount iso so we can use its kernel
311 315
    mnt = mkdtemp()
312 316
    srun( 'mount %s %s' % ( iso, mnt ) )
313
    srun( 'ls ' + mnt )
314 317
    kernel = path.join( mnt, 'install/vmlinuz' )
315 318
    initrd = path.join( mnt, 'install/initrd.gz' )
316 319
    cmd = [ 'sudo', kvm,
......
450 453
    return vmdk
451 454

  
452 455

  
456
# Template for virt-image(5) file
457

  
458
VirtImageXML = """
459
<?xml version="1.0" encoding="UTF-8"?>
460
<image>
461
    <name>%s</name>
462
    <domain>
463
        <boot type="hvm">
464
            <guest>
465
                <arch>%s/arch>
466
            </guest>
467
            <os>
468
                <loader dev="hd"/>
469
            </os>
470
            <drive disk="root.raw" target="hda"/>
471
        </boot>
472
        <devices>
473
            <vcpu>1</vcpu>
474
            <memory>%s</memory>
475
            <interface/>
476
            <graphics/>
477
        </devices>
478
    </domain>
479
        <storage>
480
            <disk file="%s" size="%s" format="vmdk"/>
481
        </storage>
482
</image>
483
"""
484

  
485
def genVirtImage( name, mem, diskname, disksize ):
486
    "Generate and return virt-image file name.xml"
487
    # Our strategy is going to be: create a
488
    # virt-image file and then use virt-convert to convert
489
    # it to an .ovf file
490
    xmlfile = name + '.xml'
491
    xmltext = VirtImageXML % ( name, mem, diskname, disksize )
492
    with open( xmlfile, 'w+' ) as f:
493
        f.write( xmltext )
494
    return xmlfile
495

  
496

  
453 497
def build( flavor='raring32server' ):
454 498
    "Build a Mininet VM"
455 499
    start = time()

Also available in: Unified diff