debuggers.hg

view tools/python/xen/xend/server/SrvDomain.py @ 4647:9c88ba91d330

bitkeeper revision 1.1346.1.1 (42670505dNhgnJm5dQD81pCalXMZgw)

manual merge
author iap10@freefall.cl.cam.ac.uk
date Thu Apr 21 01:42:29 2005 +0000 (2005-04-21)
parents 7fc6eac6da3a 0dc3b8b8c298
children 86285c9c18c1
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 return deferred
34 def op_unpause(self, op, req):
35 val = self.xd.domain_unpause(self.dom.name)
36 return val
38 def op_pause(self, op, req):
39 val = self.xd.domain_pause(self.dom.name)
40 return val
42 def op_shutdown(self, op, req):
43 fn = FormFn(self.xd.domain_shutdown,
44 [['dom', 'str'],
45 ['reason', 'str'],
46 ['key', 'int']])
47 val = fn(req.args, {'dom': self.dom.id})
48 req.setResponseCode(http.ACCEPTED)
49 req.setHeader("Location", "%s/.." % req.prePathURL())
50 return val
52 def op_destroy(self, op, req):
53 fn = FormFn(self.xd.domain_destroy,
54 [['dom', 'str'],
55 ['reason', 'str']])
56 val = fn(req.args, {'dom': self.dom.id})
57 req.setHeader("Location", "%s/.." % req.prePathURL())
58 return val
60 def op_save(self, op, req):
61 fn = FormFn(self.xd.domain_save,
62 [['dom', 'str'],
63 ['file', 'str']])
64 deferred = fn(req.args, {'dom': self.dom.id})
65 deferred.addCallback(self._op_save_cb, req)
66 return deferred
68 def _op_save_cb(self, val, req):
69 return 0
71 def op_migrate(self, op, req):
72 fn = FormFn(self.xd.domain_migrate,
73 [['dom', 'str'],
74 ['destination', 'str'],
75 ['live', 'int'],
76 ['resource', 'int']])
77 deferred = fn(req.args, {'dom': self.dom.id})
78 deferred.addCallback(self._op_migrate_cb, req)
79 return deferred
81 def _op_migrate_cb(self, info, req):
82 print '_op_migrate_cb>', info, req
83 #req.setResponseCode(http.ACCEPTED)
84 host = info.dst_host
85 port = info.dst_port
86 dom = info.dst_dom
87 url = "http://%s:%d/xend/domain/%d" % (host, port, dom)
88 req.setHeader("Location", url)
89 print '_op_migrate_cb> url=', url
90 return url
92 def op_pincpu(self, op, req):
93 fn = FormFn(self.xd.domain_pincpu,
94 [['dom', 'str'],
95 ['cpu', 'int']])
96 val = fn(req.args, {'dom': self.dom.id})
97 return val
99 def op_cpu_bvt_set(self, op, req):
100 fn = FormFn(self.xd.domain_cpu_bvt_set,
101 [['dom', 'str'],
102 ['mcuadv', 'int'],
103 ['warpback', 'int'],
104 ['warpvalue', 'int'],
105 ['warpl', 'long'],
106 ['warpu', 'long']])
107 val = fn(req.args, {'dom': self.dom.id})
108 return val
111 def op_cpu_sedf_set(self, op, req):
112 fn = FormFn(self.xd.domain_cpu_sedf_set,
113 [['dom', 'str'],
114 ['period', 'int'],
115 ['slice', 'int'],
116 ['latency', 'int'],
117 ['extratime', 'int'],
118 ['weight', 'int']])
119 val = fn(req.args, {'dom': self.dom.id})
120 return val
122 def op_maxmem_set(self, op, req):
123 fn = FormFn(self.xd.domain_maxmem_set,
124 [['dom', 'str'],
125 ['memory', 'int']])
126 val = fn(req.args, {'dom': self.dom.id})
127 return val
129 def op_device_create(self, op, req):
130 fn = FormFn(self.xd.domain_device_create,
131 [['dom', 'str'],
132 ['config', 'sxpr']])
133 d = fn(req.args, {'dom': self.dom.id})
134 return d
136 def op_device_refresh(self, op, req):
137 fn = FormFn(self.xd.domain_device_refresh,
138 [['dom', 'str'],
139 ['type', 'str'],
140 ['idx', 'str']])
141 val = fn(req.args, {'dom': self.dom.id})
142 return val
144 def op_device_destroy(self, op, req):
145 fn = FormFn(self.xd.domain_device_destroy,
146 [['dom', 'str'],
147 ['type', 'str'],
148 ['idx', 'str']])
149 val = fn(req.args, {'dom': self.dom.id})
150 return val
152 def op_device_configure(self, op, req):
153 fn = FormFn(self.xd.domain_device_configure,
154 [['dom', 'str'],
155 ['config', 'sxpr'],
156 ['idx', 'str']])
157 d = fn(req.args, {'dom': self.dom.id})
158 return d
160 def op_vif_credit_limit(self, op, req):
161 fn = FormFn(self.xd.domain_vif_credit_limit,
162 [['dom', 'str'],
163 ['vif', 'int'],
164 ['credit', 'int'],
165 ['period', 'int']])
166 val = fn(req.args, {'dom': self.dom.id})
167 return val
169 def op_vifs(self, op, req):
170 devs = self.xd.domain_vif_ls(self.dom.id)
171 return [ dev.sxpr() for dev in devs ]
173 def op_vif(self, op, req):
174 fn = FormFn(self.xd.domain_vif_get,
175 [['dom', 'str'],
176 ['vif', 'str']])
177 val = fn(req.args, {'dom': self.dom.id})
178 return val
180 def op_vbds(self, op, req):
181 devs = self.xd.domain_vbd_ls(self.dom.id)
182 return [ dev.sxpr() for dev in devs ]
184 def op_vbd(self, op, req):
185 fn = FormFn(self.xd.domain_vbd_get,
186 [['dom', 'str'],
187 ['vbd', 'str']])
188 val = fn(req.args, {'dom': self.dom.id})
189 return val
191 def op_mem_target_set(self, op, req):
192 fn = FormFn(self.xd.domain_mem_target_set,
193 [['dom', 'str'],
194 ['target', 'int']])
195 val = fn(req.args, {'dom': self.dom.id})
196 return val
198 def render_POST(self, req):
199 return self.perform(req)
201 def render_GET(self, req):
202 op = req.args.get('op')
203 if op and op[0] in ['vifs', 'vif', 'vbds', 'vbd', 'mem_target_set']:
204 return self.perform(req)
205 if self.use_sxp(req):
206 req.setHeader("Content-Type", sxp.mime_type)
207 sxp.show(self.dom.sxpr(), out=req)
208 else:
209 req.write('<html><head></head><body>')
210 self.print_path(req)
211 #self.ls()
212 req.write('<p>%s</p>' % self.dom)
213 if self.dom.console:
214 cinfo = self.dom.console
215 cid = str(cinfo.console_port)
216 #todo: Local xref: need to know server prefix.
217 req.write('<p><a href="/xend/console/%s">Console %s</a></p>'
218 % (cid, cid))
219 req.write('<p><a href="%s">Connect to console</a></p>'
220 % cinfo.uri())
221 if self.dom.config:
222 req.write("<code><pre>")
223 PrettyPrint.prettyprint(self.dom.config, out=req)
224 req.write("</pre></code>")
225 self.form(req)
226 req.write('</body></html>')
227 return ''
229 def form(self, req):
230 url = req.prePathURL()
231 req.write('<form method="post" action="%s">' % url)
232 req.write('<input type="submit" name="op" value="unpause">')
233 req.write('<input type="submit" name="op" value="pause">')
234 req.write('</form>')
236 req.write('<form method="post" action="%s">' % url)
237 req.write('<input type="submit" name="op" value="destroy">')
238 req.write('<input type="radio" name="reason" value="halt" checked>Halt')
239 req.write('<input type="radio" name="reason" value="reboot">Reboot')
240 req.write('</form>')
242 req.write('<form method="post" action="%s">' % url)
243 req.write('<input type="submit" name="op" value="shutdown">')
244 req.write('<input type="radio" name="reason" value="poweroff" checked>Poweroff')
245 req.write('<input type="radio" name="reason" value="halt">Halt')
246 req.write('<input type="radio" name="reason" value="reboot">Reboot')
247 req.write('</form>')
249 req.write('<form method="post" action="%s">' % url)
250 req.write('<br><input type="submit" name="op" value="save">')
251 req.write(' To file: <input type="text" name="file">')
252 req.write('</form>')
254 req.write('<form method="post" action="%s">' % url)
255 req.write('<br><input type="submit" name="op" value="migrate">')
256 req.write(' To host: <input type="text" name="destination">')
257 req.write('<input type="checkbox" name="live" value="1">Live')
258 req.write('</form>')