ia64/xen-unstable

changeset 12094:f297eef12823

[XEND] Exposing the XendAPI module in the XMLRPCServer

Signed-off-by: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Thu Oct 05 17:29:19 2006 +0100 (2006-10-05)
parents edb546bbfff0
children ddf523b09100
files tools/python/xen/xend/server/XMLRPCServer.py
line diff
     1.1 --- a/tools/python/xen/xend/server/XMLRPCServer.py	Thu Oct 05 17:29:19 2006 +0100
     1.2 +++ b/tools/python/xen/xend/server/XMLRPCServer.py	Thu Oct 05 17:29:19 2006 +0100
     1.3 @@ -16,7 +16,7 @@
     1.4  # Copyright (C) 2006 XenSource Ltd.
     1.5  #============================================================================
     1.6  
     1.7 -from types import ListType
     1.8 +import types
     1.9  import xmlrpclib
    1.10  from xen.util.xmlrpclib2 import UnixXMLRPCServer, TCPXMLRPCServer
    1.11  
    1.12 @@ -24,10 +24,23 @@ from xen.xend import XendDomain, XendDom
    1.13  from xen.xend import XendLogging, XendDmesg
    1.14  from xen.xend.XendClient import XML_RPC_SOCKET
    1.15  from xen.xend.XendLogging import log
    1.16 +from xen.xend.XendAPI import XendAPI
    1.17  from xen.xend.XendError import XendInvalidDomain
    1.18  
    1.19 +# vcpu_avail is a long and is not needed by the clients.  It's far easier
    1.20 +# to just remove it then to try and marshal the long.
    1.21 +def fixup_sxpr(sexpr):
    1.22 +    ret = []
    1.23 +    for k in sexpr:
    1.24 +        if type(k) in (types.ListType, types.TupleType):
    1.25 +            if len(k) != 2 or k[0] != 'vcpu_avail':
    1.26 +                ret.append(fixup_sxpr(k))
    1.27 +        else:
    1.28 +            ret.append(k)
    1.29 +    return ret
    1.30 +
    1.31  def lookup(domid):
    1.32 -    info = XendDomain.instance().domain_lookup_by_name_or_id(domid)
    1.33 +    info = XendDomain.instance().domain_lookup_nr(domid)
    1.34      if not info:
    1.35          raise XendInvalidDomain(str(domid))
    1.36      return info
    1.37 @@ -36,18 +49,6 @@ def dispatch(domid, fn, args):
    1.38      info = lookup(domid)
    1.39      return getattr(info, fn)(*args)
    1.40  
    1.41 -# vcpu_avail is a long and is not needed by the clients.  It's far easier
    1.42 -# to just remove it then to try and marshal the long.
    1.43 -def fixup_sxpr(sexpr):
    1.44 -    ret = []
    1.45 -    for k in sexpr:
    1.46 -        if type(k) is ListType:
    1.47 -            if len(k) != 2 or k[0] != 'vcpu_avail':
    1.48 -                ret.append(fixup_sxpr(k))
    1.49 -        else:
    1.50 -            ret.append(k)
    1.51 -    return ret
    1.52 -
    1.53  def domain(domid):
    1.54      info = lookup(domid)
    1.55      return fixup_sxpr(info.sxpr())
    1.56 @@ -92,6 +93,7 @@ class XMLRPCServer:
    1.57          
    1.58          self.ready = False        
    1.59          self.running = True
    1.60 +        self.xenapi = XendAPI()
    1.61          
    1.62      def run(self):
    1.63          if self.use_tcp:
    1.64 @@ -100,6 +102,16 @@ class XMLRPCServer:
    1.65          else:
    1.66              self.server = UnixXMLRPCServer(self.path, logRequests = False)
    1.67  
    1.68 +        # Register Xen API Functions
    1.69 +        # -------------------------------------------------------------------
    1.70 +        # exportable functions are ones that do not begin with '_'
    1.71 +        # and has the 'api' attribute.
    1.72 +        
    1.73 +        for meth_name in dir(self.xenapi):
    1.74 +            meth = getattr(self.xenapi, meth_name)
    1.75 +            if meth_name[0] != '_' and callable(meth) and hasattr(meth, 'api'):
    1.76 +                self.server.register_function(meth, getattr(meth, 'api'))
    1.77 +                
    1.78          # Legacy deprecated xm xmlrpc api
    1.79          # --------------------------------------------------------------------
    1.80