ia64/xen-unstable

view tools/python/xen/xend/server/SrvDomain.py @ 13642:ba3ec84c9423

[XEND] Add missing ConsoleController.py

Signed-off-by: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Fri Jan 26 02:44:35 2007 +0000 (2007-01-26)
parents bc3ff220d24d
children 7869f58ff551
line source
1 #============================================================================
2 # This library is free software; you can redistribute it and/or
3 # modify it under the terms of version 2.1 of the GNU Lesser General Public
4 # License as published by the Free Software Foundation.
5 #
6 # This library is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # Lesser General Public License for more details.
10 #
11 # You should have received a copy of the GNU Lesser General Public
12 # License along with this library; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 #============================================================================
15 # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
16 # Copyright (C) 2005 Xensource Ltd
17 #============================================================================
19 from xen.web import http
21 from xen.xend import sxp
22 from xen.xend import XendDomain
23 from xen.xend.Args import FormFn
24 from xen.xend.XendLogging import log
26 from xen.web.SrvDir import SrvDir
28 class SrvDomain(SrvDir):
29 """Service managing a single domain.
30 """
32 def __init__(self, dom):
33 SrvDir.__init__(self)
34 self.dom = dom
35 self.xd = XendDomain.instance()
37 def op_configure(self, _, req):
38 """Configure an existing domain.
39 Configure is unusual in that it requires a domain id,
40 not a domain name.
41 """
42 fn = FormFn(self.xd.domain_configure,
43 [['dom', 'int'],
44 ['config', 'sxpr']])
45 return fn(req.args, {'dom': self.dom.domid})
47 def op_unpause(self, _1, _2):
48 val = self.xd.domain_unpause(self.dom.domid)
49 return val
51 def op_pause(self, _1, _2):
52 val = self.xd.domain_pause(self.dom.domid)
53 return val
55 def acceptCommand(self, req):
56 req.setResponseCode(http.ACCEPTED)
57 req.setHeader("Location", "%s/.." % req.prePathURL())
59 def op_rename(self, _, req):
60 self.acceptCommand(req)
61 return self.dom.setName(req.args['name'][0])
63 def op_shutdown(self, _, req):
64 self.acceptCommand(req)
65 return self.dom.shutdown(req.args['reason'][0])
67 def op_delete(self, _, req):
68 self.acceptCommand(req)
69 return self.xd.domain_delete(self.dom.getName())
71 def op_start(self, _, req):
72 self.acceptCommand(req)
73 paused = False
74 if 'paused' in req.args and req.args['paused'] == [1]:
75 paused = True
76 log.debug("Starting domain " + self.dom.getName() + " " + str(paused))
77 return self.xd.domain_start(self.dom.getName(), paused)
79 def op_sysrq(self, _, req):
80 self.acceptCommand(req)
81 return self.dom.send_sysrq(int(req.args['key'][0]))
83 def op_wait_for_devices(self, _, req):
84 self.acceptCommand(req)
85 return self.dom.waitForDevices()
87 def op_destroy(self, _, req):
88 self.acceptCommand(req)
89 return self.xd.domain_destroy(self.dom.domid)
91 def op_save(self, op, req):
92 self.acceptCommand(req)
93 return req.threadRequest(self.do_save, op, req)
95 def do_save(self, _, req):
96 return self.xd.domain_save(self.dom.domid, req.args['file'][0])
98 def op_dump(self, op, req):
99 self.acceptCommand(req)
100 return req.threadRequest(self.do_dump, op, req)
102 def do_dump(self, _, req):
103 fn = FormFn(self.xd.domain_dump,
104 [['dom', 'int'],
105 ['file', 'str'],
106 ['live', 'int'],
107 ['crash', 'int']])
108 return fn(req.args, {'dom': self.dom.domid})
110 def op_migrate(self, op, req):
111 return req.threadRequest(self.do_migrate, op, req)
113 def do_migrate(self, _, req):
114 fn = FormFn(self.xd.domain_migrate,
115 [['dom', 'int'],
116 ['destination', 'str'],
117 ['live', 'int'],
118 ['resource', 'int'],
119 ['port', 'int']])
120 return fn(req.args, {'dom': self.dom.domid})
122 def op_pincpu(self, _, req):
123 fn = FormFn(self.xd.domain_pincpu,
124 [['dom', 'int'],
125 ['vcpu', 'str'],
126 ['cpumap', 'str']])
127 val = fn(req.args, {'dom': self.dom.domid})
128 return val
130 def op_cpu_sedf_get(self, _, req):
131 fn = FormFn(self.xd.domain_cpu_sedf_get,
132 [['dom', 'int']])
133 val = fn(req.args, {'dom': self.dom.domid})
134 return val
137 def op_cpu_sedf_set(self, _, req):
138 fn = FormFn(self.xd.domain_cpu_sedf_set,
139 [['dom', 'int'],
140 ['period', 'int'],
141 ['slice', 'int'],
142 ['latency', 'int'],
143 ['extratime', 'int'],
144 ['weight', 'int']])
145 val = fn(req.args, {'dom': self.dom.domid})
146 return val
148 def op_domain_sched_credit_get(self, _, req):
149 fn = FormFn(self.xd.domain_sched_credit_get,
150 [['dom', 'int']])
151 val = fn(req.args, {'dom': self.dom.domid})
152 return val
155 def op_domain_sched_credit_set(self, _, req):
156 fn = FormFn(self.xd.domain_sched_credit_set,
157 [['dom', 'int'],
158 ['weight', 'int']])
159 val = fn(req.args, {'dom': self.dom.domid})
160 return val
162 def op_maxmem_set(self, _, req):
163 return self.call(self.dom.setMemoryMaximum,
164 [['memory', 'int']],
165 req)
167 def call(self, fn, args, req):
168 return FormFn(fn, args)(req.args)
171 def op_mem_target_set(self, _, req):
172 return self.call(self.dom.setMemoryTarget,
173 [['target', 'int']],
174 req)
176 def op_devices(self, _, req):
177 return self.call(self.dom.getDeviceSxprs,
178 [['type', 'str']],
179 req)
181 def op_device_create(self, _, req):
182 return self.call(self.dom.device_create,
183 [['config', 'sxpr']],
184 req)
186 def op_device_destroy(self, _, req):
187 return self.call(self.dom.destroyDevice,
188 [['type', 'str'],
189 ['dev', 'str']],
190 req)
192 def op_device_configure(self, _, req):
193 return self.call(self.dom.device_configure,
194 [['config', 'sxpr'],
195 ['dev', 'str']],
196 req)
199 def op_vif_limit_set(self, _, req):
200 fn = FormFn(self.xd.domain_vif_limit_set,
201 [['dom', 'int'],
202 ['vif', 'int'],
203 ['credit', 'int'],
204 ['period', 'int']])
205 val = fn(req.args, {'dom': self.dom.domid})
206 return val
208 def op_set_vcpus(self, _, req):
209 return self.call(self.dom.setVCpuCount,
210 [['vcpus', 'int']],
211 req)
214 def op_vcpuinfo(self, _1, req):
215 return self.call(self.dom.getVCPUInfo, [], req)
218 def render_POST(self, req):
219 return self.perform(req)
221 def render_GET(self, req):
222 op = req.args.get('op')
224 if op and op[0] in ['vcpuinfo']:
225 return self.perform(req)
227 #
228 # XXX SMH: below may be useful once again if we ever try to get
229 # the raw 'web' interface to xend working once more. But for now
230 # is useless and out of date (i.e. no ops called 'v???' anymore).
231 #
232 # if op and op[0] in ['vifs', 'vif', 'vbds', 'vbd', 'mem_target_set']:
233 # return self.perform(req)
234 if self.use_sxp(req):
235 req.setHeader("Content-Type", sxp.mime_type)
236 sxp.show(self.dom.sxpr(), out=req)
237 else:
238 req.write('<html><head></head><body>')
239 self.print_path(req)
240 #self.ls()
241 req.write('<p>%s</p>' % self.dom)
242 self.form(req)
243 req.write('</body></html>')
244 return ''
246 def form(self, req):
247 url = req.prePathURL()
248 req.write('<form method="post" action="%s">' % url)
249 req.write('<input type="submit" name="op" value="unpause">')
250 req.write('<input type="submit" name="op" value="pause">')
251 req.write('</form>')
253 req.write('<form method="post" action="%s">' % url)
254 req.write('<input type="submit" name="op" value="destroy">')
255 req.write('</form>')
257 req.write('<form method="post" action="%s">' % url)
258 req.write('<input type="submit" name="op" value="shutdown">')
259 req.write('<input type="radio" name="reason" value="poweroff" checked>Poweroff')
260 req.write('<input type="radio" name="reason" value="halt">Halt')
261 req.write('<input type="radio" name="reason" value="reboot">Reboot')
262 req.write('</form>')
264 req.write('<form method="post" action="%s">' % url)
265 req.write('<br><input type="submit" name="op" value="save">')
266 req.write(' To file: <input type="text" name="file">')
267 req.write('</form>')
269 req.write('<form method="post" action="%s">' % url)
270 req.write('<br><input type="submit" name="op" value="migrate">')
271 req.write(' To host: <input type="text" name="destination">')
272 req.write('<input type="checkbox" name="live" value="1">Live')
273 req.write('</form>')