ia64/xen-unstable

view tools/python/xen/xend/server/SrvDomain.py @ 15512:f20ee5bc9d28

xend: Fix op_domain_sched_credit_set() in SrvDomain.py
This patch adds "cap" into op_domain_sched_credit_set().
Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
author kfraser@localhost.localdomain
date Fri Jul 06 14:39:21 2007 +0100 (2007-07-06)
parents 7869f58ff551
children d0a538659726
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 ['cap', 'int']])
160 val = fn(req.args, {'dom': self.dom.domid})
161 return val
163 def op_maxmem_set(self, _, req):
164 return self.call(self.dom.setMemoryMaximum,
165 [['memory', 'int']],
166 req)
168 def call(self, fn, args, req):
169 return FormFn(fn, args)(req.args)
172 def op_mem_target_set(self, _, req):
173 return self.call(self.dom.setMemoryTarget,
174 [['target', 'int']],
175 req)
177 def op_devices(self, _, req):
178 return self.call(self.dom.getDeviceSxprs,
179 [['type', 'str']],
180 req)
182 def op_device_create(self, _, req):
183 return self.call(self.dom.device_create,
184 [['config', 'sxpr']],
185 req)
187 def op_device_destroy(self, _, req):
188 return self.call(self.dom.destroyDevice,
189 [['type', 'str'],
190 ['dev', 'str']],
191 req)
193 def op_device_configure(self, _, req):
194 return self.call(self.dom.device_configure,
195 [['config', 'sxpr'],
196 ['dev', 'str']],
197 req)
200 def op_vif_limit_set(self, _, req):
201 fn = FormFn(self.xd.domain_vif_limit_set,
202 [['dom', 'int'],
203 ['vif', 'int'],
204 ['credit', 'int'],
205 ['period', 'int']])
206 val = fn(req.args, {'dom': self.dom.domid})
207 return val
209 def op_set_vcpus(self, _, req):
210 return self.call(self.dom.setVCpuCount,
211 [['vcpus', 'int']],
212 req)
215 def op_vcpuinfo(self, _1, req):
216 return self.call(self.dom.getVCPUInfo, [], req)
219 def render_POST(self, req):
220 return self.perform(req)
222 def render_GET(self, req):
223 op = req.args.get('op')
225 if op and op[0] in ['vcpuinfo']:
226 return self.perform(req)
228 #
229 # XXX SMH: below may be useful once again if we ever try to get
230 # the raw 'web' interface to xend working once more. But for now
231 # is useless and out of date (i.e. no ops called 'v???' anymore).
232 #
233 # if op and op[0] in ['vifs', 'vif', 'vbds', 'vbd', 'mem_target_set']:
234 # return self.perform(req)
235 if self.use_sxp(req):
236 req.setHeader("Content-Type", sxp.mime_type)
237 sxp.show(self.dom.sxpr(), out=req)
238 else:
239 req.write('<html><head></head><body>')
240 self.print_path(req)
241 #self.ls()
242 req.write('<p>%s</p>' % self.dom)
243 self.form(req)
244 req.write('</body></html>')
245 return ''
247 def form(self, req):
248 url = req.prePathURL()
249 req.write('<form method="post" action="%s">' % url)
250 req.write('<input type="submit" name="op" value="unpause">')
251 req.write('<input type="submit" name="op" value="pause">')
252 req.write('</form>')
254 req.write('<form method="post" action="%s">' % url)
255 req.write('<input type="submit" name="op" value="destroy">')
256 req.write('</form>')
258 req.write('<form method="post" action="%s">' % url)
259 req.write('<input type="submit" name="op" value="shutdown">')
260 req.write('<input type="radio" name="reason" value="poweroff" checked>Poweroff')
261 req.write('<input type="radio" name="reason" value="halt">Halt')
262 req.write('<input type="radio" name="reason" value="reboot">Reboot')
263 req.write('</form>')
265 req.write('<form method="post" action="%s">' % url)
266 req.write('<br><input type="submit" name="op" value="save">')
267 req.write(' To file: <input type="text" name="file">')
268 req.write('</form>')
270 req.write('<form method="post" action="%s">' % url)
271 req.write('<br><input type="submit" name="op" value="migrate">')
272 req.write(' To host: <input type="text" name="destination">')
273 req.write('<input type="checkbox" name="live" value="1">Live')
274 req.write('</form>')