debuggers.hg

view tools/python/xen/xend/server/SrvUsbif.py @ 4655:a838a908e38e

bitkeeper revision 1.1327.2.2 (4267a9b3MhPpljnjQ5IbfLdzcW2K3w)

Remove twisted from the HTTP server and replace with a
threaded server. Add classes to provide tcp and unix servers
using threads instead of twisted. Remove use of twisted from
the consoles, event server and HTTP resources

Signed-off-by: Mike Wray <mike.wray@hp.com>
author mjw@wray-m-3.hpl.hp.com
date Thu Apr 21 13:25:07 2005 +0000 (2005-04-21)
parents 7fc6eac6da3a
children
line source
1 # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
3 from xen.web 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 val = fn(req.args, {'dom': self.dom.id})
52 req.setResponseCode(http.ACCEPTED)
53 req.setHeader("Location", "%s/.." % req.prePathURL())
54 return val
56 def op_destroy(self, op, req):
57 fn = FormFn(self.xd.domain_destroy,
58 [['dom', 'str'],
59 ['reason', 'str']])
60 val = fn(req.args, {'dom': self.dom.id})
61 req.setHeader("Location", "%s/.." % req.prePathURL())
62 return val
64 def op_save(self, op, req):
65 fn = FormFn(self.xd.domain_save,
66 [['dom', 'str'],
67 ['file', 'str']])
68 deferred = fn(req.args, {'dom': self.dom.id})
69 deferred.addCallback(self._op_save_cb, req)
70 deferred.addErrback(self._op_save_err, req)
71 return deferred
73 def _op_save_cb(self, val, req):
74 return 0
76 def _op_save_err(self, err, req):
77 req.setResponseCode(http.BAD_REQUEST, "Error: "+ str(err))
78 return str(err)
80 def op_migrate(self, op, req):
81 fn = FormFn(self.xd.domain_migrate,
82 [['dom', 'str'],
83 ['destination', 'str'],
84 ['live', 'int']])
85 deferred = fn(req.args, {'dom': self.dom.id})
86 print 'op_migrate>', deferred
87 deferred.addCallback(self._op_migrate_cb, req)
88 deferred.addErrback(self._op_migrate_err, req)
89 return deferred
91 def _op_migrate_cb(self, info, req):
92 print '_op_migrate_cb>', info, req
93 #req.setResponseCode(http.ACCEPTED)
94 host = info.dst_host
95 port = info.dst_port
96 dom = info.dst_dom
97 url = "http://%s:%d/xend/domain/%d" % (host, port, dom)
98 req.setHeader("Location", url)
99 print '_op_migrate_cb> url=', url
100 return url
102 def _op_migrate_err(self, err, req):
103 print '_op_migrate_err>', err, req
104 req.setResponseCode(http.BAD_REQUEST, "Error: "+ str(err))
105 return str(err)
107 def op_pincpu(self, op, req):
108 fn = FormFn(self.xd.domain_pincpu,
109 [['dom', 'str'],
110 ['cpu', 'int']])
111 val = fn(req.args, {'dom': self.dom.id})
112 return val
114 def op_cpu_bvt_set(self, op, req):
115 fn = FormFn(self.xd.domain_cpu_bvt_set,
116 [['dom', 'str'],
117 ['mcuadv', 'int'],
118 ['warpback', 'int'],
119 ['warpvalue', 'int'],
120 ['warpl', 'long'],
121 ['warpu', 'long']])
122 val = fn(req.args, {'dom': self.dom.id})
123 return val
125 def op_cpu_fbvt_set(self, op, req):
126 fn = FormFn(self.xd.domain_cpu_fbvt_set,
127 [['dom', 'str'],
128 ['mcuadv', 'int'],
129 ['warp', 'int'],
130 ['warpl', 'int'],
131 ['warpu', 'int']])
132 val = fn(req.args, {'dom': self.dom.id})
133 return val
135 def op_maxmem_set(self, op, req):
136 fn = FormFn(self.xd.domain_maxmem_set,
137 [['dom', 'str'],
138 ['memory', 'int']])
139 val = fn(req.args, {'dom': self.dom.id})
140 return val
142 def op_device_create(self, op, req):
143 fn = FormFn(self.xd.domain_device_create,
144 [['dom', 'str'],
145 ['config', 'sxpr']])
146 d = fn(req.args, {'dom': self.dom.id})
147 return d
149 def op_device_destroy(self, op, req):
150 fn = FormFn(self.xd.domain_device_destroy,
151 [['dom', 'str'],
152 ['type', 'str'],
153 ['idx', 'str']])
154 val = fn(req.args, {'dom': self.dom.id})
155 return val
157 def op_vifs(self, op, req):
158 devs = self.xd.domain_vif_ls(self.dom.id)
159 return [ dev.sxpr() for dev in devs ]
161 def op_vif(self, op, req):
162 fn = FormFn(self.xd.domain_vif_get,
163 [['dom', 'str'],
164 ['vif', 'str']])
165 val = fn(req.args, {'dom': self.dom.id})
166 return val
168 def op_vbds(self, op, req):
169 devs = self.xd.domain_vbd_ls(self.dom.id)
170 return [ dev.sxpr() for dev in devs ]
172 def op_vbd(self, op, req):
173 fn = FormFn(self.xd.domain_vbd_get,
174 [['dom', 'str'],
175 ['vbd', 'str']])
176 val = fn(req.args, {'dom': self.dom.id})
177 return val
179 def render_POST(self, req):
180 return self.perform(req)
182 def render_GET(self, req):
183 op = req.args.get('op')
184 if op and op[0] in ['vifs', 'vif', 'vbds', 'vbd']:
185 return self.perform(req)
186 if self.use_sxp(req):
187 req.setHeader("Content-Type", sxp.mime_type)
188 sxp.show(self.dom.sxpr(), out=req)
189 else:
190 req.write('<html><head></head><body>')
191 self.print_path(req)
192 #self.ls()
193 req.write('<p>%s</p>' % self.dom)
194 if self.dom.console:
195 cinfo = self.dom.console
196 cid = str(cinfo.console_port)
197 #todo: Local xref: need to know server prefix.
198 req.write('<p><a href="/xend/console/%s">Console %s</a></p>'
199 % (cid, cid))
200 req.write('<p><a href="%s">Connect to console</a></p>'
201 % cinfo.uri())
202 if self.dom.config:
203 req.write("<code><pre>")
204 PrettyPrint.prettyprint(self.dom.config, out=req)
205 req.write("</pre></code>")
206 self.form(req)
207 req.write('</body></html>')
208 return ''
210 def form(self, req):
211 url = req.prePathURL()
212 req.write('<form method="post" action="%s">' % url)
213 req.write('<input type="submit" name="op" value="unpause">')
214 req.write('<input type="submit" name="op" value="pause">')
215 req.write('</form>')
217 req.write('<form method="post" action="%s">' % url)
218 req.write('<input type="submit" name="op" value="destroy">')
219 req.write('<input type="radio" name="reason" value="halt" checked>Halt')
220 req.write('<input type="radio" name="reason" value="reboot">Reboot')
221 req.write('</form>')
223 req.write('<form method="post" action="%s">' % url)
224 req.write('<input type="submit" name="op" value="shutdown">')
225 req.write('<input type="radio" name="reason" value="poweroff" checked>Poweroff')
226 req.write('<input type="radio" name="reason" value="halt">Halt')
227 req.write('<input type="radio" name="reason" value="reboot">Reboot')
228 req.write('</form>')
230 req.write('<form method="post" action="%s">' % url)
231 req.write('<br><input type="submit" name="op" value="save">')
232 req.write(' To file: <input type="text" name="file">')
233 req.write('</form>')
235 req.write('<form method="post" action="%s">' % url)
236 req.write('<br><input type="submit" name="op" value="migrate">')
237 req.write(' To host: <input type="text" name="destination">')
238 req.write('<input type="checkbox" name="live" value="1">Live')
239 req.write('</form>')