ia64/xen-unstable

changeset 985:acc6520a4d4f

bitkeeper revision 1.638 (3fca7788evQFw3E81lBB0aqsSAxjwA)

Slightly more complicated example script
author iap10@labyrinth.cl.cam.ac.uk
date Sun Nov 30 23:04:40 2003 +0000 (2003-11-30)
parents d63f2c8a7f71
children c27b19a9ea1d
files .rootkeys tools/examples/mynewdom.py
line diff
     1.1 --- a/.rootkeys	Sun Nov 30 23:02:25 2003 +0000
     1.2 +++ b/.rootkeys	Sun Nov 30 23:04:40 2003 +0000
     1.3 @@ -42,6 +42,7 @@ 3e6377dbGcgnisKw16DPCaND7oGO3Q tools/bal
     1.4  3fbe2f12OPAkzIUtumU3wRAihnhocQ tools/examples/createlinuxdom.py
     1.5  3fbe2f12dZbmXLlgQdMgkmnSUj23AQ tools/examples/destroydom.py
     1.6  3fbe2f12ltvweb13kBSsxqzZDAq4sg tools/examples/listdoms.py
     1.7 +3fca7788tBihusQSq3HJI-YKQTN2iQ tools/examples/mynewdom.py
     1.8  3fca7700PVj36cZObaFZlQicRiw1pQ tools/examples/pincpu.py
     1.9  3fbe2f12Bnt8mwmr1ZCP6HWGS6yvYw tools/examples/stopdom.py
    1.10  3f776bd2Xd-dUcPKlPN2vG89VGtfvQ tools/misc/Makefile
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/examples/mynewdom.py	Sun Nov 30 23:04:40 2003 +0000
     2.3 @@ -0,0 +1,113 @@
     2.4 +#!/usr/bin/env python
     2.5 +
     2.6 +#
     2.7 +# Example script for creating and building a new Linux guest OS for Xen.
     2.8 +#
     2.9 +
    2.10 +import Xc, XenoUtil, sys, os, socket, re
    2.11 +
    2.12 +# Variable declaration. Set these up properly later on, as needed.
    2.13 +nfsserv = nfspath = root_partn = usr_partn = ""
    2.14 +shost = re.search( '([a-zA-Z]+)[-.]', socket.gethostname() ).group(1)
    2.15 +
    2.16 +# STEP 1. Specify kernel image file.
    2.17 +image = "/usr/groups/srgboot/%s/xenolinux.gz" % shost
    2.18 +
    2.19 +# STEP 2. How many megabytes of memory for the new domain?
    2.20 +memory_megabytes = 64
    2.21 +
    2.22 +# STEP 3. A handy name for your new domain.
    2.23 +domain_name = "My new domain"
    2.24 +
    2.25 +# Allocate new domain
    2.26 +xc = Xc.new()
    2.27 +id = xc.domain_create( mem_kb=memory_megabytes*1024, name=domain_name )
    2.28 +if id <= 0:
    2.29 +    print "Error creating domain"
    2.30 +    sys.exit()
    2.31 +
    2.32 +# Set the CPU, or leave to round robin
    2.33 +#xc.domain_pincpu( dom=id, cpu=1 )
    2.34 +
    2.35 +# STEP 4. Specify IP address, netmask and gateway for the new domain.
    2.36 +ipaddr  = XenoUtil.add_to_ip(XenoUtil.addr_of_iface('eth0'),id)
    2.37 +netmask = XenoUtil.get_current_ipmask()
    2.38 +gateway = XenoUtil.get_current_ipgw()
    2.39 +
    2.40 +# STEP 5a. Specify NFS server and path to rootfs (only needed for network boot)
    2.41 +#nfsserv = "ADDRESS"
    2.42 +#nfspath = "FULL_PATH_TO_ROOT_DIR"
    2.43 +
    2.44 +# STEP 5b. Specify root partition on local disc (if not NFS booting)
    2.45 +root_partn = "/dev/sda%d" % (7+id)
    2.46 +# (NB. The following is only needed for a separate shared read-only /usr)
    2.47 +usr_partn  = "/dev/sda6"
    2.48 +
    2.49 +# STEP 6. Check that the following cmdline setup is to your taste.
    2.50 +cmdline = "ip="+ipaddr+":"+nfsserv+":"+gateway+":"+netmask+"::eth0:off"
    2.51 +if root_partn:
    2.52 +    # Boot from local disc. May specify a separate /usr.
    2.53 +    cmdline = cmdline + " root="+root_partn+" ro"
    2.54 +    if usr_partn:
    2.55 +        " usr="+usr_partn
    2.56 +elif nfsserv:
    2.57 +    # NFS boot
    2.58 +    cmdline = cmdline + " root=/dev/nfs"
    2.59 +    cmdline = cmdline + " nfsroot="+nfspath
    2.60 +
    2.61 +if root_partn:
    2.62 +    root_info = XenoUtil.lookup_blkdev_partn_info(root_partn)
    2.63 +    if not root_info:
    2.64 +        print "Could not obtain info on partition '" + root_partn + "'"
    2.65 +        sys.exit()
    2.66 +
    2.67 +if usr_partn:
    2.68 +    usr_info = XenoUtil.lookup_blkdev_partn_info(usr_partn)
    2.69 +    if not usr_info:
    2.70 +        print "Could not obtain info on partition '" + usr_partn + "'"
    2.71 +        sys.exit()
    2.72 +
    2.73 +if not os.path.isfile( image ):
    2.74 +    print "Image file '" + image + "' does not exist"
    2.75 +    sys.exit()
    2.76 +
    2.77 +
    2.78 +if xc.linux_build( dom=id, image=image, cmdline=cmdline ):
    2.79 +    print "Error building Linux guest OS"
    2.80 +    xc.domain_destroy ( dom=id )
    2.81 +    sys.exit()
    2.82 +
    2.83 +if root_partn:
    2.84 +    if xc.vbd_create( dom=id, vbd=root_info[0], writeable=1 ):
    2.85 +        print "Error creating root VBD"
    2.86 +        xc.domain_destroy ( dom=id )
    2.87 +        sys.exit()
    2.88 +    if xc.vbd_add_extent( dom=id,
    2.89 +                          vbd=root_info[0],
    2.90 +                          device=root_info[1],
    2.91 +                          start_sector=root_info[2],
    2.92 +                          nr_sectors=root_info[3] ):
    2.93 +        print "Error populating root VBD"
    2.94 +        xc.domain_destroy ( dom=id )
    2.95 +        sys.exit()
    2.96 +
    2.97 +if usr_partn:
    2.98 +    if xc.vbd_create( dom=id, vbd=usr_info[0], writeable=0 ):
    2.99 +        print "Error creating usr VBD"
   2.100 +        xc.domain_destroy ( dom=id )
   2.101 +        sys.exit()
   2.102 +    if xc.vbd_add_extent( dom=id,
   2.103 +                          vbd=usr_info[0],
   2.104 +                          device=usr_info[1],
   2.105 +                          start_sector=usr_info[2],
   2.106 +                          nr_sectors=usr_info[3] ):
   2.107 +        print "Error populating usr VBD"
   2.108 +        xc.domain_destroy ( dom=id )
   2.109 +        sys.exit()
   2.110 +
   2.111 +XenoUtil.setup_vfr_rules_for_vif( id, 0, ipaddr )
   2.112 +
   2.113 +if xc.domain_start( dom=id ):
   2.114 +    print "Error starting domain"
   2.115 +    xc.domain_destroy ( dom=id )
   2.116 +    sys.exit()