debuggers.hg

view tools/python/xen/xend/server/SrvVnetDir.py @ 4672:d781b9d08e80

bitkeeper revision 1.1327.2.4 (426918a34Af7gihN8mTkq-P3KrAZXg)

Remove twisted from save/migrate handling.
This needs to use threads, so add thread support for
http server requests.

Signed-off-by: Mike Wray <mike.wray@hp.com>
author mjw@wray-m-3.hpl.hp.com
date Fri Apr 22 15:30:43 2005 +0000 (2005-04-22)
parents dae98734f12e
children 369e382b2f81
line source
1 # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
3 from xen.xend import sxp
4 from xen.xend.Args import FormFn
5 from xen.xend import PrettyPrint
6 from xen.xend import XendVnet
8 from SrvDir import SrvDir
10 class SrvVnet(SrvDir):
12 def __init__(self, vnetinfo):
13 SrvDir.__init__(self)
14 self.vnetinfo = vnetinfo
15 self.xvnet = XendVnet.instance()
17 def op_delete(self, op, req):
18 val = self.xvnet.vnet_delete(self.vnetinfo.id)
19 return val
21 def render_POST(self, req):
22 return self.perform(req)
24 def render_GET(self, req):
25 if self.use_sxp(req):
26 req.setHeader("Content-Type", sxp.mime_type)
27 sxp.show(self.vnetinfo.sxpr(), out=req)
28 else:
29 req.write('<html><head></head><body>')
30 self.print_path(req)
31 req.write('<p>Vnet %s</p>' % self.vnetinfo.id)
32 req.write("<code><pre>")
33 PrettyPrint.prettyprint(self.vnetinfo.sxpr(), out=req)
34 req.write("</pre></code>")
35 self.form(req)
36 req.write('</body></html>')
37 return ''
39 def form(self, req):
40 url = req.prePathURL()
41 req.write('<form method="post" action="%s">' % url)
42 req.write('<input type="submit" name="op" value="delete">')
43 req.write('</form>')
45 class SrvVnetDir(SrvDir):
46 """Vnet directory.
47 """
49 def __init__(self):
50 SrvDir.__init__(self)
51 self.xvnet = XendVnet.instance()
53 def vnet(self, x):
54 val = None
55 vnetinfo = self.xvnet.vnet_get(x)
56 if not vnetinfo:
57 raise XendError('No such vnet ' + str(x))
58 val = SrvVnet(vnetinfo)
59 return val
61 def get(self, x):
62 v = SrvDir.get(self, x)
63 if v is not None:
64 return v
65 v = self.vnet(x)
66 return v
68 def op_create(self, op, req):
69 fn = FormFn(self.xvnet.vnet_create,
70 [['config', 'sxpr']])
71 val = fn(req.args, {})
72 return val
74 def render_POST(self, req):
75 return self.perform(req)
77 def render_GET(self, req):
78 if self.use_sxp(req):
79 req.setHeader("Content-Type", sxp.mime_type)
80 self.ls_vnet(req, 1)
81 else:
82 req.write("<html><head></head><body>")
83 self.print_path(req)
84 self.ls(req)
85 self.ls_vnet(req)
86 self.form(req)
87 req.write("</body></html>")
89 def ls_vnet(self, req, use_sxp=0):
90 url = req.prePathURL()
91 if not url.endswith('/'):
92 url += '/'
93 if use_sxp:
94 vnets = self.xvnet.vnet_ls()
95 sxp.show(vnets, out=req)
96 else:
97 vnets = self.xvnet.vnets()
98 vnets.sort(lambda x, y: cmp(x.id, y.id))
99 req.write('<ul>')
100 for v in vnets:
101 req.write('<li><a href="%s%s"> Vnet %s</a>' % (url, v.id, v.id))
102 req.write('</li>')
103 req.write('</ul>')
105 def form(self, req):
106 """Generate the form(s) for vnet dir operations.
107 """
108 req.write('<form method="post" action="%s" enctype="multipart/form-data">'
109 % req.prePathURL())
110 req.write('<button type="submit" name="op" value="create">Create Vnet</button>')
111 req.write('Config <input type="file" name="config"><br>')
112 req.write('</form>')