ia64/xen-unstable

view tools/python/xen/sv/DomInfo.py @ 7174:600f3d2b78d6

Remove the reason code from the destroy action -- the reason is only of value
on a graceful shutdown. Clarify the semantic difference between poweroff and
halt (we use halt to mean 'shutdown and stop' and poweroff to mean 'shutdown
and do whatever the configured behaviour is').

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Tue Oct 04 00:56:24 2005 +0100 (2005-10-04)
parents 06d84bf87159
children
line source
1 from xen.xend.XendClient import server
2 from xen.xend import PrettyPrint
4 from xen.sv.HTMLBase import HTMLBase
5 from xen.sv.util import *
6 from xen.sv.GenTabbed import *
7 from xen.sv.Wizard import *
9 DEBUG=1
11 class DomInfo( GenTabbed ):
13 def __init__( self, urlWriter ):
15 self.dom = 0;
17 GenTabbed.__init__( self, "Domain Info", urlWriter, [ 'General', 'SXP', 'Devices', 'Migrate', 'Save' ], [ DomGeneralTab, DomSXPTab, DomDeviceTab, DomMigrateTab, DomSaveTab ] )
19 def write_BODY( self, request ):
20 try:
21 dom = int( getVar( 'dom', request ) )
22 except:
23 request.write( "<p>Please Select a Domain</p>" )
24 return None
26 GenTabbed.write_BODY( self, request )
28 def write_MENU( self, request ):
29 domains = []
31 try:
32 domains = server.xend_domains()
33 domains.sort()
34 except:
35 pass
37 request.write( "\n<table style='border:0px solid white' cellspacing='0' cellpadding='0' border='0' width='100%'>\n" )
38 request.write( "<tr class='domainInfoHead'>" )
39 request.write( "<td class='domainInfoHead' align='center'>Domain</td>\n" )
40 request.write( "<td class='domainInfoHead' align='center'>Name</td>\n" )
41 request.write( "<td class='domainInfoHead' align='center'>State</td>\n" )
42 request.write( "<td class='domainInfoHead' align='center'></td>\n" )
43 request.write( "</tr>" )
45 odd = True
46 if not domains is None:
47 for domain in domains:
48 odd = not odd;
49 if odd:
50 request.write( "<tr class='domainInfoOdd'>\n" )
51 else:
52 request.write( "<tr class='domainInfoEven'>\n" )
53 domInfo = getDomInfo( domain )
54 request.write( "<td class='domainInfo' align='center'>%(id)s</td>\n" % domInfo )
55 url = self.urlWriter( "&dom=%(id)s" % domInfo )
56 request.write( "<td class='domainInfo' align='center'><a href='%s'>%s</a></td>\n" % ( url, domInfo['name'] ) )
57 request.write( "<td class='domainInfo' align='center'>%(state)5s</td>\n" % domInfo )
58 if domInfo[ 'id' ] != "0":
59 request.write( "<td class='domainInfo' align='center'>" )
60 if domInfo[ 'state' ][ 2 ] == "-":
61 request.write( "<img src='images/small-pause.png' onclick='doOp2( \"pause\", \"%(dom)-4s\" )'>" % domInfo )
62 else:
63 request.write( "<img src='images/small-unpause.png' onclick='doOp2( \"unpause\", \"%(dom)-4s\" )'>" % domInfo )
64 request.write( "<img src='images/small-destroy.png' onclick='doOp2( \"destroy\", \"%(dom)-4s\" )'></td>" % domInfo )
65 else:
66 request.write( "<td>&nbsp;</td>" )
67 request.write( "</tr>\n" )
68 else:
69 request.write( "<tr colspan='10'><p class='small'>Error getting domain list<br/>Perhaps XenD not running?</p></tr>")
70 request.write( "</table>" )
72 class DomGeneralTab( CompositeTab ):
73 def __init__( self, urlWriter ):
74 CompositeTab.__init__( self, [ DomGenTab, DomActionTab ], urlWriter )
76 class DomGenTab( GeneralTab ):
78 def __init__( self, _ ):
80 titles = {}
82 titles[ 'ID' ] = 'dom'
83 titles[ 'Name' ] = 'name'
84 titles[ 'CPU' ] = 'cpu'
85 titles[ 'Memory' ] = ( 'mem', memoryFormatter )
86 titles[ 'State' ] = ( 'state', stateFormatter )
87 titles[ 'Total CPU' ] = ( 'cpu_time', smallTimeFormatter )
88 titles[ 'Up Time' ] = ( 'up_time', bigTimeFormatter )
90 GeneralTab.__init__( self, {}, titles )
92 def write_BODY( self, request ):
94 self.dom = getVar('dom', request)
96 if self.dom is None:
97 request.write( "<p>Please Select a Domain</p>" )
98 return None
100 self.dict = getDomInfo( self.dom )
102 GeneralTab.write_BODY( self, request )
104 class DomSXPTab( PreTab ):
106 def __init__( self, _ ):
107 self.dom = 0
108 PreTab.__init__( self, "" )
111 def write_BODY( self, request ):
112 self.dom = getVar('dom', request)
114 if self.dom is None:
115 request.write( "<p>Please Select a Domain</p>" )
116 return None
118 try:
119 domInfo = server.xend_domain( self.dom )
120 except:
121 domInfo = [["Error getting domain details."]]
123 self.source = sxp2prettystring( domInfo )
125 PreTab.write_BODY( self, request )
127 class DomActionTab( ActionTab ):
129 def __init__( self, _ ):
130 actions = { "shutdown" : "Shutdown",
131 "reboot" : "Reboot",
132 "pause" : "Pause",
133 "unpause" : "Unpause",
134 "destroy" : "Destroy" }
135 ActionTab.__init__( self, actions )
137 def op_shutdown( self, request ):
138 dom = getVar( 'dom', request )
139 if not dom is None and dom != '0':
140 if DEBUG: print ">DomShutDown %s" % dom
141 try:
142 server.xend_domain_shutdown( int( dom ), "poweroff" )
143 except:
144 pass
146 def op_reboot( self, request ):
147 dom = getVar( 'dom', request )
148 if not dom is None and dom != '0':
149 if DEBUG: print ">DomReboot %s" % dom
150 try:
151 server.xend_domain_shutdown( int( dom ), "reboot" )
152 except:
153 pass
155 def op_pause( self, request ):
156 dom = getVar( 'dom', request )
157 if not dom is None and dom != '0':
158 if DEBUG: print ">DomPause %s" % dom
159 try:
160 server.xend_domain_pause( int( dom ) )
161 except:
162 pass
164 def op_unpause( self, request ):
165 dom = getVar( 'dom', request )
166 if not dom is None and dom != '0':
167 if DEBUG: print ">DomUnpause %s" % dom
168 try:
169 server.xend_domain_unpause( int( dom ) )
170 except:
171 pass
173 def op_destroy( self, request ):
174 dom = getVar( 'dom', request )
175 if not dom is None and dom != '0':
176 if DEBUG: print ">DomDestroy %s" % dom
177 try:
178 server.xend_domain_destroy(int( dom ))
179 except:
180 pass
182 class DomDeviceTab( CompositeTab ):
184 def __init__( self, urlWriter ):
185 CompositeTab.__init__( self, [ DomDeviceListTab, DomDeviceOptionsTab, DomDeviceActionTab ], urlWriter )
187 class DomDeviceListTab( NullTab ):
189 title = "Device List"
191 def __init__( self, _ ):
192 pass
194 class DomDeviceOptionsTab( NullTab ):
196 title = "Device Options"
198 def __init__( self, _ ):
199 pass
201 class DomDeviceActionTab( ActionTab ):
203 def __init__( self, _ ):
204 ActionTab.__init__( self, { "addvcpu" : "Add VCPU", "addvbd" : "Add VBD", "addvif" : "Add VIF" } )
206 class DomMigrateTab( CompositeTab ):
208 def __init__( self, urlWriter ):
209 CompositeTab.__init__( self, [ DomMigrateExtraTab, DomMigrateActionTab ], urlWriter )
211 class DomMigrateExtraTab( Sheet ):
213 def __init__( self, urlWriter ):
214 Sheet.__init__( self, urlWriter, "Configure Migration", 0)
215 self.addControl( TickControl('live', 'True', 'Live migrate:') )
216 self.addControl( InputControl('rate', '0', 'Rate limit:') )
217 self.addControl( InputControl( 'dest', 'host.domain', 'Name or IP address:', ".*") )
219 class DomMigrateActionTab( ActionTab ):
221 def __init__( self, _ ):
222 actions = { "migrate" : "Migrate" }
223 ActionTab.__init__( self, actions )
225 def op_migrate( self, request ):
226 try:
227 domid = int( getVar( 'dom', request ) )
228 live = getVar( 'live', request )
229 rate = getVar( 'rate', request )
230 dest = getVar( 'dest', request )
231 dom_sxp = server.xend_domain_migrate( domid, dest, live == 'True', rate )
232 success = "Your domain was successfully Migrated.\n"
233 except Exception, e:
234 success = "There was an error migrating your domain\n"
235 dom_sxp = str(e)
237 class DomSaveTab( CompositeTab ):
239 def __init__( self, urlWriter ):
240 CompositeTab.__init__( self, [ DomSaveExtraTab, DomSaveActionTab ], urlWriter )
242 class DomSaveExtraTab( Sheet ):
244 title = "Save location"
246 def __init__( self, urlWriter ):
247 Sheet.__init__( self, urlWriter, "Save Domain to file", 0 )
248 self.addControl( InputControl( 'file', '', 'Suspend file name:', ".*") )
250 class DomSaveActionTab( ActionTab ):
252 def __init__( self, _ ):
253 actions = { "save" : "Save" }
254 ActionTab.__init__( self, actions )
256 def op_save( self, request ):
258 try:
259 dom_sxp = server.xend_domain_save( config['domid'], config['file'] )
260 success = "Your domain was successfully saved.\n"
261 except Exception, e:
262 success = "There was an error saving your domain\n"
263 dom_sxp = str(e)
265 try:
266 dom = int( getVar( 'dom', request ) )
267 except:
268 pass