ia64/xen-unstable

view tools/python/xen/xend/server/SrvDomain.py @ 19356:3c1a88dc6fbe

xend: Fix domain core-dumping about reset option

This patch moves a call processing of a domain reset processing
from xm to xend. Also, it adds a reset argument to do_dump() of
SrvDomain.py.

Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Mar 13 07:38:05 2009 +0000 (2009-03-13)
parents 6f48c4ee8ae2
children
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 ['reset', 'int']])
109 return fn(req.args, {'dom': self.dom.domid})
111 def op_migrate(self, op, req):
112 return req.threadRequest(self.do_migrate, op, req)
114 def do_migrate(self, _, req):
115 fn = FormFn(self.xd.domain_migrate,
116 [['dom', 'int'],
117 ['destination', 'str'],
118 ['live', 'int'],
119 ['port', 'int'],
120 ['node', 'int'],
121 ['ssl', 'int']])
122 return fn(req.args, {'dom': self.dom.domid})
124 def op_pincpu(self, _, req):
125 fn = FormFn(self.xd.domain_pincpu,
126 [['dom', 'str'],
127 ['vcpu', 'str'],
128 ['cpumap', 'str']])
129 val = fn(req.args, {'dom': self.dom.getName()})
130 return val
132 def op_cpu_sedf_get(self, _, req):
133 fn = FormFn(self.xd.domain_cpu_sedf_get,
134 [['dom', 'int']])
135 val = fn(req.args, {'dom': self.dom.domid})
136 return val
139 def op_cpu_sedf_set(self, _, req):
140 fn = FormFn(self.xd.domain_cpu_sedf_set,
141 [['dom', 'int'],
142 ['period', 'int'],
143 ['slice', 'int'],
144 ['latency', 'int'],
145 ['extratime', 'int'],
146 ['weight', 'int']])
147 val = fn(req.args, {'dom': self.dom.domid})
148 return val
150 def op_domain_sched_credit_get(self, _, req):
151 fn = FormFn(self.xd.domain_sched_credit_get,
152 [['dom', 'str']])
153 val = fn(req.args, {'dom': self.dom.getName()})
154 return val
157 def op_domain_sched_credit_set(self, _, req):
158 fn = FormFn(self.xd.domain_sched_credit_set,
159 [['dom', 'str'],
160 ['weight', 'int'],
161 ['cap', 'int']])
162 val = fn(req.args, {'dom': self.dom.getName()})
163 return val
165 def op_maxmem_set(self, _, req):
166 return self.call(self.dom.setMemoryMaximum,
167 [['memory', 'int']],
168 req)
170 def call(self, fn, args, req):
171 return FormFn(fn, args)(req.args)
174 def op_mem_target_set(self, _, req):
175 return self.call(self.dom.setMemoryTarget,
176 [['target', 'int']],
177 req)
179 def op_devices(self, _, req):
180 return self.call(self.dom.getDeviceSxprs,
181 [['type', 'str']],
182 req)
184 def op_device_create(self, _, req):
185 return self.call(self.dom.device_create,
186 [['config', 'sxpr']],
187 req)
189 def op_device_destroy(self, _, req):
190 return self.call(self.dom.destroyDevice,
191 [['type', 'str'],
192 ['dev', 'str'],
193 ['force', 'int'],
194 ['rm_cfg', 'int']],
195 req)
197 def op_device_configure(self, _, req):
198 return self.call(self.dom.device_configure,
199 [['config', 'sxpr'],
200 ['dev', 'str']],
201 req)
204 def op_vif_limit_set(self, _, req):
205 fn = FormFn(self.xd.domain_vif_limit_set,
206 [['dom', 'int'],
207 ['vif', 'int'],
208 ['credit', 'int'],
209 ['period', 'int']])
210 val = fn(req.args, {'dom': self.dom.domid})
211 return val
213 def op_set_vcpus(self, _, req):
214 return self.call(self.dom.setVCpuCount,
215 [['vcpus', 'int']],
216 req)
219 def op_vcpuinfo(self, _1, req):
220 return self.call(self.dom.getVCPUInfo, [], req)
223 def op_reset(self, _, req):
224 self.acceptCommand(req)
225 return self.xd.domain_reset(self.dom.getName())
228 def render_POST(self, req):
229 return self.perform(req)
231 def render_GET(self, req):
232 op = req.args.get('op')
234 if op and op[0] in ['vcpuinfo']:
235 return self.perform(req)
237 #
238 # XXX SMH: below may be useful once again if we ever try to get
239 # the raw 'web' interface to xend working once more. But for now
240 # is useless and out of date (i.e. no ops called 'v???' anymore).
241 #
242 # if op and op[0] in ['vifs', 'vif', 'vbds', 'vbd', 'mem_target_set']:
243 # return self.perform(req)
244 if self.use_sxp(req):
245 req.setHeader("Content-Type", sxp.mime_type)
246 sxp.show(self.dom.sxpr(), out=req)
247 else:
248 req.write('<html><head></head><body>')
249 self.print_path(req)
250 #self.ls()
251 req.write('<p>%s</p>' % self.dom)
252 self.form(req)
253 req.write('</body></html>')
254 return ''
256 def form(self, req):
257 url = req.prePathURL()
258 req.write('<form method="post" action="%s">' % url)
259 req.write('<input type="submit" name="op" value="unpause">')
260 req.write('<input type="submit" name="op" value="pause">')
261 req.write('</form>')
263 req.write('<form method="post" action="%s">' % url)
264 req.write('<input type="submit" name="op" value="destroy">')
265 req.write('</form>')
267 req.write('<form method="post" action="%s">' % url)
268 req.write('<input type="submit" name="op" value="reset">')
269 req.write('</form>')
271 req.write('<form method="post" action="%s">' % url)
272 req.write('<input type="submit" name="op" value="shutdown">')
273 req.write('<input type="radio" name="reason" value="poweroff" checked>Poweroff')
274 req.write('<input type="radio" name="reason" value="halt">Halt')
275 req.write('<input type="radio" name="reason" value="reboot">Reboot')
276 req.write('</form>')
278 req.write('<form method="post" action="%s">' % url)
279 req.write('<br><input type="submit" name="op" value="save">')
280 req.write(' To file: <input type="text" name="file">')
281 req.write('</form>')
283 req.write('<form method="post" action="%s">' % url)
284 req.write('<br><input type="submit" name="op" value="migrate">')
285 req.write(' To host: <input type="text" name="destination">')
286 req.write('<input type="checkbox" name="live" value="1">Live')
287 req.write('</form>')