debuggers.hg

view tools/python/xen/xend/server/SrvDomain.py @ 3611:3dc193a9786a

bitkeeper revision 1.1159.170.102 (41fa2751heRkQ76AYa9Oe-6cOyJuLw)

Enhanced SEDF scheduler
author sd386@font.cl.cam.ac.uk
date Fri Jan 28 11:51:45 2005 +0000 (2005-01-28)
parents f8e1f285e41f
children 0dc3b8b8c298
line source
1 # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
3 from twisted.protocols import http
5 from xen.xend import sxp
6 from xen.xend import XendDomain
7 from xen.xend import XendConsole
8 from xen.xend import PrettyPrint
9 from xen.xend.Args import FormFn
11 from SrvDir import SrvDir
13 class SrvDomain(SrvDir):
14 """Service managing a single domain.
15 """
17 def __init__(self, dom):
18 SrvDir.__init__(self)
19 self.dom = dom
20 self.xd = XendDomain.instance()
21 self.xconsole = XendConsole.instance()
23 def op_configure(self, op, req):
24 """Configure an existing domain.
25 Configure is unusual in that it requires a domain id,
26 not a domain name.
27 """
28 fn = FormFn(self.xd.domain_configure,
29 [['dom', 'int'],
30 ['config', 'sxpr']])
31 deferred = fn(req.args, {'dom': self.dom.dom})
32 deferred.addErrback(self._op_configure_err, req)
33 return deferred
35 def _op_configure_err(self, err, req):
36 req.setResponseCode(http.BAD_REQUEST, "Error: "+ str(err))
37 return str(err)
39 def op_unpause(self, op, req):
40 val = self.xd.domain_unpause(self.dom.name)
41 return val
43 def op_pause(self, op, req):
44 val = self.xd.domain_pause(self.dom.name)
45 return val
47 def op_shutdown(self, op, req):
48 fn = FormFn(self.xd.domain_shutdown,
49 [['dom', 'str'],
50 ['reason', 'str'],
51 ['key', 'int']])
52 val = fn(req.args, {'dom': self.dom.id})
53 req.setResponseCode(http.ACCEPTED)
54 req.setHeader("Location", "%s/.." % req.prePathURL())
55 return val
57 def op_destroy(self, op, req):
58 fn = FormFn(self.xd.domain_destroy,
59 [['dom', 'str'],
60 ['reason', 'str']])
61 val = fn(req.args, {'dom': self.dom.id})
62 req.setHeader("Location", "%s/.." % req.prePathURL())
63 return val
65 def op_save(self, op, req):
66 fn = FormFn(self.xd.domain_save,
67 [['dom', 'str'],
68 ['file', 'str']])
69 deferred = fn(req.args, {'dom': self.dom.id})
70 deferred.addCallback(self._op_save_cb, req)
71 deferred.addErrback(self._op_save_err, req)
72 return deferred
74 def _op_save_cb(self, val, req):
75 return 0
77 def _op_save_err(self, err, req):
78 req.setResponseCode(http.BAD_REQUEST, "Error: "+ str(err))
79 return str(err)
81 def op_migrate(self, op, req):
82 fn = FormFn(self.xd.domain_migrate,
83 [['dom', 'str'],
84 ['destination', 'str'],
85 ['live', 'int'],
86 ['resource', 'int']])
87 deferred = fn(req.args, {'dom': self.dom.id})
88 print 'op_migrate>', deferred
89 deferred.addCallback(self._op_migrate_cb, req)
90 deferred.addErrback(self._op_migrate_err, req)
91 return deferred
93 def _op_migrate_cb(self, info, req):
94 print '_op_migrate_cb>', info, req
95 #req.setResponseCode(http.ACCEPTED)
96 host = info.dst_host
97 port = info.dst_port
98 dom = info.dst_dom
99 url = "http://%s:%d/xend/domain/%d" % (host, port, dom)
100 req.setHeader("Location", url)
101 print '_op_migrate_cb> url=', url
102 return url
104 def _op_migrate_err(self, err, req):
105 print '_op_migrate_err>', err, req
106 req.setResponseCode(http.BAD_REQUEST, "Error: "+ str(err))
107 return str(err)
109 def op_pincpu(self, op, req):
110 fn = FormFn(self.xd.domain_pincpu,
111 [['dom', 'str'],
112 ['cpu', 'int']])
113 val = fn(req.args, {'dom': self.dom.id})
114 return val
116 def op_cpu_bvt_set(self, op, req):
117 fn = FormFn(self.xd.domain_cpu_bvt_set,
118 [['dom', 'str'],
119 ['mcuadv', 'int'],
120 ['warpback', 'int'],
121 ['warpvalue', 'int'],
122 ['warpl', 'long'],
123 ['warpu', 'long']])
124 val = fn(req.args, {'dom': self.dom.id})
125 return val
127 def op_cpu_atropos_set(self, op, req):
128 fn = FormFn(self.xd.domain_cpu_atropos_set,
129 [['dom', 'str'],
130 ['period', 'int'],
131 ['slice', 'int'],
132 ['latency', 'int'],
133 ['xtratime', 'int']])
134 val = fn(req.args, {'dom': self.dom.id})
135 return val
137 def op_cpu_sedf_set(self, op, req):
138 fn = FormFn(self.xd.domain_cpu_sedf_set,
139 [['dom', 'str'],
140 ['period', 'int'],
141 ['slice', 'int'],
142 ['latency', 'int'],
143 ['extratime', 'int'],
144 ['weight', 'int']])
145 val = fn(req.args, {'dom': self.dom.id})
146 return val
148 def op_maxmem_set(self, op, req):
149 fn = FormFn(self.xd.domain_maxmem_set,
150 [['dom', 'str'],
151 ['memory', 'int']])
152 val = fn(req.args, {'dom': self.dom.id})
153 return val
155 def op_device_create(self, op, req):
156 fn = FormFn(self.xd.domain_device_create,
157 [['dom', 'str'],
158 ['config', 'sxpr']])
159 d = fn(req.args, {'dom': self.dom.id})
160 return d
162 def op_device_destroy(self, op, req):
163 fn = FormFn(self.xd.domain_device_destroy,
164 [['dom', 'str'],
165 ['type', 'str'],
166 ['idx', 'str']])
167 val = fn(req.args, {'dom': self.dom.id})
168 return val
170 def op_device_configure(self, op, req):
171 fn = FormFn(self.xd.domain_device_configure,
172 [['dom', 'str'],
173 ['config', 'sxpr'],
174 ['idx', 'str']])
175 d = fn(req.args, {'dom': self.dom.id})
176 return d
178 def op_vifs(self, op, req):
179 devs = self.xd.domain_vif_ls(self.dom.id)
180 return [ dev.sxpr() for dev in devs ]
182 def op_vif(self, op, req):
183 fn = FormFn(self.xd.domain_vif_get,
184 [['dom', 'str'],
185 ['vif', 'str']])
186 val = fn(req.args, {'dom': self.dom.id})
187 return val
189 def op_vbds(self, op, req):
190 devs = self.xd.domain_vbd_ls(self.dom.id)
191 return [ dev.sxpr() for dev in devs ]
193 def op_vbd(self, op, req):
194 fn = FormFn(self.xd.domain_vbd_get,
195 [['dom', 'str'],
196 ['vbd', 'str']])
197 val = fn(req.args, {'dom': self.dom.id})
198 return val
200 def op_mem_target_set(self, op, req):
201 fn = FormFn(self.xd.domain_mem_target_set,
202 [['dom', 'str'],
203 ['target', 'int']])
204 val = fn(req.args, {'dom': self.dom.id})
205 return val
207 def render_POST(self, req):
208 return self.perform(req)
210 def render_GET(self, req):
211 op = req.args.get('op')
212 if op and op[0] in ['vifs', 'vif', 'vbds', 'vbd', 'mem_target_set']:
213 return self.perform(req)
214 if self.use_sxp(req):
215 req.setHeader("Content-Type", sxp.mime_type)
216 sxp.show(self.dom.sxpr(), out=req)
217 else:
218 req.write('<html><head></head><body>')
219 self.print_path(req)
220 #self.ls()
221 req.write('<p>%s</p>' % self.dom)
222 if self.dom.console:
223 cinfo = self.dom.console
224 cid = str(cinfo.console_port)
225 #todo: Local xref: need to know server prefix.
226 req.write('<p><a href="/xend/console/%s">Console %s</a></p>'
227 % (cid, cid))
228 req.write('<p><a href="%s">Connect to console</a></p>'
229 % cinfo.uri())
230 if self.dom.config:
231 req.write("<code><pre>")
232 PrettyPrint.prettyprint(self.dom.config, out=req)
233 req.write("</pre></code>")
234 self.form(req)
235 req.write('</body></html>')
236 return ''
238 def form(self, req):
239 url = req.prePathURL()
240 req.write('<form method="post" action="%s">' % url)
241 req.write('<input type="submit" name="op" value="unpause">')
242 req.write('<input type="submit" name="op" value="pause">')
243 req.write('</form>')
245 req.write('<form method="post" action="%s">' % url)
246 req.write('<input type="submit" name="op" value="destroy">')
247 req.write('<input type="radio" name="reason" value="halt" checked>Halt')
248 req.write('<input type="radio" name="reason" value="reboot">Reboot')
249 req.write('</form>')
251 req.write('<form method="post" action="%s">' % url)
252 req.write('<input type="submit" name="op" value="shutdown">')
253 req.write('<input type="radio" name="reason" value="poweroff" checked>Poweroff')
254 req.write('<input type="radio" name="reason" value="halt">Halt')
255 req.write('<input type="radio" name="reason" value="reboot">Reboot')
256 req.write('</form>')
258 req.write('<form method="post" action="%s">' % url)
259 req.write('<br><input type="submit" name="op" value="save">')
260 req.write(' To file: <input type="text" name="file">')
261 req.write('</form>')
263 req.write('<form method="post" action="%s">' % url)
264 req.write('<br><input type="submit" name="op" value="migrate">')
265 req.write(' To host: <input type="text" name="destination">')
266 req.write('<input type="checkbox" name="live" value="1">Live')
267 req.write('</form>')