ia64/xen-unstable

view tools/python/xen/sv/Main.py @ 6538:84ee014ebd41

Merge xen-vtx-unstable.hg
author adsharma@los-vmm.sc.intel.com
date Wed Aug 17 12:34:38 2005 -0800 (2005-08-17)
parents 23979fb12c49 356b14d5ffc8
children 99914b54f7bf
line source
2 from xen.sv.HTMLBase import HTMLBase
3 from xen.sv.NodeInfo import NodeInfo
4 from xen.sv.DomInfo import DomInfo
5 from xen.sv.CreateDomain import CreateDomain
6 from xen.sv.RestoreDomain import RestoreDomain
8 from xen.sv.util import getVar
10 # adapter to make this all work with mod_python
11 # as opposed to Twisted
12 # (c) Tom Wilkie 2005
14 class Args:
15 def __init__( self, req ):
16 from mod_python.util import FieldStorage
17 self.fieldStorage = FieldStorage( req, True )
19 # return a list of values for the given key,
20 # or None if key not there
21 def get( self, var ):
22 retVar = self.fieldStorage.getlist( var )
23 if len( retVar ) == 0:
24 return None
25 else:
26 return retVar
28 # return a list of tuples,
29 # (key, value) where value is a list of values
30 def items( self ):
31 result = [];
32 for key in self.fieldStorage.keys():
33 result.append( (key, self.fieldStorage.getlist( key ) ) )
34 return result
36 class TwistedAdapter:
37 def __init__( self, req ):
38 self.args = Args( req )
39 self.uri = req.unparsed_uri
40 self.url = req.uri
41 self.write = req.write
43 # This is the Main class
44 # It peices together all the modules
46 class Main:
47 def __init__( self ):
48 self.modules = { "node": NodeInfo,
49 "create": CreateDomain,
50 "restore" : RestoreDomain,
51 "info": DomInfo }
53 self.init_done = False
55 def init_modules( self, request ):
56 for moduleName, module in self.modules.iteritems():
57 self.modules[ moduleName ] = module( self.urlWriter( moduleName, request.url ) )
59 def render_menu( self, request ):
60 if not self.init_done:
61 self.init_modules( request )
62 self.init_done = True
64 for moduleName, module in self.modules.iteritems():
65 module.write_MENU( request )
66 request.write( "\n" )
68 def render_main( self, request ):
69 if not self.init_done:
70 self.init_modules( request )
71 self.init_done = True
73 moduleName = getVar('mod', request)
74 if moduleName not in self.modules:
75 request.write( '<p>Please select a module</p>' )
76 else:
77 module = self.modules[ moduleName ]
78 module.write_BODY( request )
80 def do_POST( self, request ):
81 if not self.init_done:
82 self.init_modules( request )
83 self.init_done = True
85 moduleName = getVar( 'mod', request )
86 if moduleName in self.modules:
87 self.modules[ moduleName ].perform( request )
89 def urlWriter( self, module, url ):
90 return lambda x: "%s?mod=%s%s" % ( url, module, x )