
##### Edit this python file to reflect the configuration of your system

##### This example script requires variable 'ip' to be set, and optionally
##### netmask and gatewaty for the kernel command line

def config_usage ():
    print >>sys.stderr, """
The config file %s requires the following vars to be defined:
 ip               -- List of IP addr(s) for Xen to route to domain 
                     e.g. '-Dip=1.2.3.4,5.6.7.8'
The following variables may be optionally defined:
 mem              -- Adjust initial memory allocation (default 64MB)
 netmask          -- Override gateway for kernel ip= command line
 gateway          -- Override network for kernel ip= command line
""" % config_file

try:
    ip
except:
    print "Set variable 'ip' using '-Dip=1.2.3.4,5.6.7.8'"
    assert()

# STEP 1. Specify kernel image file and otional ramdisk. Can be gzip'ed.
image   = "/boot/xenolinux.gz"
ramdisk = "/boot/initrd.gz"
builder_fn='linux' # this is a linux domain

# STEP 2. The initial memory allocation (in megabytes) for the new domain.
try:
    mem_size = int(mem)
except NameError:
    mem_size = 64


# STEP 3. A handy name for your new domain.
# appends either first hostname or last quad of first IP address dependant on value passed

quads = string.split(ip, '.')
if len(quads) == 4:					# fragile heuristic for valid IP verification
	domain_name = "Xen VM .%s" % quads[3]		# use last quad of IP
else:
	domain_name = "Xen VM: %s" % ip			# use hostname passed in


# STEP 4. Specify IP address(es), for the new domain.  You need to
# configure IP addrs within the domain just as you do normally.  This
# is just to let Xen know about them so it can route packets
# appropriately.

#vfr_ipaddr = ["111.222.333.444","222.333.444.555"]
#vfr_ipaddr  = [XenoUtil.add_offset_to_ip(XenoUtil.get_current_ipaddr(),vmid)]
vfr_ipaddr  = map(socket.gethostbyname,string.split(ip,','))



# STEP 5a. Identify any physcial partitions or virtual disks you want the
# domain to have access to, and what you want them accessible as
# e.g. vbd_list = [ ('phy:sda1','sda1', 'w'),
#	 ('phy:sda%d' % (3+vmid), 'hda2', 'r'), 
#	 ('vd:as73gd784dh','hda1','w'),
#	 ('phy:cdrom','hdd','r')

vbd_list = [ ('phy:cdrom','hdd','r' ) ]



# STEP 5b. Set the VBD expertise level.  Most people should leave this
# on 0, at least to begin with - this script can detect most dangerous
# disk sharing between domains and with this set to zero it will only
# allow read only sharing.

vbd_expert = 0


# STEP 6. Build the command line for the new domain. Edit as req'd.
# You only need the ip= line if you're NFS booting or the root file system
# doesn't set it later e.g. in ifcfg-eth0 or via DHCP
# You can use 'extrabit' to set the runlevel and custom environment
# variables used by custom rc scripts (e.g. VMID=, usr= )


# see if we have a local IP at all
localip=''
for i in vfr_ipaddr:
    if XenoUtil.check_subnet(i,'169.254.0.0','255.255.0.0'):
	localip=i
	break


# if either netmask and gateway has been set from the command line,
# associate it with the first IP address that has been specified.

myip = ''

try: 
    netmask = socket.gethostbyname( netmask )
    gateway = socket.gethostbyname( gateway )
    myip = vfr_ipaddr[0]

except NameError:
    netmask = XenoUtil.get_current_ipmask()
    gateway = XenoUtil.get_current_ipgw()

# if we haven't got an address, see if we have one that matches the LAN

if not myip:
    if netmask and gateway:
	for i in vfr_ipaddr:
	    if XenoUtil.check_subnet(i,gateway,netmask): 
		myip=i
		break

# if we still haven't got an address, see if there's a link local one

if not myip and localip:
    myip = localip
    netmask = '255.255.0.0'
    gateway = '169.254.1.0'


# As a final fallback, through everything down the interface

if not myip:
    myip = vfr_ipaddr[0]
    netmask = '0.0.0.0' 
    gateway = '' 

# Calculate the components with which we will build the command line

nfsserv = '169.254.1.0'  

cmdline_ip="ip="+myip+":"+nfsserv+":"+gateway+":"+netmask+"::eth0:off"
cmdline_root  = "root=/dev/ram0 rw init=/linuxrc"

if localip:
    cmdline_extra = "4 LOCALIP=%s" % localip
else:
    cmdline_extra = "4"

# STEP 7. Set according to whether you want the script to watch the domain 
# and auto-restart it should it die or exit.

auto_restart = False
#auto_restart = True
