ia64/xen-unstable

changeset 9421:5c9c44fc1c39

Use XML-RPC as a transport for Xend instead of S-Expression/HTTP.

This changeset introduces a new XML-RPC service that runs in Xend and the
required changes to have xm use this new service by default.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
author anthony@rhesis.austin.ibm.com
date Thu Mar 23 11:25:37 2006 +0100 (2006-03-23)
parents 2c77d26871f7
children 8afbc2586121
files tools/python/xen/util/xmlrpclib2.py tools/python/xen/xend/XendClient.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendError.py tools/python/xen/xend/XendRoot.py tools/python/xen/xend/server/SrvServer.py tools/python/xen/xend/server/XMLRPCServer.py tools/python/xen/xm/create.py tools/python/xen/xm/main.py tools/python/xen/xm/migrate.py tools/python/xen/xm/shutdown.py tools/python/xen/xm/sysrq.py
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/python/xen/util/xmlrpclib2.py	Thu Mar 23 11:25:37 2006 +0100
     1.3 @@ -0,0 +1,109 @@
     1.4 +#============================================================================
     1.5 +# This library is free software; you can redistribute it and/or
     1.6 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
     1.7 +# License as published by the Free Software Foundation.
     1.8 +#
     1.9 +# This library is distributed in the hope that it will be useful,
    1.10 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.11 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.12 +# Lesser General Public License for more details.
    1.13 +#
    1.14 +# You should have received a copy of the GNU Lesser General Public
    1.15 +# License along with this library; if not, write to the Free Software
    1.16 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.17 +#============================================================================
    1.18 +# Copyright (C) 2006 Anthony Liguori <aliguori@us.ibm.com>
    1.19 +#============================================================================
    1.20 +
    1.21 +"""
    1.22 +An enhanced XML-RPC client/server interface for Python.
    1.23 +"""
    1.24 +
    1.25 +from httplib import HTTPConnection, HTTP
    1.26 +from xmlrpclib import Transport
    1.27 +from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
    1.28 +import xmlrpclib, socket, os, traceback
    1.29 +
    1.30 +# A new ServerProxy that also supports httpu urls.  An http URL comes in the
    1.31 +# form:
    1.32 +#
    1.33 +# httpu:///absolute/path/to/socket.sock
    1.34 +#
    1.35 +# It assumes that the RPC handler is /RPC2.  This probably needs to be improved
    1.36 +
    1.37 +class HTTPUnixConnection(HTTPConnection):
    1.38 +    def connect(self):
    1.39 +        self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    1.40 +        self.sock.connect(self.host)
    1.41 +
    1.42 +class HTTPUnix(HTTP):
    1.43 +    _connection_class = HTTPUnixConnection
    1.44 +
    1.45 +class UnixTransport(Transport):
    1.46 +    def request(self, host, handler, request_body, verbose=0):
    1.47 +        self.__handler = handler
    1.48 +        return Transport.request(self, host, '/RPC2', request_body, verbose)
    1.49 +    def make_connection(self, host):
    1.50 +        return HTTPUnix(self.__handler)
    1.51 +
    1.52 +class ServerProxy(xmlrpclib.ServerProxy):
    1.53 +    def __init__(self, uri, transport=None, encoding=None, verbose=0,
    1.54 +                 allow_none=1):
    1.55 +        if transport == None:
    1.56 +            (protocol, rest) = uri.split(':', 1)
    1.57 +            if protocol == 'httpu':
    1.58 +                uri = 'http:' + rest
    1.59 +                transport = UnixTransport()
    1.60 +        xmlrpclib.ServerProxy.__init__(self, uri, transport, encoding,
    1.61 +                                       verbose, allow_none)
    1.62 +
    1.63 +# This is a base XML-RPC server for TCP.  It sets allow_reuse_address to
    1.64 +# true, and has an improved marshaller that serializes unknown exceptions
    1.65 +# with full traceback information.
    1.66 +
    1.67 +class TCPXMLRPCServer(SimpleXMLRPCServer):
    1.68 +    allow_reuse_address = True
    1.69 +
    1.70 +    def _marshaled_dispatch(self, data, dispatch_method = None):
    1.71 +        params, method = xmlrpclib.loads(data)
    1.72 +        try:
    1.73 +            if dispatch_method is not None:
    1.74 +                response = dispatch_method(method, params)
    1.75 +            else:
    1.76 +                response = self._dispatch(method, params)
    1.77 +
    1.78 +            response = (response,)
    1.79 +            response = xmlrpclib.dumps(response,
    1.80 +                                       methodresponse=1,
    1.81 +                                       allow_none=1)
    1.82 +        except xmlrpclib.Fault, fault:
    1.83 +            response = xmlrpclib.dumps(fault)
    1.84 +        except:
    1.85 +            response = xmlrpclib.dumps(
    1.86 +                xmlrpclib.Fault(1, traceback.format_exc())
    1.87 +                )
    1.88 +
    1.89 +        return response
    1.90 +
    1.91 +# This is a XML-RPC server that sits on a Unix domain socket.
    1.92 +# It implements proper support for allow_reuse_address by
    1.93 +# unlink()'ing an existing socket.
    1.94 +
    1.95 +class UnixXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
    1.96 +    def address_string(self):
    1.97 +        try:
    1.98 +            return SimpleXMLRPCRequestHandler.address_string(self)
    1.99 +        except ValueError, e:
   1.100 +            return self.client_address[:2]
   1.101 +
   1.102 +class UnixXMLRPCServer(TCPXMLRPCServer):
   1.103 +    address_family = socket.AF_UNIX
   1.104 +
   1.105 +    def __init__(self, addr, requestHandler=UnixXMLRPCRequestHandler,
   1.106 +                 logRequests=1):
   1.107 +        if self.allow_reuse_address:
   1.108 +            try:
   1.109 +                os.unlink(addr)
   1.110 +            except OSError, exc:
   1.111 +                pass
   1.112 +        TCPXMLRPCServer.__init__(self, addr, requestHandler, logRequests)
     2.1 --- a/tools/python/xen/xend/XendClient.py	Thu Mar 23 10:58:39 2006 +0100
     2.2 +++ b/tools/python/xen/xend/XendClient.py	Thu Mar 23 11:25:37 2006 +0100
     2.3 @@ -14,403 +14,11 @@
     2.4  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     2.5  #============================================================================
     2.6  # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
     2.7 +# Copyright (C) 2006 Anthony Liguori <aliguori@us.ibm.com>
     2.8  #============================================================================
     2.9  
    2.10 -"""Client API for the HTTP interface on xend.
    2.11 -Callable as a script - see main().
    2.12 -Supports inet or unix connection to xend.
    2.13 -
    2.14 -This API is the 'control-plane' for xend.
    2.15 -The 'data-plane' is done separately.
    2.16 -"""
    2.17 -import os
    2.18 -import sys
    2.19 -import types
    2.20 -
    2.21 -import sxp
    2.22 -import PrettyPrint
    2.23 -from XendProtocol import HttpXendClientProtocol, \
    2.24 -                         UnixXendClientProtocol, \
    2.25 -                         XendError
    2.26 -
    2.27 -def fileof(val):
    2.28 -    """Converter for passing configs or other 'large' data.
    2.29 -    Handles lists, files directly.
    2.30 -    Assumes a string is a file name and passes its contents.
    2.31 -    """
    2.32 -    if isinstance(val, types.ListType):
    2.33 -        return sxp.to_string(val)
    2.34 -    if isinstance(val, types.StringType):
    2.35 -        return file(val)
    2.36 -    if hasattr(val, 'readlines'):
    2.37 -        return val
    2.38 -    raise XendError('cannot convert value')
    2.39 -
    2.40 -class URL:
    2.41 -    """A URL.
    2.42 -    """
    2.43 -
    2.44 -    def __init__(self, proto='http', host='localhost', port=None, path='', query=None, frag=None):
    2.45 -        self.proto = proto
    2.46 -        self.host = host
    2.47 -        if port: port = int(port)
    2.48 -        self.port = port
    2.49 -        self.path = path
    2.50 -        self.query = query
    2.51 -        self.frag = frag
    2.52 -
    2.53 -    def url(self):
    2.54 -        """Get the full URL string including protocol, location and the full path.
    2.55 -        """
    2.56 -        return self.proto + '://' + self.location() + self.fullpath()
    2.57 -
    2.58 -    def location(self):
    2.59 -        """Get the location part of the URL, including host and port, if present.
    2.60 -        """
    2.61 -        if self.port:
    2.62 -            return self.host + ':' + str(self.port)
    2.63 -        else:
    2.64 -            return self.host
    2.65 -
    2.66 -    def fullpath(self):
    2.67 -        """Get the full path part of the URL, including query and fragment if present.
    2.68 -        """
    2.69 -        u = [ self.path ]
    2.70 -        if self.query:
    2.71 -            u.append('?')
    2.72 -            u.append(self.query)
    2.73 -        if self.frag:
    2.74 -            u.append('#')
    2.75 -            u.append(self.frag)
    2.76 -        return ''.join(u)
    2.77 -
    2.78 -    def relative(self, path='', query=None, frag=None):
    2.79 -        """Create a URL relative to this one.
    2.80 -        """
    2.81 -        return URL(proto=self.proto,
    2.82 -                   host=self.host,
    2.83 -                   port=self.port,
    2.84 -                   path=self.path + path,
    2.85 -                   query=query,
    2.86 -                   frag=frag)
    2.87 -
    2.88 -class Xend:
    2.89 -    """Client interface to Xend.
    2.90 -    """
    2.91 -
    2.92 -    """Default location of the xend server."""
    2.93 -    SRV_DEFAULT = "localhost:8000"
    2.94 -
    2.95 -    """Environment variable to set the location of xend."""
    2.96 -    SRV_VAR = "XEND"
    2.97 -
    2.98 -    """Default path to the xend root on the server."""
    2.99 -    ROOT_DEFAULT = "/xend/"
   2.100 -
   2.101 -    """Environment variable to set the xend root path."""
   2.102 -    ROOT_VAR = "XEND_ROOT"
   2.103 -
   2.104 -    def __init__(self, client=None, srv=None, root=None):
   2.105 -        """Create a xend client interface.
   2.106 -        If the client protocol is not specified, the default
   2.107 -        is to use a synchronous protocol.
   2.108 -
   2.109 -        @param client:  client protocol to use
   2.110 -        @param srv:     server host, and optional port (format host:port)
   2.111 -        @param root:    xend root path on the server
   2.112 -        """
   2.113 -        if client is None:
   2.114 -            client = HttpXendClientProtocol()
   2.115 -        self.client = client
   2.116 -        self.bind(srv, root)
   2.117 -
   2.118 -    def default_server(self):
   2.119 -        """Get the default location of the xend server.
   2.120 -        """
   2.121 -        return os.getenv(self.SRV_VAR, self.SRV_DEFAULT)
   2.122 -
   2.123 -    def default_root(self):
   2.124 -        """Get the default root path on the xend server.
   2.125 -        """
   2.126 -        return os.getenv(self.ROOT_VAR, self.ROOT_DEFAULT)
   2.127 -
   2.128 -    def bind(self, srv=None, root=None):
   2.129 -        """Bind to a given server.
   2.130 -
   2.131 -        @param srv:  server location (host:port)
   2.132 -        @param root: xend root path on the server
   2.133 -        """
   2.134 -        if srv is None: srv = self.default_server()
   2.135 -        if root is None: root = self.default_root()
   2.136 -        if not root.endswith('/'): root += '/'
   2.137 -        (host, port) = srv.split(':', 1)
   2.138 -        self.url = URL(host=host, port=port, path=root)
   2.139 -
   2.140 -    def xendGet(self, url, args=None):
   2.141 -        return self.client.xendGet(url, args)
   2.142 -
   2.143 -    def xendPost(self, url, data):
   2.144 -        return self.client.xendPost(url, data)
   2.145 -
   2.146 -    def nodeurl(self, id=''):
   2.147 -        return self.url.relative('node/' + str(id))
   2.148 -
   2.149 -    def domainurl(self, id=''):
   2.150 -        return self.url.relative('domain/' + str(id))
   2.151 -
   2.152 -    def deviceurl(self, id=''):
   2.153 -        return self.url.relative('device/' + str(id))
   2.154 -
   2.155 -    def vneturl(self, id=''):
   2.156 -        return self.url.relative('vnet/' + str(id))
   2.157 -
   2.158 -    def xend(self):
   2.159 -        return self.xendGet(self.url)
   2.160 -
   2.161 -    def xend_node(self):
   2.162 -        return self.xendGet(self.nodeurl())
   2.163 -        
   2.164 -    def xend_node_shutdown(self):
   2.165 -        return self.xendPost(self.nodeurl(),
   2.166 -                             {'op'      : 'shutdown'})
   2.167 -                
   2.168 -    def xend_node_restart(self):
   2.169 -        return self.xendPost(self.nodeurl(),
   2.170 -                             {'op'      : 'reboot'})
   2.171 -
   2.172 -    def xend_node_get_dmesg(self):
   2.173 -            return self.xendGet(self.nodeurl('dmesg'))
   2.174 -
   2.175 -    def xend_node_clear_dmesg(self):
   2.176 -        return self.xendPost(self.nodeurl('dmesg'),
   2.177 -                             {'op' : 'clear' } )
   2.178 -
   2.179 -    def xend_node_log(self):
   2.180 -        return self.xendGet(self.nodeurl('log'))
   2.181 -
   2.182 -    def xend_node_cpu_bvt_slice_set(self, ctx_allow):
   2.183 -        return self.xendPost(self.nodeurl(),
   2.184 -                             {'op'      : 'cpu_bvt_slice_set',
   2.185 -                              'ctx_allow' : ctx_allow })
   2.186 -
   2.187 -    def xend_domains(self):
   2.188 -        return self.xendGet(self.domainurl())
   2.189 -
   2.190 -    def xend_list_domains(self, detail = True):
   2.191 -        return self.xendGet(self.domainurl(),
   2.192 -                            {'detail': detail and '1' or '0'})
   2.193 -
   2.194 -    def xend_domain_vcpuinfo(self, dom):
   2.195 -        return self.xendGet(self.domainurl(dom), {'op': 'vcpuinfo'})
   2.196 -
   2.197 -    def xend_domain_create(self, conf):
   2.198 -        return self.xendPost(self.domainurl(),
   2.199 -                             {'op'      : 'create',
   2.200 -                              'config'  : fileof(conf) })
   2.201 -
   2.202 -    def xend_domain_restore(self, filename):
   2.203 -        return self.xendPost(self.domainurl(),
   2.204 -                             {'op'      : 'restore',
   2.205 -                              'file'    : filename })
   2.206 +from xen.util.xmlrpclib2 import ServerProxy
   2.207  
   2.208 -    def xend_domain_configure(self, id, conf):
   2.209 -        return self.xendPost(self.domainurl(id),
   2.210 -                             {'op'      : 'configure',
   2.211 -                              'config'  : fileof(conf) })
   2.212 -
   2.213 -    def xend_domain(self, id):
   2.214 -        return self.xendGet(self.domainurl(id))
   2.215 -
   2.216 -    def xend_domain_wait_for_devices(self, id):
   2.217 -        return self.xendPost(self.domainurl(id),
   2.218 -                             {'op'      : 'wait_for_devices' })
   2.219 -
   2.220 -    def xend_domain_unpause(self, id):
   2.221 -        return self.xendPost(self.domainurl(id),
   2.222 -                             {'op'      : 'unpause' })
   2.223 -
   2.224 -    def xend_domain_pause(self, id):
   2.225 -        return self.xendPost(self.domainurl(id),
   2.226 -                             {'op'      : 'pause' })
   2.227 -
   2.228 -    def xend_domain_rename(self, id, name):
   2.229 -        return self.xendPost(self.domainurl(id),
   2.230 -                             {'op'      : 'rename',
   2.231 -                              'name'    : name})
   2.232 -
   2.233 -    def xend_domain_shutdown(self, id, reason):
   2.234 -        return self.xendPost(self.domainurl(id),
   2.235 -                             {'op'      : 'shutdown',
   2.236 -                              'reason'  : reason})
   2.237 -
   2.238 -    def xend_domain_sysrq(self, id, key):
   2.239 -        return self.xendPost(self.domainurl(id),
   2.240 -                             {'op'      : 'sysrq',
   2.241 -                              'key'     : key})
   2.242 -
   2.243 -    def xend_domain_destroy(self, id):
   2.244 -        return self.xendPost(self.domainurl(id),
   2.245 -                             {'op'      : 'destroy' })
   2.246 -
   2.247 -    def xend_domain_save(self, id, filename):
   2.248 -        return self.xendPost(self.domainurl(id),
   2.249 -                             {'op'      : 'save',
   2.250 -                              'file'    : filename })
   2.251 -
   2.252 -    def xend_domain_migrate(self, id, dst, live=0, resource=0, port=0):
   2.253 -        return self.xendPost(self.domainurl(id),
   2.254 -                             {'op'         : 'migrate',
   2.255 -                              'destination': dst,
   2.256 -                              'live'       : live,
   2.257 -                              'resource'   : resource,
   2.258 -                              'port'       : port })
   2.259 -
   2.260 -    def xend_domain_pincpu(self, id, vcpu, cpumap):
   2.261 -        return self.xendPost(self.domainurl(id),
   2.262 -                             {'op'      : 'pincpu',
   2.263 -                              'vcpu'    : vcpu,
   2.264 -                              'cpumap'  : str(cpumap) })
   2.265 -
   2.266 -    def xend_domain_cpu_bvt_set(self, id, mcuadv, warpback, warpvalue, warpl, warpu):
   2.267 -        return self.xendPost(self.domainurl(id),
   2.268 -                             {'op'       : 'cpu_bvt_set',
   2.269 -                              'mcuadv'   : mcuadv,
   2.270 -                              'warpback' : warpback,
   2.271 -                              'warpvalue': warpvalue,
   2.272 -                              'warpl'    : warpl,
   2.273 -                              'warpu'    : warpu })
   2.274 -
   2.275 -    def xend_domain_cpu_sedf_get(self, id):
   2.276 -        return self.xendPost(self.domainurl(id),
   2.277 -                             {'op' : 'cpu_sedf_get'})
   2.278 -
   2.279 -    def xend_domain_cpu_sedf_set(self, id, period, slice, latency, extratime, weight):
   2.280 -        return self.xendPost(self.domainurl(id),
   2.281 -                             {'op'        : 'cpu_sedf_set',
   2.282 -                              'period'    : period,
   2.283 -                              'slice'     : slice,
   2.284 -			      'latency'   : latency,
   2.285 -			      'extratime' : extratime,
   2.286 -			      'weight'    : weight })
   2.287 -
   2.288 -    def xend_domain_maxmem_set(self, id, memory):
   2.289 -        return self.xendPost(self.domainurl(id),
   2.290 -                             { 'op'      : 'maxmem_set',
   2.291 -                               'memory'  : memory })
   2.292 -
   2.293 -    def xend_domain_mem_target_set(self, id, mem_target):
   2.294 -        val = self.xendPost(self.domainurl(id),
   2.295 -                            {'op'        : 'mem_target_set',
   2.296 -                             'target'    : mem_target })
   2.297 -        return val
   2.298 -
   2.299 -    def xend_domain_set_vcpus(self, dom, vcpus):
   2.300 -        return self.xendPost(self.domainurl(dom),
   2.301 -                            {'op'    : 'set_vcpus',
   2.302 -                             'vcpus' : vcpus })
   2.303 +XML_RPC_SOCKET = "/var/run/xend-xmlrpc.sock"
   2.304  
   2.305 -    def xend_domain_devices(self, id, type):
   2.306 -        return self.xendPost(self.domainurl(id),
   2.307 -                             {'op'      : 'devices',
   2.308 -                              'type'    : type })
   2.309 -
   2.310 -    def xend_domain_device_create(self, id, config):
   2.311 -        return self.xendPost(self.domainurl(id),
   2.312 -                             {'op'      : 'device_create',
   2.313 -                              'config'  : fileof(config) })
   2.314 -
   2.315 -    def xend_domain_device_refresh(self, id, type, dev):
   2.316 -        return self.xendPost(self.domainurl(id),
   2.317 -                             {'op'      : 'device_refresh',
   2.318 -                              'type'    : type,
   2.319 -                              'dev'     : dev })
   2.320 -
   2.321 -    def xend_domain_device_destroy(self, id, type, dev):
   2.322 -        return self.xendPost(self.domainurl(id),
   2.323 -                             {'op'      : 'device_destroy',
   2.324 -                              'type'    : type,
   2.325 -                              'dev'     : dev })
   2.326 -
   2.327 -    def xend_domain_device_configure(self, id, config, dev):
   2.328 -        return self.xendPost(self.domainurl(id),
   2.329 -                             {'op'      : 'device_configure',
   2.330 -                              'dev'     : dev,
   2.331 -                              'config'  : fileof(config) })
   2.332 -
   2.333 -    def xend_vnets(self):
   2.334 -        return self.xendGet(self.vneturl())
   2.335 -
   2.336 -    def xend_vnet_create(self, conf):
   2.337 -        return self.xendPost(self.vneturl(),
   2.338 -                             {'op'      : 'create',
   2.339 -                              'config'  : fileof(conf) })
   2.340 -
   2.341 -    def xend_vnet(self, id):
   2.342 -        return self.xendGet(self.vneturl(id))
   2.343 -
   2.344 -    def xend_vnet_delete(self, id):
   2.345 -        return self.xendPost(self.vneturl(id),
   2.346 -                              {'op'     : 'delete' })
   2.347 -
   2.348 -def getHttpServer(srv=None):
   2.349 -    """Create and return a xend client.
   2.350 -    """
   2.351 -    return Xend(srv=srv, client=HttpXendClientProtocol())
   2.352 -
   2.353 -def getUnixServer(srv=None):
   2.354 -    """Create and return a unix-domain xend client.
   2.355 -    """
   2.356 -    return Xend(client=UnixXendClientProtocol(srv))
   2.357 -
   2.358 -def xendmain(srv, fn, args, unix=False):
   2.359 -    if unix:
   2.360 -        xend = getUnixServer(srv)
   2.361 -    else:
   2.362 -        xend = getHttpServer(srv)
   2.363 -    xend.rc = 0
   2.364 -    try:
   2.365 -        v = getattr(xend, fn)(*args)
   2.366 -        PrettyPrint.prettyprint(v)
   2.367 -        return 0
   2.368 -    except XendError, err:
   2.369 -        print 'ERROR:', err
   2.370 -        return 1
   2.371 -
   2.372 -def main(argv):
   2.373 -    """Call an API function:
   2.374 -
   2.375 -    python XendClient.py fn args...
   2.376 -
   2.377 -    The leading 'xend_' on the function can be omitted.
   2.378 -    Example:
   2.379 -
   2.380 -python XendClient.py domains
   2.381 -    (0 8)
   2.382 -python XendClient.py domain 0
   2.383 -    (domain (id 0) (name Domain-0) (memory 128))
   2.384 -    """
   2.385 -    from getopt import getopt
   2.386 -    short_options = 'x:au:d'
   2.387 -    long_options = ['xend=', 'unix=', 'debug']
   2.388 -    (options, args) = getopt(argv[1:], short_options, long_options)
   2.389 -    srv = None
   2.390 -    unix = 1
   2.391 -    for k, v in options:
   2.392 -        if k in ['-x', '--xend']:
   2.393 -            srv = v
   2.394 -        elif k in ['-u', '--unix']:
   2.395 -            unix = int(v)
   2.396 -    if len(args):
   2.397 -        fn = args[0]
   2.398 -        args = args[1:]
   2.399 -    else:
   2.400 -        fn = 'xend'
   2.401 -        args = []
   2.402 -    if not fn.startswith('xend'):
   2.403 -        fn = 'xend_' + fn
   2.404 -    sys.exit(xendmain(srv, fn, args, unix=unix))
   2.405 -
   2.406 -if __name__ == "__main__":
   2.407 -    main(sys.argv)
   2.408 -else:    
   2.409 -    server = getUnixServer()
   2.410 +server = ServerProxy('httpu:///var/run/xend-xmlrpc.sock')
     3.1 --- a/tools/python/xen/xend/XendDomain.py	Thu Mar 23 10:58:39 2006 +0100
     3.2 +++ b/tools/python/xen/xend/XendDomain.py	Thu Mar 23 11:25:37 2006 +0100
     3.3 @@ -355,7 +355,7 @@ class XendDomain:
     3.4      def domain_unpause(self, domid):
     3.5          """Unpause domain execution."""
     3.6          try:
     3.7 -            dominfo = self.domain_lookup(domid)
     3.8 +            dominfo = self.domain_lookup_by_name_or_id_nr(domid)
     3.9              log.info("Domain %s (%d) unpaused.", dominfo.getName(),
    3.10                       dominfo.getDomid())
    3.11              return dominfo.unpause()
    3.12 @@ -366,7 +366,7 @@ class XendDomain:
    3.13      def domain_pause(self, domid):
    3.14          """Pause domain execution."""
    3.15          try:
    3.16 -            dominfo = self.domain_lookup(domid)
    3.17 +            dominfo = self.domain_lookup_by_name_or_id_nr(domid)
    3.18              log.info("Domain %s (%d) paused.", dominfo.getName(),
    3.19                       dominfo.getDomid())
    3.20              return dominfo.pause()
    3.21 @@ -377,10 +377,10 @@ class XendDomain:
    3.22      def domain_destroy(self, domid):
    3.23          """Terminate domain immediately."""
    3.24  
    3.25 -        if domid == PRIV_DOMAIN:
    3.26 -            raise XendError("Cannot destroy privileged domain %i" % domid)
    3.27 -        
    3.28 -        dominfo = self.domain_lookup(domid)
    3.29 +        dominfo = self.domain_lookup_by_name_or_id_nr(domid)
    3.30 +	if dominfo and dominfo.getDomid() == PRIV_DOMAIN:
    3.31 +            raise XendError("Cannot destroy privileged domain %s" % domid)
    3.32 +
    3.33          if dominfo:
    3.34              val = dominfo.destroy()
    3.35          else:
    3.36 @@ -393,7 +393,7 @@ class XendDomain:
    3.37      def domain_migrate(self, domid, dst, live=False, resource=0, port=0):
    3.38          """Start domain migration."""
    3.39  
    3.40 -        dominfo = self.domain_lookup(domid)
    3.41 +        dominfo = self.domain_lookup_by_name_or_id_nr(domid)
    3.42  
    3.43          if dominfo.getDomid() == PRIV_DOMAIN:
    3.44              raise XendError("Cannot migrate privileged domain %i" % domid)
    3.45 @@ -418,7 +418,7 @@ class XendDomain:
    3.46          """
    3.47  
    3.48          try:
    3.49 -            dominfo = self.domain_lookup(domid)
    3.50 +            dominfo = self.domain_lookup_by_name_or_id_nr(domid)
    3.51  
    3.52              if dominfo.getDomid() == PRIV_DOMAIN:
    3.53                  raise XendError("Cannot save privileged domain %i" % domid)
    3.54 @@ -438,7 +438,7 @@ class XendDomain:
    3.55  
    3.56          @param cpumap:  string repr of list of usable cpus
    3.57          """
    3.58 -        dominfo = self.domain_lookup(domid)
    3.59 +        dominfo = self.domain_lookup_by_name_or_id_nr(domid)
    3.60          # convert cpumap string into a list of ints
    3.61          cpumap = map(lambda x: int(x),
    3.62                       cpumap.replace("[", "").replace("]", "").split(","))
    3.63 @@ -451,7 +451,7 @@ class XendDomain:
    3.64                             warpu):
    3.65          """Set BVT (Borrowed Virtual Time) scheduler parameters for a domain.
    3.66          """
    3.67 -        dominfo = self.domain_lookup(domid)
    3.68 +        dominfo = self.domain_lookup_by_name_or_id_nr(domid)
    3.69          try:
    3.70              return xc.bvtsched_domain_set(dom=dominfo.getDomid(),
    3.71                                            mcuadv=mcuadv,
    3.72 @@ -464,7 +464,7 @@ class XendDomain:
    3.73      def domain_cpu_bvt_get(self, domid):
    3.74          """Get BVT (Borrowed Virtual Time) scheduler parameters for a domain.
    3.75          """
    3.76 -        dominfo = self.domain_lookup(domid)
    3.77 +        dominfo = self.domain_lookup_by_name_or_id_nr(domid)
    3.78          try:
    3.79              return xc.bvtsched_domain_get(dominfo.getDomid())
    3.80          except Exception, ex:
    3.81 @@ -475,7 +475,7 @@ class XendDomain:
    3.82                              weight):
    3.83          """Set Simple EDF scheduler parameters for a domain.
    3.84          """
    3.85 -        dominfo = self.domain_lookup(domid)
    3.86 +        dominfo = self.domain_lookup_by_name_or_id_nr(domid)
    3.87          try:
    3.88              return xc.sedf_domain_set(dominfo.getDomid(), period, slice_,
    3.89                                        latency, extratime, weight)
    3.90 @@ -485,7 +485,7 @@ class XendDomain:
    3.91      def domain_cpu_sedf_get(self, domid):
    3.92          """Get Simple EDF scheduler parameters for a domain.
    3.93          """
    3.94 -        dominfo = self.domain_lookup(domid)
    3.95 +        dominfo = self.domain_lookup_by_name_or_id_nr(domid)
    3.96          try:
    3.97              
    3.98              sedf_info = xc.sedf_domain_get(dominfo.getDomid())
    3.99 @@ -507,7 +507,7 @@ class XendDomain:
   3.100          @param mem: memory limit (in MiB)
   3.101          @return: 0 on success, -1 on error
   3.102          """
   3.103 -        dominfo = self.domain_lookup(domid)
   3.104 +        dominfo = self.domain_lookup_by_name_or_id_nr(domid)
   3.105          maxmem = int(mem) * 1024
   3.106          try:
   3.107              return xc.domain_setmaxmem(dominfo.getDomid(), maxmem)
   3.108 @@ -521,7 +521,7 @@ class XendDomain:
   3.109          @param last: last IO port
   3.110          @return: 0 on success, -1 on error
   3.111          """
   3.112 -        dominfo = self.domain_lookup(domid)
   3.113 +        dominfo = self.domain_lookup_by_name_or_id_nr(domid)
   3.114          nr_ports = last - first + 1
   3.115          try:
   3.116              return xc.domain_ioport_permission(dominfo.getDomid(),
   3.117 @@ -538,7 +538,7 @@ class XendDomain:
   3.118          @param last: last IO port
   3.119          @return: 0 on success, -1 on error
   3.120          """
   3.121 -        dominfo = self.domain_lookup(domid)
   3.122 +        dominfo = self.domain_lookup_by_name_or_id_nr(domid)
   3.123          nr_ports = last - first + 1
   3.124          try:
   3.125              return xc.domain_ioport_permission(dominfo.getDomid(),
     4.1 --- a/tools/python/xen/xend/XendError.py	Thu Mar 23 10:58:39 2006 +0100
     4.2 +++ b/tools/python/xen/xend/XendError.py	Thu Mar 23 11:25:37 2006 +0100
     4.3 @@ -15,9 +15,12 @@
     4.4  # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
     4.5  #============================================================================
     4.6  
     4.7 -class XendError(ValueError):
     4.8 +from xmlrpclib import Fault
     4.9 +
    4.10 +class XendError(Fault):
    4.11      
    4.12      def __init__(self, value):
    4.13 +        Fault.__init__(self, 2, value)
    4.14          self.value = value
    4.15  
    4.16      def __str__(self):
     5.1 --- a/tools/python/xen/xend/XendRoot.py	Thu Mar 23 10:58:39 2006 +0100
     5.2 +++ b/tools/python/xen/xend/XendRoot.py	Thu Mar 23 11:25:37 2006 +0100
     5.3 @@ -60,6 +60,10 @@ class XendRoot:
     5.4      """Default for the flag indicating whether xend should run an http server."""
     5.5      xend_http_server_default = 'no'
     5.6  
     5.7 +    xend_tcp_xmlrpc_server_default = 'no'
     5.8 +
     5.9 +    xend_unix_xmlrpc_server_default = 'yes'
    5.10 +
    5.11      """Default interface address xend listens at. """
    5.12      xend_address_default      = ''
    5.13  
    5.14 @@ -180,6 +184,12 @@ class XendRoot:
    5.15          """
    5.16          return self.get_config_bool("xend-http-server", self.xend_http_server_default)
    5.17  
    5.18 +    def get_xend_tcp_xmlrpc_server(self):
    5.19 +        return self.get_config_bool("xend-tcp-xmlrpc-server", self.xend_tcp_xmlrpc_server_default)
    5.20 +
    5.21 +    def get_xend_unix_xmlrpc_server(self):
    5.22 +        return self.get_config_bool("xend-unix-xmlrpc-server", self.xend_unix_xmlrpc_server_default)
    5.23 +
    5.24      def get_xend_relocation_server(self):
    5.25          """Get the flag indicating whether xend should run a relocation server.
    5.26          """
     6.1 --- a/tools/python/xen/xend/server/SrvServer.py	Thu Mar 23 10:58:39 2006 +0100
     6.2 +++ b/tools/python/xen/xend/server/SrvServer.py	Thu Mar 23 11:25:37 2006 +0100
     6.3 @@ -52,6 +52,7 @@ from xen.xend.XendLogging import log
     6.4  from xen.web.SrvDir import SrvDir
     6.5  
     6.6  from SrvRoot import SrvRoot
     6.7 +from XMLRPCServer import XMLRPCServer
     6.8  
     6.9  
    6.10  xroot = XendRoot.instance()
    6.11 @@ -114,4 +115,10 @@ def create():
    6.12          path = xroot.get_xend_unix_path()
    6.13          log.info('unix path=' + path)
    6.14          servers.add(UnixHttpServer(root, path))
    6.15 +
    6.16 +    if xroot.get_xend_tcp_xmlrpc_server():
    6.17 +        servers.add(XMLRPCServer(True))
    6.18 +
    6.19 +    if xroot.get_xend_unix_xmlrpc_server():
    6.20 +        servers.add(XMLRPCServer())
    6.21      return servers
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tools/python/xen/xend/server/XMLRPCServer.py	Thu Mar 23 11:25:37 2006 +0100
     7.3 @@ -0,0 +1,106 @@
     7.4 +#============================================================================
     7.5 +# This library is free software; you can redistribute it and/or
     7.6 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
     7.7 +# License as published by the Free Software Foundation.
     7.8 +#
     7.9 +# This library is distributed in the hope that it will be useful,
    7.10 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.11 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.12 +# Lesser General Public License for more details.
    7.13 +#
    7.14 +# You should have received a copy of the GNU Lesser General Public
    7.15 +# License along with this library; if not, write to the Free Software
    7.16 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    7.17 +#============================================================================
    7.18 +# Copyright (C) 2006 Anthony Liguori <aliguori@us.ibm.com>
    7.19 +#============================================================================
    7.20 +
    7.21 +from xen.xend import XendDomain, XendDomainInfo, XendNode, \
    7.22 +                     XendLogging, XendDmesg
    7.23 +from xen.util.xmlrpclib2 import UnixXMLRPCServer, TCPXMLRPCServer
    7.24 +
    7.25 +from xen.xend.XendClient import XML_RPC_SOCKET
    7.26 +
    7.27 +def lookup(domid):
    7.28 +    return XendDomain.instance().domain_lookup_by_name_or_id(domid)
    7.29 +
    7.30 +def dispatch(domid, fn, args):
    7.31 +    info = lookup(domid)
    7.32 +    return getattr(info, fn)(*args)
    7.33 +
    7.34 +def domain(domid):
    7.35 +    info = lookup(domid)
    7.36 +    return info.sxpr()
    7.37 +
    7.38 +def domains(detail=1):
    7.39 +    if detail < 1:
    7.40 +        return XendDomain.instance().list_names()
    7.41 +    else:
    7.42 +        domains = XendDomain.instance().list_sorted()
    7.43 +        return map(lambda dom: dom.sxpr(), domains)
    7.44 +
    7.45 +def domain_create(config):
    7.46 +    info = XendDomain.instance().domain_create(config)
    7.47 +    return info.sxpr()
    7.48 +
    7.49 +def domain_restore(src):
    7.50 +    info = XendDomain.instance().domain_restore(src)
    7.51 +    return info.sxpr()    
    7.52 +
    7.53 +def get_log():
    7.54 +    f = open(XendLogging.getLogFilename(), 'r')
    7.55 +    try:
    7.56 +        return f.read()
    7.57 +    finally:
    7.58 +        f.close()
    7.59 +
    7.60 +methods = ['device_create', 'destroyDevice', 'getDeviceSxprs',
    7.61 +           'setMemoryTarget', 'setName', 'setVCpuCount', 'shutdown',
    7.62 +           'send_sysrq', 'getVCPUInfo', 'waitForDevices']
    7.63 +
    7.64 +exclude = ['domain_create', 'domain_restore']
    7.65 +
    7.66 +class XMLRPCServer:
    7.67 +    def __init__(self, use_tcp=False):
    7.68 +        self.ready = False
    7.69 +        self.use_tcp = use_tcp
    7.70 +        
    7.71 +    def run(self):
    7.72 +        if self.use_tcp:
    7.73 +            # bind to something fixed for now as we may eliminate
    7.74 +            # tcp support completely.
    7.75 +            self.server = TCPXMLRPCServer(("localhost", 8005))
    7.76 +        else:
    7.77 +            self.server = UnixXMLRPCServer(XML_RPC_SOCKET)
    7.78 +
    7.79 +        # Functions in XendDomainInfo
    7.80 +        for name in methods:
    7.81 +            fn = eval("lambda domid, *args: dispatch(domid, '%s', args)"%name)
    7.82 +            self.server.register_function(fn, "xend.domain.%s" % name)
    7.83 +
    7.84 +        # Functions in XendDomain
    7.85 +        inst = XendDomain.instance()
    7.86 +        for name in dir(inst):
    7.87 +            fn = getattr(inst, name)
    7.88 +            if name.startswith("domain_") and callable(fn):
    7.89 +                if name not in exclude:
    7.90 +                    self.server.register_function(fn, "xend.domain.%s" % name[7:])
    7.91 +
    7.92 +        # Functions in XendNode and XendDmesg
    7.93 +        for type, lst, n in [(XendNode, ['info', 'cpu_bvt_slice_set'], 'node'),
    7.94 +                             (XendDmesg, ['info', 'clear'], 'node.dmesg')]:
    7.95 +            inst = type.instance()
    7.96 +            for name in lst:
    7.97 +                self.server.register_function(getattr(inst, name),
    7.98 +                                              "xend.%s.%s" % (n, name))
    7.99 +
   7.100 +        # A few special cases
   7.101 +        self.server.register_function(domain, 'xend.domain')
   7.102 +        self.server.register_function(domains, 'xend.domains')
   7.103 +        self.server.register_function(get_log, 'xend.node.log')
   7.104 +        self.server.register_function(domain_create, 'xend.domain.create')
   7.105 +        self.server.register_function(domain_restore, 'xend.domain.restore')
   7.106 +
   7.107 +        self.server.register_introspection_functions()
   7.108 +        self.ready = True
   7.109 +        self.server.serve_forever()
     8.1 --- a/tools/python/xen/xm/create.py	Thu Mar 23 10:58:39 2006 +0100
     8.2 +++ b/tools/python/xen/xm/create.py	Thu Mar 23 11:25:37 2006 +0100
     8.3 @@ -30,7 +30,7 @@ import re
     8.4  
     8.5  from xen.xend import sxp
     8.6  from xen.xend import PrettyPrint
     8.7 -from xen.xend.XendClient import server, XendError
     8.8 +from xen.xend.XendClient import server
     8.9  from xen.xend.XendBootloader import bootloader
    8.10  from xen.util import blkif
    8.11  
    8.12 @@ -813,8 +813,8 @@ def make_domain(opts, config):
    8.13      """
    8.14  
    8.15      try:
    8.16 -        dominfo = server.xend_domain_create(config)
    8.17 -    except XendError, ex:
    8.18 +        dominfo = server.xend.domain.create(config)
    8.19 +    except Exception, ex:
    8.20          import signal
    8.21          if vncpid:
    8.22              os.kill(vncpid, signal.SIGKILL)
    8.23 @@ -822,13 +822,17 @@ def make_domain(opts, config):
    8.24  
    8.25      dom = sxp.child_value(dominfo, 'name')
    8.26  
    8.27 -    if server.xend_domain_wait_for_devices(dom) < 0:
    8.28 -        server.xend_domain_destroy(dom)
    8.29 +    try:
    8.30 +        server.xend.domain.waitForDevices(dom)
    8.31 +    except:
    8.32 +        server.xend.domain.destroy(dom)
    8.33          err("Device creation failed for domain %s" % dom)
    8.34  
    8.35      if not opts.vals.paused:
    8.36 -        if server.xend_domain_unpause(dom) < 0:
    8.37 -            server.xend_domain_destroy(dom)
    8.38 +        try:
    8.39 +            server.xend.domain.unpause(dom)
    8.40 +        except:
    8.41 +            server.xend.domain.destroy(dom)
    8.42              err("Failed to unpause domain %s" % dom)
    8.43      opts.info("Started domain %s" % (dom))
    8.44      return int(sxp.child_value(dominfo, 'domid'))
     9.1 --- a/tools/python/xen/xm/main.py	Thu Mar 23 10:58:39 2006 +0100
     9.2 +++ b/tools/python/xen/xm/main.py	Thu Mar 23 11:25:37 2006 +0100
     9.3 @@ -29,8 +29,8 @@ import getopt
     9.4  import socket
     9.5  import warnings
     9.6  warnings.filterwarnings('ignore', category=FutureWarning)
     9.7 +import xmlrpclib
     9.8  
     9.9 -import xen.xend.XendError
    9.10  import xen.xend.XendProtocol
    9.11  
    9.12  from xen.xend import PrettyPrint
    9.13 @@ -39,6 +39,7 @@ from xen.xm.opts import *
    9.14  
    9.15  import console
    9.16  
    9.17 +from xen.xend.XendClient import server
    9.18  
    9.19  # getopt.gnu_getopt is better, but only exists in Python 2.3+.  Use
    9.20  # getopt.getopt if gnu_getopt is not available.  This will mean that options
    9.21 @@ -319,8 +320,7 @@ def xm_save(args):
    9.22          err("xm save: Unable to create file %s" % savefile)
    9.23          sys.exit(1)
    9.24      
    9.25 -    from xen.xend.XendClient import server
    9.26 -    server.xend_domain_save(dom, savefile)
    9.27 +    server.xend.domain.save(dom, savefile)
    9.28      
    9.29  def xm_restore(args):
    9.30      arg_check(args, "restore", 1)
    9.31 @@ -331,16 +331,14 @@ def xm_restore(args):
    9.32          err("xm restore: Unable to read file %s" % savefile)
    9.33          sys.exit(1)
    9.34  
    9.35 -    from xen.xend.XendClient import server
    9.36 -    server.xend_domain_restore(savefile)
    9.37 +    server.xend.domain.restore(savefile)
    9.38  
    9.39  
    9.40  def getDomains(domain_names):
    9.41 -    from xen.xend.XendClient import server
    9.42      if domain_names:
    9.43 -        return map(server.xend_domain, domain_names)
    9.44 +        return map(server.xend.domain, domain_names)
    9.45      else:
    9.46 -        return server.xend_list_domains()
    9.47 +        return server.xend.domains(1)
    9.48  
    9.49  
    9.50  def xm_list(args):
    9.51 @@ -416,12 +414,11 @@ def xm_brief_list(doms):
    9.52  
    9.53  def xm_vcpu_list(args):
    9.54  
    9.55 -    from xen.xend.XendClient import server
    9.56      if args:
    9.57 -        dominfo = map(server.xend_domain_vcpuinfo, args)
    9.58 +        dominfo = map(server.xend.domain.getVCPUInfo, args)
    9.59      else:
    9.60 -        doms = server.xend_list_domains(False)
    9.61 -        dominfo = map(server.xend_domain_vcpuinfo, doms)
    9.62 +        doms = server.xend.domains(False)
    9.63 +        dominfo = map(server.xend.domain.getVCPUInfo, doms)
    9.64  
    9.65      print 'Name                              ID  VCPU  CPU  State  Time(s)  CPU Affinity'
    9.66  
    9.67 @@ -475,8 +472,7 @@ def xm_vcpu_list(args):
    9.68              cpumap = map(lambda x: int(x), cpumap)
    9.69              cpumap.sort()
    9.70  
    9.71 -            from xen.xend.XendClient import server
    9.72 -            for x in server.xend_node()[1:]:
    9.73 +            for x in server.xend.node.info()[1:]:
    9.74                  if len(x) > 1 and x[0] == 'nr_cpus':
    9.75                      nr_cpus = int(x[1])
    9.76                      # normalize cpumap by modulus nr_cpus, and drop duplicates
    9.77 @@ -532,21 +528,18 @@ def xm_pause(args):
    9.78      arg_check(args, "pause", 1)
    9.79      dom = args[0]
    9.80  
    9.81 -    from xen.xend.XendClient import server
    9.82 -    server.xend_domain_pause(dom)
    9.83 +    server.xend.domain.pause(dom)
    9.84  
    9.85  def xm_unpause(args):
    9.86      arg_check(args, "unpause", 1)
    9.87      dom = args[0]
    9.88  
    9.89 -    from xen.xend.XendClient import server
    9.90 -    server.xend_domain_unpause(dom)
    9.91 +    server.xend.domain.unpause(dom)
    9.92  
    9.93  def xm_rename(args):
    9.94      arg_check(args, "rename", 2)
    9.95  
    9.96 -    from xen.xend.XendClient import server
    9.97 -    server.xend_domain_rename(args[0], args[1])
    9.98 +    server.xend.domain.setName(args[0], args[1])
    9.99  
   9.100  def xm_subcommand(command, args):
   9.101      cmd = __import__(command, globals(), locals(), 'xen.xm')
   9.102 @@ -574,8 +567,7 @@ def xm_vcpu_pin(args):
   9.103      vcpu = int(args[1])
   9.104      cpumap = cpu_make_map(args[2])
   9.105      
   9.106 -    from xen.xend.XendClient import server
   9.107 -    server.xend_domain_pincpu(dom, vcpu, cpumap)
   9.108 +    server.xend.domain.pincpu(dom, vcpu, cpumap)
   9.109  
   9.110  def xm_mem_max(args):
   9.111      arg_check(args, "mem-max", 2)
   9.112 @@ -583,8 +575,7 @@ def xm_mem_max(args):
   9.113      dom = args[0]
   9.114      mem = int_unit(args[1], 'm')
   9.115  
   9.116 -    from xen.xend.XendClient import server
   9.117 -    server.xend_domain_maxmem_set(dom, mem)
   9.118 +    server.xend.domain.maxmem_set(dom, mem)
   9.119      
   9.120  def xm_mem_set(args):
   9.121      arg_check(args, "mem-set", 2)
   9.122 @@ -592,20 +583,17 @@ def xm_mem_set(args):
   9.123      dom = args[0]
   9.124      mem_target = int_unit(args[1], 'm')
   9.125  
   9.126 -    from xen.xend.XendClient import server
   9.127 -    server.xend_domain_mem_target_set(dom, mem_target)
   9.128 +    server.xend.domain.setMemoryTarget(dom, mem_target)
   9.129      
   9.130  def xm_vcpu_set(args):
   9.131      arg_check(args, "vcpu-set", 2)
   9.132      
   9.133 -    from xen.xend.XendClient import server
   9.134 -    server.xend_domain_set_vcpus(args[0], int(args[1]))
   9.135 +    server.xend.domain.setVCpuCount(args[0], int(args[1]))
   9.136  
   9.137  
   9.138  def xm_destroy(args):
   9.139      arg_check(args, "destroy", 1)
   9.140 -    from xen.xend.XendClient import server
   9.141 -    server.xend_domain_destroy(args[0])
   9.142 +    server.xend.domain.destroy(args[0])
   9.143  
   9.144  
   9.145  def xm_domid(args):
   9.146 @@ -613,8 +601,7 @@ def xm_domid(args):
   9.147  
   9.148      name = args[0]
   9.149  
   9.150 -    from xen.xend.XendClient import server
   9.151 -    dom = server.xend_domain(name)
   9.152 +    dom = server.xend.domain(name)
   9.153      print sxp.child_value(dom, 'domid')
   9.154      
   9.155  def xm_domname(args):
   9.156 @@ -622,23 +609,20 @@ def xm_domname(args):
   9.157  
   9.158      name = args[0]
   9.159  
   9.160 -    from xen.xend.XendClient import server
   9.161 -    dom = server.xend_domain(name)
   9.162 +    dom = server.xend.domain(name)
   9.163      print sxp.child_value(dom, 'name')
   9.164  
   9.165  def xm_sched_bvt(args):
   9.166      arg_check(args, "sched-bvt", 6)
   9.167      dom = args[0]
   9.168      v = map(long, args[1:6])
   9.169 -    from xen.xend.XendClient import server
   9.170 -    server.xend_domain_cpu_bvt_set(dom, *v)
   9.171 +    server.xend.domain.cpu_bvt_set(dom, *v)
   9.172  
   9.173  def xm_sched_bvt_ctxallow(args):
   9.174      arg_check(args, "sched-bvt-ctxallow", 1)
   9.175  
   9.176      slice = int(args[0])
   9.177 -    from xen.xend.XendClient import server
   9.178 -    server.xend_node_cpu_bvt_slice_set(slice)
   9.179 +    server.xend.node.cpu_bvt_slice_set(slice)
   9.180  
   9.181  def xm_sched_sedf(args):
   9.182      def ns_to_ms(val):
   9.183 @@ -695,13 +679,12 @@ def xm_sched_sedf(args):
   9.184                                                       'Slice(ms)', 'Lat(ms)',
   9.185                                                       'Extra','Weight')
   9.186  
   9.187 -    from xen.xend.XendClient import server
   9.188      doms = filter(lambda x : domid_match(domid, x),
   9.189                          [parse_doms_info(dom) for dom in getDomains("")])
   9.190      for d in doms:
   9.191          # fetch current values so as not to clobber them
   9.192          sedf_info = \
   9.193 -            parse_sedf_info(server.xend_domain_cpu_sedf_get(d['dom']))
   9.194 +            parse_sedf_info(server.xend.domain.cpu_sedf_get(d['dom']))
   9.195          sedf_info['name'] = d['name']
   9.196  
   9.197          # update values in case of call to set
   9.198 @@ -713,7 +696,7 @@ def xm_sched_sedf(args):
   9.199              v = map(int, [sedf_info['period'], sedf_info['slice'],
   9.200                            sedf_info['latency'],sedf_info['extratime'], 
   9.201                            sedf_info['weight']])
   9.202 -            rv = server.xend_domain_cpu_sedf_set(d['dom'], *v)
   9.203 +            rv = server.xend.domain.cpu_sedf_set(d['dom'], *v)
   9.204              if int(rv) != 0:
   9.205                  err("Failed to set sedf parameters (rv=%d)."%(rv))
   9.206  
   9.207 @@ -725,8 +708,7 @@ def xm_sched_sedf(args):
   9.208  def xm_info(args):
   9.209      arg_check(args, "info", 0)
   9.210  
   9.211 -    from xen.xend.XendClient import server
   9.212 -    info = server.xend_node()
   9.213 +    info = server.xend.node.info()
   9.214      
   9.215      for x in info[1:]:
   9.216          if len(x) < 2: 
   9.217 @@ -738,8 +720,7 @@ def xm_console(args):
   9.218      arg_check(args, "console", 1)
   9.219  
   9.220      dom = args[0]
   9.221 -    from xen.xend.XendClient import server
   9.222 -    info = server.xend_domain(dom)
   9.223 +    info = server.xend.domain(dom)
   9.224      domid = int(sxp.child_value(info, 'domid', '-1'))
   9.225      console.execConsole(domid)
   9.226  
   9.227 @@ -768,17 +749,15 @@ its contents if the [-c|--clear] flag is
   9.228      if not (1 <= len(myargs) <= 2):
   9.229          err('Invalid arguments: ' + str(myargs))
   9.230  
   9.231 -    from xen.xend.XendClient import server
   9.232      if not gopts.vals.clear:
   9.233 -        print server.xend_node_get_dmesg()
   9.234 +        print server.xend.node.dmesg.info()
   9.235      else:
   9.236 -        server.xend_node_clear_dmesg()
   9.237 +        server.xend.node.dmesg.clear()
   9.238  
   9.239  def xm_log(args):
   9.240      arg_check(args, "log", 0)
   9.241      
   9.242 -    from xen.xend.XendClient import server
   9.243 -    print server.xend_node_log()
   9.244 +    print server.xend.node.log()
   9.245  
   9.246  def parse_dev_info(info):
   9.247      def get_info(n, t, d):
   9.248 @@ -826,13 +805,12 @@ def xm_network_list(args):
   9.249          print 'No domain parameter given'
   9.250          sys.exit(1)
   9.251      dom = params[0]
   9.252 -    from xen.xend.XendClient import server
   9.253      if use_long:
   9.254 -        devs = server.xend_domain_devices(dom, 'vif')
   9.255 +        devs = server.xend.domain.getDeviceSxprs(dom, 'vif')
   9.256          map(PrettyPrint.prettyprint, devs)
   9.257      else:
   9.258          hdr = 0
   9.259 -        for x in server.xend_domain_devices(dom, 'vif'):
   9.260 +        for x in server.xend.domain.getDeviceSxprs(dom, 'vif'):
   9.261              if hdr == 0:
   9.262                  print 'Idx BE     MAC Addr.     handle state evt-ch tx-/rx-ring-ref BE-path'
   9.263                  hdr = 1
   9.264 @@ -857,13 +835,12 @@ def xm_block_list(args):
   9.265          print 'No domain parameter given'
   9.266          sys.exit(1)
   9.267      dom = params[0]
   9.268 -    from xen.xend.XendClient import server
   9.269      if use_long:
   9.270 -        devs = server.xend_domain_devices(dom, 'vbd')
   9.271 +        devs = server.xend.domain.getDeviceSxprs(dom, 'vbd')
   9.272          map(PrettyPrint.prettyprint, devs)
   9.273      else:
   9.274          hdr = 0
   9.275 -        for x in server.xend_domain_devices(dom, 'vbd'):
   9.276 +        for x in server.xend.domain.getDeviceSxprs(dom, 'vbd'):
   9.277              if hdr == 0:
   9.278                  print 'Vdev  BE handle state evt-ch ring-ref BE-path'
   9.279                  hdr = 1
   9.280 @@ -887,13 +864,12 @@ def xm_vtpm_list(args):
   9.281          print 'No domain parameter given'
   9.282          sys.exit(1)
   9.283      dom = params[0]
   9.284 -    from xen.xend.XendClient import server
   9.285      if use_long:
   9.286 -        devs = server.xend_domain_devices(dom, 'vtpm')
   9.287 +        devs = server.xend.domain.getDeviceSxprs(dom, 'vtpm')
   9.288          map(PrettyPrint.prettyprint, devs)
   9.289      else:
   9.290          hdr = 0
   9.291 -        for x in server.xend_domain_devices(dom, 'vtpm'):
   9.292 +        for x in server.xend.domain.getDeviceSxprs(dom, 'vtpm'):
   9.293              if hdr == 0:
   9.294                  print 'Idx  BE handle state evt-ch ring-ref BE-path'
   9.295                  hdr = 1
   9.296 @@ -919,8 +895,7 @@ def xm_block_attach(args):
   9.297      if len(args) == 5:
   9.298          vbd.append(['backend', args[4]])
   9.299  
   9.300 -    from xen.xend.XendClient import server
   9.301 -    server.xend_domain_device_create(dom, vbd)
   9.302 +    server.xend.domain.device_create(dom, vbd)
   9.303  
   9.304  
   9.305  def xm_network_attach(args):
   9.306 @@ -932,8 +907,7 @@ def xm_network_attach(args):
   9.307      for a in args[1:]:
   9.308          vif.append(a.split("="))
   9.309  
   9.310 -    from xen.xend.XendClient import server
   9.311 -    server.xend_domain_device_create(dom, vif)
   9.312 +    server.xend.domain.device_create(dom, vif)
   9.313  
   9.314  
   9.315  def detach(args, command, deviceClass):
   9.316 @@ -942,8 +916,7 @@ def detach(args, command, deviceClass):
   9.317      dom = args[0]
   9.318      dev = args[1]
   9.319  
   9.320 -    from xen.xend.XendClient import server
   9.321 -    server.xend_domain_device_destroy(dom, deviceClass, dev)
   9.322 +    server.xend.domain.destroyDevice(dom, deviceClass, dev)
   9.323  
   9.324  
   9.325  def xm_block_detach(args):
   9.326 @@ -955,7 +928,6 @@ def xm_network_detach(args):
   9.327  
   9.328  
   9.329  def xm_vnet_list(args):
   9.330 -    from xen.xend.XendClient import server
   9.331      try:
   9.332          (options, params) = getopt.gnu_getopt(args, 'l', ['long'])
   9.333      except getopt.GetoptError, opterr:
   9.334 @@ -990,13 +962,11 @@ def xm_vnet_create(args):
   9.335          print "File not found: %s" % conf
   9.336          sys.exit(1)
   9.337  
   9.338 -    from xen.xend.XendClient import server
   9.339      server.xend_vnet_create(conf)
   9.340  
   9.341  def xm_vnet_delete(args):
   9.342      arg_check(args, "vnet-delete", 1)
   9.343      vnet = args[0]
   9.344 -    from xen.xend.XendClient import server
   9.345      server.xend_vnet_delete(vnet)
   9.346  
   9.347  commands = {
   9.348 @@ -1132,24 +1102,11 @@ def main(argv=sys.argv):
   9.349              else:
   9.350                  err("Error connecting to xend: %s." % ex[1])
   9.351              sys.exit(1)
   9.352 -        except xen.xend.XendError.XendError, ex:
   9.353 -            if len(args) > 0:
   9.354 -                handle_xend_error(argv[1], args, ex)
   9.355 -            else:
   9.356 -                print "Unexpected error:", sys.exc_info()[0]
   9.357 -                print
   9.358 -                print "Please report to xen-devel@lists.xensource.com"
   9.359 -                raise
   9.360 -        except xen.xend.XendProtocol.XendError, ex:
   9.361 -            if len(args) > 0:
   9.362 -                handle_xend_error(argv[1], args, ex)
   9.363 -            else:
   9.364 -                print "Unexpected error:", sys.exc_info()[0]
   9.365 -                print
   9.366 -                print "Please report to xen-devel@lists.xensource.com"
   9.367 -                raise
   9.368          except SystemExit:
   9.369              sys.exit(1)
   9.370 +        except xmlrpclib.Fault, ex:
   9.371 +            print "Xend generated an internal fault: %s" % ex.faultString
   9.372 +            sys.exit(1)
   9.373          except:
   9.374              print "Unexpected error:", sys.exc_info()[0]
   9.375              print
    10.1 --- a/tools/python/xen/xm/migrate.py	Thu Mar 23 10:58:39 2006 +0100
    10.2 +++ b/tools/python/xen/xm/migrate.py	Thu Mar 23 11:25:37 2006 +0100
    10.3 @@ -60,4 +60,4 @@ def main(argv):
    10.4          opts.err('Invalid arguments: ' + str(args))
    10.5      dom = args[0]
    10.6      dst = args[1]
    10.7 -    server.xend_domain_migrate(dom, dst, opts.vals.live, opts.vals.resource, opts.vals.port)
    10.8 +    server.xend.domain.migrate(dom, dst, opts.vals.live, opts.vals.resource, opts.vals.port)
    11.1 --- a/tools/python/xen/xm/shutdown.py	Thu Mar 23 10:58:39 2006 +0100
    11.2 +++ b/tools/python/xen/xm/shutdown.py	Thu Mar 23 11:25:37 2006 +0100
    11.3 @@ -53,8 +53,8 @@ gopts.opt('reboot', short='R',
    11.4            use='Shutdown and reboot.')
    11.5  
    11.6  def shutdown(opts, doms, mode, wait):
    11.7 -    if doms == None: doms = server.xend_domains()
    11.8 -    dom0_name = sxp.child_value(server.xend_domain(0), 'name')
    11.9 +    if doms == None: doms = server.xend.domains(0)
   11.10 +    dom0_name = sxp.child_value(server.xend.domain(0), 'name')
   11.11      for x in [dom0_name, DOM0_ID]:
   11.12          if x in doms:
   11.13              if opts.vals.all:
   11.14 @@ -62,10 +62,10 @@ def shutdown(opts, doms, mode, wait):
   11.15              else:
   11.16                  opts.err("Can't specify Domain-0")
   11.17      for d in doms:
   11.18 -        server.xend_domain_shutdown(d, mode)
   11.19 +        server.xend.domain.shutdown(d, mode)
   11.20      if wait:
   11.21          while doms:
   11.22 -            alive = server.xend_domains()
   11.23 +            alive = server.xend.domains(0)
   11.24              dead = []
   11.25              for d in doms:
   11.26                  if d in alive: continue
    12.1 --- a/tools/python/xen/xm/sysrq.py	Thu Mar 23 10:58:39 2006 +0100
    12.2 +++ b/tools/python/xen/xm/sysrq.py	Thu Mar 23 11:25:37 2006 +0100
    12.3 @@ -28,4 +28,4 @@ def main(argv):
    12.4      if len(args) < 2: opts.err('Missing sysrq character')
    12.5      dom = args[0]
    12.6      req = ord(args[1][0])
    12.7 -    server.xend_domain_sysrq(dom, req)
    12.8 +    server.xend.domain.sysrq(dom, req)