~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/examples/democd

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
##### Edit this python file to reflect the configuration of your system
3
 
 
4
 
##### This example script requires variable 'ip' to be set, and optionally
5
 
##### netmask and gatewaty for the kernel command line
6
 
 
7
 
def config_usage ():
8
 
    print >>sys.stderr, """
9
 
The config file %s requires the following vars to be defined:
10
 
 ip               -- List of IP addr(s) for Xen to route to domain 
11
 
                     e.g. '-Dip=1.2.3.4,5.6.7.8'
12
 
The following variables may be optionally defined:
13
 
 mem              -- Adjust initial memory allocation (default 64MB)
14
 
 netmask          -- Override gateway for kernel ip= command line
15
 
 gateway          -- Override network for kernel ip= command line
16
 
""" % config_file
17
 
 
18
 
try:
19
 
    ip
20
 
except:
21
 
    print "Set variable 'ip' using '-Dip=1.2.3.4,5.6.7.8'"
22
 
    assert()
23
 
 
24
 
# STEP 1. Specify kernel image file and otional ramdisk. Can be gzip'ed.
25
 
image   = "/boot/xenolinux.gz"
26
 
ramdisk = "/boot/initrd.gz"
27
 
builder_fn='linux' # this is a linux domain
28
 
 
29
 
# STEP 2. The initial memory allocation (in megabytes) for the new domain.
30
 
try:
31
 
    mem_size = int(mem)
32
 
except NameError:
33
 
    mem_size = 64
34
 
 
35
 
 
36
 
# STEP 3. A handy name for your new domain.
37
 
# appends either first hostname or last quad of first IP address dependant on value passed
38
 
 
39
 
quads = string.split(ip, '.')
40
 
if len(quads) == 4:                                     # fragile heuristic for valid IP verification
41
 
        domain_name = "Xen VM .%s" % quads[3]           # use last quad of IP
42
 
else:
43
 
        domain_name = "Xen VM: %s" % ip                 # use hostname passed in
44
 
 
45
 
 
46
 
# STEP 4. Specify IP address(es), for the new domain.  You need to
47
 
# configure IP addrs within the domain just as you do normally.  This
48
 
# is just to let Xen know about them so it can route packets
49
 
# appropriately.
50
 
 
51
 
#vfr_ipaddr = ["111.222.333.444","222.333.444.555"]
52
 
#vfr_ipaddr  = [XenoUtil.add_offset_to_ip(XenoUtil.get_current_ipaddr(),vmid)]
53
 
vfr_ipaddr  = map(socket.gethostbyname,string.split(ip,','))
54
 
 
55
 
 
56
 
 
57
 
# STEP 5a. Identify any physcial partitions or virtual disks you want the
58
 
# domain to have access to, and what you want them accessible as
59
 
# e.g. vbd_list = [ ('phy:sda1','sda1', 'w'),
60
 
#        ('phy:sda%d' % (3+vmid), 'hda2', 'r'), 
61
 
#        ('vd:as73gd784dh','hda1','w'),
62
 
#        ('phy:cdrom','hdd','r')
63
 
 
64
 
vbd_list = [ ('phy:cdrom','hdd','r' ) ]
65
 
 
66
 
 
67
 
 
68
 
# STEP 5b. Set the VBD expertise level.  Most people should leave this
69
 
# on 0, at least to begin with - this script can detect most dangerous
70
 
# disk sharing between domains and with this set to zero it will only
71
 
# allow read only sharing.
72
 
 
73
 
vbd_expert = 0
74
 
 
75
 
 
76
 
# STEP 6. Build the command line for the new domain. Edit as req'd.
77
 
# You only need the ip= line if you're NFS booting or the root file system
78
 
# doesn't set it later e.g. in ifcfg-eth0 or via DHCP
79
 
# You can use 'extrabit' to set the runlevel and custom environment
80
 
# variables used by custom rc scripts (e.g. VMID=, usr= )
81
 
 
82
 
 
83
 
# see if we have a local IP at all
84
 
localip=''
85
 
for i in vfr_ipaddr:
86
 
    if XenoUtil.check_subnet(i,'169.254.0.0','255.255.0.0'):
87
 
        localip=i
88
 
        break
89
 
 
90
 
 
91
 
# if either netmask and gateway has been set from the command line,
92
 
# associate it with the first IP address that has been specified.
93
 
 
94
 
myip = ''
95
 
 
96
 
try: 
97
 
    netmask = socket.gethostbyname( netmask )
98
 
    gateway = socket.gethostbyname( gateway )
99
 
    myip = vfr_ipaddr[0]
100
 
 
101
 
except NameError:
102
 
    netmask = XenoUtil.get_current_ipmask()
103
 
    gateway = XenoUtil.get_current_ipgw()
104
 
 
105
 
# if we haven't got an address, see if we have one that matches the LAN
106
 
 
107
 
if not myip:
108
 
    if netmask and gateway:
109
 
        for i in vfr_ipaddr:
110
 
            if XenoUtil.check_subnet(i,gateway,netmask): 
111
 
                myip=i
112
 
                break
113
 
 
114
 
# if we still haven't got an address, see if there's a link local one
115
 
 
116
 
if not myip and localip:
117
 
    myip = localip
118
 
    netmask = '255.255.0.0'
119
 
    gateway = '169.254.1.0'
120
 
 
121
 
 
122
 
# As a final fallback, through everything down the interface
123
 
 
124
 
if not myip:
125
 
    myip = vfr_ipaddr[0]
126
 
    netmask = '0.0.0.0' 
127
 
    gateway = '' 
128
 
 
129
 
# Calculate the components with which we will build the command line
130
 
 
131
 
nfsserv = '169.254.1.0'  
132
 
 
133
 
cmdline_ip="ip="+myip+":"+nfsserv+":"+gateway+":"+netmask+"::eth0:off"
134
 
cmdline_root  = "root=/dev/ram0 rw init=/linuxrc"
135
 
 
136
 
if localip:
137
 
    cmdline_extra = "4 LOCALIP=%s" % localip
138
 
else:
139
 
    cmdline_extra = "4"
140
 
 
141
 
# STEP 7. Set according to whether you want the script to watch the domain 
142
 
# and auto-restart it should it die or exit.
143
 
 
144
 
auto_restart = False
145
 
#auto_restart = True