ia64/xen-unstable

view tools/python/xen/xend/server/XMLRPCServer.py @ 9516:58938b561b66

Remove vcpu_avail from the public S-Expression that's passed over the wire.
This trips up the XML-RPC layer on large SMP systems and isn't actually used
by xm.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
author anthony@rhesis.austin.ibm.com
date Wed Mar 29 14:50:57 2006 +0100 (2006-03-29)
parents 33df7d4eff23
children ff124973a28a
line source
1 #============================================================================
2 # This library is free software; you can redistribute it and/or
3 # modify it under the terms of version 2.1 of the GNU Lesser General Public
4 # License as published by the Free Software Foundation.
5 #
6 # This library is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # Lesser General Public License for more details.
10 #
11 # You should have received a copy of the GNU Lesser General Public
12 # License along with this library; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 #============================================================================
15 # Copyright (C) 2006 Anthony Liguori <aliguori@us.ibm.com>
16 # Copyright (C) 2006 XenSource Ltd.
17 #============================================================================
19 import xmlrpclib
21 from xen.xend import XendDomain, XendDomainInfo, XendNode, \
22 XendLogging, XendDmesg
23 from xen.util.xmlrpclib2 import UnixXMLRPCServer, TCPXMLRPCServer
25 from xen.xend.XendClient import XML_RPC_SOCKET, ERROR_INVALID_DOMAIN
26 from xen.xend.XendError import *
27 from types import ListType
29 def lookup(domid):
30 info = XendDomain.instance().domain_lookup_by_name_or_id(domid)
31 if not info:
32 raise XendInvalidDomain(str(domid))
33 return info
35 def dispatch(domid, fn, args):
36 info = lookup(domid)
37 return getattr(info, fn)(*args)
39 # vcpu_avail is a long and is not needed by the clients. It's far easier
40 # to just remove it then to try and marshal the long.
41 def fixup_sxpr(sexpr):
42 ret = []
43 for k in sexpr:
44 if type(k) is ListType:
45 if len(k) != 2 or k[0] != 'vcpu_avail':
46 ret.append(fixup_sxpr(k))
47 else:
48 ret.append(k)
49 return ret
51 def domain(domid):
52 info = lookup(domid)
53 return fixup_sxpr(info.sxpr())
55 def domains(detail=1):
56 if detail < 1:
57 return XendDomain.instance().list_names()
58 else:
59 domains = XendDomain.instance().list_sorted()
60 return map(lambda dom: fixup_sxpr(dom.sxpr()), domains)
62 def domain_create(config):
63 info = XendDomain.instance().domain_create(config)
64 return fixup_sxpr(info.sxpr())
66 def domain_restore(src):
67 info = XendDomain.instance().domain_restore(src)
68 return fixup_sxpr(info.sxpr())
70 def get_log():
71 f = open(XendLogging.getLogFilename(), 'r')
72 try:
73 return f.read()
74 finally:
75 f.close()
77 methods = ['device_create', 'destroyDevice', 'getDeviceSxprs',
78 'setMemoryTarget', 'setName', 'setVCpuCount', 'shutdown',
79 'send_sysrq', 'getVCPUInfo', 'waitForDevices']
81 exclude = ['domain_create', 'domain_restore']
83 class XMLRPCServer:
84 def __init__(self, use_tcp=False):
85 self.ready = False
86 self.use_tcp = use_tcp
88 def run(self):
89 if self.use_tcp:
90 # bind to something fixed for now as we may eliminate
91 # tcp support completely.
92 self.server = TCPXMLRPCServer(("localhost", 8005), logRequests=False)
93 else:
94 self.server = UnixXMLRPCServer(XML_RPC_SOCKET, False)
96 # Functions in XendDomainInfo
97 for name in methods:
98 fn = eval("lambda domid, *args: dispatch(domid, '%s', args)"%name)
99 self.server.register_function(fn, "xend.domain.%s" % name)
101 # Functions in XendDomain
102 inst = XendDomain.instance()
103 for name in dir(inst):
104 fn = getattr(inst, name)
105 if name.startswith("domain_") and callable(fn):
106 if name not in exclude:
107 self.server.register_function(fn, "xend.domain.%s" % name[7:])
109 # Functions in XendNode and XendDmesg
110 for type, lst, n in [(XendNode, ['info', 'cpu_bvt_slice_set'], 'node'),
111 (XendDmesg, ['info', 'clear'], 'node.dmesg')]:
112 inst = type.instance()
113 for name in lst:
114 self.server.register_function(getattr(inst, name),
115 "xend.%s.%s" % (n, name))
117 # A few special cases
118 self.server.register_function(domain, 'xend.domain')
119 self.server.register_function(domains, 'xend.domains')
120 self.server.register_function(get_log, 'xend.node.log')
121 self.server.register_function(domain_create, 'xend.domain.create')
122 self.server.register_function(domain_restore, 'xend.domain.restore')
124 self.server.register_introspection_functions()
125 self.ready = True
126 self.server.serve_forever()