ia64/xen-unstable

view tools/python/xen/sv/CreateDomain.py @ 16739:33dcf04d7715

tools/docs: Fix example and default IP addresses.

In various places in documentation and code, IP addresses are provided
as examples, defaults, or dummy configuration. In general the
specific IP addresses used in Xen are not always appropriate. (For
example, 1.2.3.4 is used in a few places!)

The following addresses should be used:
* For examples and documentation, 192.0.2.0/24. (See RFC3330.)
* For defaults for private networks, a random network from RFC1918.
I have randomly selected 172.30.206.0/24 for this purpose and
documented this in at the only registry I know of,
www.ucam.org/cam-grin. This network should henceforth be used for
default configurations of local bridges, test networks, etc. in
Xen tools.

The following addresses should NOT be used:
* 10.0.*.*, 10.1.*.*, 192.168.0.*, 192.168.1.*, etc. Using these
addresses gives greatly increased likelihood of collision, as
ignorant network administrators and reckless middlebox vendors
often pick networks from the bottom of 10/8 and 192.168/16.
* 169.254.*.*. These are reserved for zeroconf (ad-hoc networking)
and should not be used for Xen private networks, bridges, etc.,
etc. Use of these addresses by Xen scripts causes trouble on hosts
(eg laptops) which find themselves in ad-hoc networking
environments. I think this is not hypothetical (!) since at least
one Linux distribution have specific code to detect this case and
cause Xen startup to fail iff the host already has an external
zeroconf address.
* 1.2.3.4. WTF !?

I have also used 127.0.255.255 in one place where apparently a dummy
address is needed (some Linux kernels won't accept a lack of an NFS
server address). If 127.0.255.255 is mistakenly used it is unlikely
to do any damage to real traffic even if it does escape into the
network at large.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jan 17 15:13:40 2008 +0000 (2008-01-17)
parents 386990d004b8
children
line source
1 from xen.sv.Wizard import *
2 from xen.sv.util import *
3 from xen.sv.GenTabbed import PreTab
5 from xen.xm.create import make_config, OptVals
7 from xen.xend.XendClient import server
9 class CreateDomain( Wizard ):
10 def __init__( self, urlWriter ):
12 sheets = [ CreatePage0,
13 CreatePage1,
14 CreatePage2,
15 CreatePage3,
16 CreatePage4,
17 CreateFinish ]
19 Wizard.__init__( self, urlWriter, "Create Domain", sheets )
21 def op_finish( self, request ):
22 pass
24 class CreatePage0( Sheet ):
26 title = "General"
28 def __init__( self, urlWriter ):
29 Sheet.__init__( self, urlWriter, "General", 0 )
30 self.addControl( InputControl( 'name', 'VM Name', 'VM Name:', "[\\w|\\S]+", "You must enter a name in this field" ) )
31 self.addControl( InputControl( 'memory', '64', 'Memory (Mb):', "[\\d]+", "You must enter a number in this field" ) )
32 self.addControl( InputControl( 'cpu', '0', 'CPU:', "[\\d]+", "You must enter a number in this feild" ) )
33 self.addControl( InputControl( 'cpu_weight', '1', 'CPU Weight:', "[\\d]+", "You must enter a number in this feild" ) )
34 self.addControl( InputControl( 'vcpus', '1', 'Virtual CPUs:', '[\\d]+', "You must enter a number in this feild") )
36 class CreatePage1( Sheet ):
38 title = "Setup Kernel Image"
40 def __init__( self, urlWriter ):
41 Sheet.__init__( self, urlWriter, "Setup Kernel Image", 1 )
42 self.addControl( ListControl( 'builder', [('linux', 'Linux'), ('netbsd', 'NetBSD')], 'Domain Builder:' ) )
43 self.addControl( FileControl( 'kernel', '/boot/vmlinuz-2.6.12-xenU', 'Kernel Image:' ) )
44 self.addControl( InputControl( 'extra', '', 'Kernel Command Line Parameters:' ) )
45 self.addControl( ListControl( 'use-initrd', [('yes', 'Yes'), ('no', 'No')], 'Use an Initial Ram Disk?:' ) )
46 self.addControl( FileControl( 'initrd', '/boot/initrd-2.6.12-xenU.img', 'Initial Ram Disk:' ) )
48 def validate( self, request ):
49 if not self.passback: self.parseForm( request )
50 check = True
51 request.write( previous_values.get( '>>>>>use-initrd' ) )
52 previous_values = ssxp2hash( string2sxp( self.passback ) ) #get the map for quick reference
53 if DEBUG: print previous_values
54 for (feild, control) in self.feilds:
55 if feild == 'initrd' and previous_values.get( 'use-initrd' ) != 'no':
56 request.write( previous_values.get( '>>>>>use-initrd' ) )
57 if control.validate( previous_values.get( feild ) ):
58 check = False
59 elif not control.validate( previous_values.get( feild ) ):
60 check = False
62 if DEBUG: print "> %s = %s" % (feild, previous_values.get( feild ))
64 return check
67 class CreatePage2( Sheet ):
69 title = "Choose number of VBDS"
71 def __init__( self, urlWriter ):
72 Sheet.__init__( self, urlWriter, "Setup Virtual Block Device", 2 )
73 self.addControl( InputControl( 'num_vbds', '1', 'Number of VBDs:', '[\\d]+', "You must enter a number in this field" ) )
75 class CreatePage3( Sheet ):
77 title = "Setup VBDS"
79 def __init__( self, urlWriter ):
80 Sheet.__init__( self, urlWriter, "Setup Virtual Block Device", 3 )
82 def write_BODY( self, request ):
83 if not self.passback: self.parseForm( request )
85 previous_values = sxp2hash( string2sxp( self.passback ) ) #get the hash for quick reference
87 num_vbds = previous_values.get( 'num_vbds' )
89 for i in range( int( num_vbds ) ):
90 self.addControl( InputControl( 'vbd%s_dom0' % i, 'phy:sda%s' % str(i + 1), 'Device %s name:' % i ) )
91 self.addControl( InputControl( 'vbd%s_domU' % i, 'sda%s' % str(i + 1), 'Virtualized device %s:' % i ) )
92 self.addControl( ListControl( 'vbd%s_mode' % i, [('w', 'Read + Write'), ('r', 'Read Only')], 'Device %s mode:' % i ) )
94 self.addControl( InputControl( 'root', '/dev/sda1', 'Root device (in VM):' ) )
96 Sheet.write_BODY( self, request )
98 class CreatePage4( Sheet ):
100 title = "Network Setting"
102 def __init__( self, urlWriter ):
103 Sheet.__init__( self, urlWriter, "Network settings", 4 )
104 self.addControl( ListControl( 'dhcp', [('off', 'No'), ('dhcp', 'Yes')], 'Use DHCP:' ) )
105 self.addControl( InputControl( 'hostname', 'hostname', 'VM Hostname:' ) )
106 self.addControl( InputControl( 'ip_addr', '192.168.1.1', 'VM IP Address:' ) )
107 self.addControl( InputControl( 'ip_subnet', '255.255.255.0', 'VM Subnet Mask:' ) )
108 self.addControl( InputControl( 'ip_gateway', '192.168.1.1', 'VM Gateway:' ) )
109 self.addControl( InputControl( 'ip_nfs', '192.168.1.1', 'NFS Server:' ) )
111 class CreateFinish( Sheet ):
113 title = "Finish"
115 def __init__( self, urlWriter ):
116 Sheet.__init__( self, urlWriter, "All Done", 5 )
118 def write_BODY( self, request ):
120 if not self.passback: self.parseForm( request )
122 xend_sxp = self.translate_sxp( string2sxp( self.passback ) )
124 request.write( "<pre>%s</pre>" % sxp2prettystring( xend_sxp ) )
126 try:
127 server.xend_domain_create( xend_sxp )
128 request.write( "<p>You domain had been successfully created.</p>" )
129 except Exception, e:
130 request.write( "<p>There was an error creating your domain.<br/>The configuration used is as follows:\n</p>" )
131 request.write( "<pre>%s</pre>" % sxp2prettystring( xend_sxp ) )
132 request.write( "<p>The error was:</p>" )
133 request.write( "<pre>%s</pre>" % str( e ) )
135 request.write( "<input type='hidden' name='passback' value=\"%s\"></p>" % self.passback )
136 request.write( "<input type='hidden' name='sheet' value='%s'></p>" % self.location )
138 def translate_sxp( self, fin_sxp ):
139 fin_hash = ssxp2hash( fin_sxp )
141 def get( key ):
142 ret = fin_hash.get( key )
143 if ret:
144 return ret
145 else:
146 return ""
148 vals = OptVals()
150 vals.name = get( 'name' )
151 vals.memory = get( 'memory' )
152 vals.maxmem = get( 'maxmem' )
153 vals.cpu = get( 'cpu' )
154 vals.cpu_weight = get( 'cpu_weight' )
155 vals.vcpus = get( 'vcpus' )
157 vals.builder = get( 'builder' )
158 vals.kernel = get( 'kernel' )
159 vals.root = get( 'root' )
160 vals.extra = get( 'extra' )
162 #setup vbds
164 vbds = []
166 for i in range( int( get( 'num_vbds' ) ) ):
167 vbds.append( ( get( 'vbd%s_dom0' % i ), get('vbd%s_domU' % i ), get( 'vbd%s_mode' % i ), None ) )
169 vals.disk = vbds
171 #misc
173 vals.pci = []
175 vals.blkif = None
176 vals.netif = None
177 vals.restart = None
178 vals.console = None
179 vals.ramdisk = None
180 vals.ssidref = -1
181 vals.bootloader = None
182 vals.usb = []
183 vals.acpi = []
185 #setup vifs
187 vals.vif = []
188 vals.nics = 1
190 ip = get( 'ip_addr' )
191 nfs = get( 'ip_nfs' )
192 gate = get( 'ip_gateway' )
193 mask = get( 'ip_subnet' )
194 host = get( 'hostname' )
195 dhcp = get( 'dhcp' )
197 vals.cmdline_ip = "%s:%s:%s:%s:%s:eth0:%s" % (ip, nfs, gate, mask, host, dhcp)
199 opts = None
201 try:
202 return make_config( opts, vals )
203 except Exception, e:
204 return [["There was an error creating the domain config SXP. This is typically due to an interface change in xm/create.py:make_config", e]]