xen-vtx-unstable

annotate tools/python/xen/sv/DomInfo.py @ 6774:4d899a738d59

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