ia64/xen-unstable

view tools/python/xen/xend/server/SrvDomain.py @ 6835:5cbb2ecce16a

Move id back into main domain dir and rename to domid.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Wed Sep 14 15:10:22 2005 +0000 (2005-09-14)
parents dd668f7527cb
children 9af349b055e5 3233e7ecfa9f
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 #============================================================================
18 from xen.web import http
20 from xen.xend import sxp
21 from xen.xend import XendDomain
22 from xen.xend import PrettyPrint
23 from xen.xend.Args import FormFn
25 from xen.web.SrvDir import SrvDir
27 class SrvDomain(SrvDir):
28 """Service managing a single domain.
29 """
31 def __init__(self, dom):
32 SrvDir.__init__(self)
33 self.dom = dom
34 self.xd = XendDomain.instance()
36 def op_configure(self, op, req):
37 """Configure an existing domain.
38 Configure is unusual in that it requires a domain id,
39 not a domain name.
40 """
41 fn = FormFn(self.xd.domain_configure,
42 [['dom', 'int'],
43 ['config', 'sxpr']])
44 return fn(req.args, {'dom': self.dom.domid})
46 def op_unpause(self, op, req):
47 val = self.xd.domain_unpause(self.dom.domid)
48 return val
50 def op_pause(self, op, req):
51 val = self.xd.domain_pause(self.dom.domid)
52 return val
54 def op_shutdown(self, op, req):
55 fn = FormFn(self.xd.domain_shutdown,
56 [['dom', 'int'],
57 ['reason', 'str']])
58 val = fn(req.args, {'dom': self.dom.domid})
59 req.setResponseCode(http.ACCEPTED)
60 req.setHeader("Location", "%s/.." % req.prePathURL())
61 return val
63 def op_sysrq(self, op, req):
64 fn = FormFn(self.xd.domain_sysrq,
65 [['dom', 'int'],
66 ['key', 'int']])
67 val = fn(req.args, {'dom' : self.dom.domid})
68 req.setResponseCode(http.ACCEPTED)
69 req.setHeader("Location", "%s/.." % req.prePathURL())
70 return val
72 def op_destroy(self, op, req):
73 fn = FormFn(self.xd.domain_destroy,
74 [['dom', 'int'],
75 ['reason', 'str']])
76 val = fn(req.args, {'dom': self.dom.domid})
77 req.setHeader("Location", "%s/.." % req.prePathURL())
78 return val
80 def op_save(self, op, req):
81 return req.threadRequest(self.do_save, op, req)
83 def do_save(self, op, req):
84 fn = FormFn(self.xd.domain_save,
85 [['dom', 'int'],
86 ['file', 'str']])
87 val = fn(req.args, {'dom': self.dom.domid})
88 return 0
90 def op_migrate(self, op, req):
91 return req.threadRequest(self.do_migrate, op, req)
93 def do_migrate(self, op, req):
94 fn = FormFn(self.xd.domain_migrate,
95 [['dom', 'int'],
96 ['destination', 'str'],
97 ['live', 'int'],
98 ['resource', 'int']])
99 return fn(req.args, {'dom': self.dom.domid})
101 def op_pincpu(self, op, req):
102 fn = FormFn(self.xd.domain_pincpu,
103 [['dom', 'int'],
104 ['vcpu', 'int'],
105 ['cpumap', 'int']])
106 val = fn(req.args, {'dom': self.dom.domid})
107 return val
109 def op_cpu_bvt_set(self, op, req):
110 fn = FormFn(self.xd.domain_cpu_bvt_set,
111 [['dom', 'int'],
112 ['mcuadv', 'int'],
113 ['warpback', 'int'],
114 ['warpvalue', 'int'],
115 ['warpl', 'long'],
116 ['warpu', 'long']])
117 val = fn(req.args, {'dom': self.dom.domid})
118 return val
121 def op_cpu_sedf_set(self, op, req):
122 fn = FormFn(self.xd.domain_cpu_sedf_set,
123 [['dom', 'int'],
124 ['period', 'int'],
125 ['slice', 'int'],
126 ['latency', 'int'],
127 ['extratime', 'int'],
128 ['weight', 'int']])
129 val = fn(req.args, {'dom': self.dom.domid})
130 return val
132 def op_maxmem_set(self, op, req):
133 fn = FormFn(self.xd.domain_maxmem_set,
134 [['dom', 'int'],
135 ['memory', 'int']])
136 val = fn(req.args, {'dom': self.dom.domid})
137 return val
139 def op_mem_target_set(self, op, req):
140 fn = FormFn(self.xd.domain_mem_target_set,
141 [['dom', 'int'],
142 ['target', 'int']])
143 val = fn(req.args, {'dom': self.dom.domid})
144 return val
146 def op_devices(self, op, req):
147 fn = FormFn(self.xd.domain_devtype_ls,
148 [['dom', 'int'],
149 ['type', 'str']])
150 val = fn(req.args, {'dom': self.dom.domid})
151 return val
153 def op_device(self, op, req):
154 fn = FormFn(self.xd.domain_devtype_get,
155 [['dom', 'int'],
156 ['type', 'str'],
157 ['idx', 'int']])
158 val = fn(req.args, {'dom': self.dom.domid})
159 if val:
160 return val.sxpr()
161 else:
162 raise XendError("invalid device")
164 def op_device_create(self, op, req):
165 fn = FormFn(self.xd.domain_device_create,
166 [['dom', 'int'],
167 ['config', 'sxpr']])
168 val = fn(req.args, {'dom': self.dom.domid})
169 return val
171 def op_device_refresh(self, op, req):
172 fn = FormFn(self.xd.domain_device_refresh,
173 [['dom', 'int'],
174 ['type', 'str'],
175 ['idx', 'str']])
176 val = fn(req.args, {'dom': self.dom.domid})
177 return val
179 def op_device_destroy(self, op, req):
180 fn = FormFn(self.xd.domain_device_destroy,
181 [['dom', 'int'],
182 ['type', 'str'],
183 ['idx', 'str']])
184 val = fn(req.args, {'dom': self.dom.domid})
185 return val
187 def op_device_configure(self, op, req):
188 fn = FormFn(self.xd.domain_device_configure,
189 [['dom', 'int'],
190 ['config', 'sxpr'],
191 ['idx', 'str']])
192 val = fn(req.args, {'dom': self.dom.domid})
193 return val
195 def op_vif_limit_set(self, op, req):
196 fn = FormFn(self.xd.domain_vif_limit_set,
197 [['dom', 'int'],
198 ['vif', 'int'],
199 ['credit', 'int'],
200 ['period', 'int']])
201 val = fn(req.args, {'dom': self.dom.domid})
202 return val
204 def op_vcpu_hotplug(self, op, req):
205 fn = FormFn(self.xd.domain_vcpu_hotplug,
206 [['dom', 'int'],
207 ['vcpu', 'int'],
208 ['state', 'int']])
209 val = fn(req.args, {'dom': self.dom.domid})
210 return val
212 def render_POST(self, req):
213 return self.perform(req)
215 def render_GET(self, req):
216 op = req.args.get('op')
217 #
218 # XXX SMH: below may be useful once again if we ever try to get
219 # the raw 'web' interface to xend working once more. But for now
220 # is useless and out of date (i.e. no ops called 'v???' anymore).
221 #
222 # if op and op[0] in ['vifs', 'vif', 'vbds', 'vbd', 'mem_target_set']:
223 # return self.perform(req)
224 self.dom.update()
225 if self.use_sxp(req):
226 req.setHeader("Content-Type", sxp.mime_type)
227 sxp.show(self.dom.sxpr(), out=req)
228 else:
229 req.write('<html><head></head><body>')
230 self.print_path(req)
231 #self.ls()
232 req.write('<p>%s</p>' % self.dom)
233 if self.dom.config:
234 req.write("<code><pre>")
235 PrettyPrint.prettyprint(self.dom.config, out=req)
236 req.write("</pre></code>")
237 self.form(req)
238 req.write('</body></html>')
239 return ''
241 def form(self, req):
242 url = req.prePathURL()
243 req.write('<form method="post" action="%s">' % url)
244 req.write('<input type="submit" name="op" value="unpause">')
245 req.write('<input type="submit" name="op" value="pause">')
246 req.write('</form>')
248 req.write('<form method="post" action="%s">' % url)
249 req.write('<input type="submit" name="op" value="destroy">')
250 req.write('<input type="radio" name="reason" value="halt" checked>Halt')
251 req.write('<input type="radio" name="reason" value="reboot">Reboot')
252 req.write('</form>')
254 req.write('<form method="post" action="%s">' % url)
255 req.write('<input type="submit" name="op" value="shutdown">')
256 req.write('<input type="radio" name="reason" value="poweroff" checked>Poweroff')
257 req.write('<input type="radio" name="reason" value="halt">Halt')
258 req.write('<input type="radio" name="reason" value="reboot">Reboot')
259 req.write('</form>')
261 req.write('<form method="post" action="%s">' % url)
262 req.write('<br><input type="submit" name="op" value="save">')
263 req.write(' To file: <input type="text" name="file">')
264 req.write('</form>')
266 req.write('<form method="post" action="%s">' % url)
267 req.write('<br><input type="submit" name="op" value="migrate">')
268 req.write(' To host: <input type="text" name="destination">')
269 req.write('<input type="checkbox" name="live" value="1">Live')
270 req.write('</form>')