debuggers.hg

view tools/python/xen/sv/CreateDomain.py @ 10971:386990d004b8

[qemu] Add switch to control whether acpi bridge is enabled.

Signed-off-by: Winston Wang <winston.l.wang@intel.com>
author chris@kneesaa.uk.xensource.com
date Fri Aug 04 10:41:27 2006 +0100 (2006-08-04)
parents 06d84bf87159
children 33dcf04d7715
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', '1.2.3.4', 'VM IP Address:' ) )
107 self.addControl( InputControl( 'ip_subnet', '255.255.255.0', 'VM Subnet Mask:' ) )
108 self.addControl( InputControl( 'ip_gateway', '1.2.3.4', 'VM Gateway:' ) )
109 self.addControl( InputControl( 'ip_nfs', '1.2.3.4', '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]]