ia64/xen-unstable

changeset 7288:32f9300618d6

/home/emellor/log2
author emellor@ewan
date Sun Oct 09 12:14:46 2005 +0100 (2005-10-09)
parents 8e3ec9ab0075
children bb113ea17659
files tools/python/xen/util/asserts.py tools/python/xen/xend/XendClient.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/SrvDomain.py tools/python/xen/xend/server/SrvDomainDir.py tools/python/xen/xm/main.py
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/python/xen/util/asserts.py	Sun Oct 09 12:14:46 2005 +0100
     1.3 @@ -0,0 +1,22 @@
     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) 2005 XenSource Ltd
    1.19 +#============================================================================
    1.20 +
    1.21 +
    1.22 +def isCharConvertible(c):
    1.23 +    assert (isinstance(c, int) or
    1.24 +            (isinstance(c, str) and
    1.25 +             len(c) == 1)), "%s is not convertible to a character" % c
     2.1 --- a/tools/python/xen/xend/XendClient.py	Sun Oct 09 11:59:37 2005 +0100
     2.2 +++ b/tools/python/xen/xend/XendClient.py	Sun Oct 09 12:14:46 2005 +0100
     2.3 @@ -196,6 +196,9 @@ class Xend:
     2.4      def xend_domains(self):
     2.5          return self.xendGet(self.domainurl())
     2.6  
     2.7 +    def xend_list_domains(self):
     2.8 +        return self.xendGet(self.domainurl(), {'detail': '1'})
     2.9 +
    2.10      def xend_domain_create(self, conf):
    2.11          return self.xendPost(self.domainurl(),
    2.12                               {'op'      : 'create',
     3.1 --- a/tools/python/xen/xend/XendDomain.py	Sun Oct 09 11:59:37 2005 +0100
     3.2 +++ b/tools/python/xen/xend/XendDomain.py	Sun Oct 09 12:14:46 2005 +0100
     3.3 @@ -359,20 +359,6 @@ class XendDomain:
     3.4              raise XendError(str(ex))
     3.5  
     3.6  
     3.7 -    def domain_shutdown(self, domid, reason = 'poweroff'):
     3.8 -        """Shutdown domain (nicely).
     3.9 -
    3.10 -        @param reason: shutdown reason: poweroff, reboot, suspend, halt
    3.11 -        """
    3.12 -        self.callInfo(domid, XendDomainInfo.XendDomainInfo.shutdown, reason)
    3.13 -
    3.14 -
    3.15 -    def domain_sysrq(self, domid, key):
    3.16 -        """Send a SysRq to the specified domain."""
    3.17 -        return self.callInfo(domid, XendDomainInfo.XendDomainInfo.send_sysrq,
    3.18 -                             key)
    3.19 -
    3.20 -
    3.21      def domain_destroy(self, domid):
    3.22          """Terminate domain immediately."""
    3.23  
    3.24 @@ -475,37 +461,6 @@ class XendDomain:
    3.25              raise XendError(str(ex))
    3.26  
    3.27  
    3.28 -    def domain_device_create(self, domid, devconfig):
    3.29 -        """Create a new device for the specified domain.
    3.30 -        """
    3.31 -        return self.callInfo(domid,
    3.32 -                             XendDomainInfo.XendDomainInfo.device_create,
    3.33 -                             devconfig)
    3.34 -
    3.35 -
    3.36 -    def domain_device_configure(self, domid, devconfig, devid):
    3.37 -        """Configure an existing device in the specified domain.
    3.38 -        @return: updated device configuration
    3.39 -        """
    3.40 -        return self.callInfo(domid,
    3.41 -                             XendDomainInfo.XendDomainInfo.device_configure,
    3.42 -                             devconfig, devid)
    3.43 -
    3.44 -    
    3.45 -    def domain_device_destroy(self, domid, devtype, devid):
    3.46 -        """Destroy a device."""
    3.47 -        return self.callInfo(domid,
    3.48 -                             XendDomainInfo.XendDomainInfo.destroyDevice,
    3.49 -                             devtype, devid)
    3.50 -
    3.51 -
    3.52 -    def domain_devtype_ls(self, domid, devtype):
    3.53 -        """Get list of device sxprs for the specified domain."""
    3.54 -        return self.callInfo(domid,
    3.55 -                             XendDomainInfo.XendDomainInfo.getDeviceSxprs,
    3.56 -                             devtype)
    3.57 -
    3.58 -
    3.59      def domain_vif_limit_set(self, domid, vif, credit, period):
    3.60          """Limit the vif's transmission rate
    3.61          """
    3.62 @@ -537,44 +492,6 @@ class XendDomain:
    3.63          except Exception, ex:
    3.64              raise XendError(str(ex))
    3.65  
    3.66 -    def domain_mem_target_set(self, domid, mem):
    3.67 -        """Set the memory target for a domain.
    3.68 -
    3.69 -        @param mem: memory target (in MiB)
    3.70 -        """
    3.71 -        self.callInfo(domid, XendDomainInfo.XendDomainInfo.setMemoryTarget,
    3.72 -                      mem << 10)
    3.73 -
    3.74 -
    3.75 -    def domain_vcpu_hotplug(self, domid, vcpu, state):
    3.76 -        """Enable or disable specified VCPU in specified domain
    3.77 -
    3.78 -        @param vcpu: target VCPU in domain
    3.79 -        @param state: which state VCPU will become
    3.80 -        """
    3.81 -        self.callInfo(domid, XendDomainInfo.XendDomainInfo.vcpu_hotplug, vcpu,
    3.82 -                      state)
    3.83 -
    3.84 -
    3.85 -    def domain_dumpcore(self, domid):
    3.86 -        """Save a core dump for a crashed domain."""
    3.87 -        self.callInfo(domid, XendDomainInfo.XendDomainInfo.dumpCore)
    3.88 -
    3.89 -
    3.90 -    ## private:
    3.91 -
    3.92 -    def callInfo(self, domid, fn, *args, **kwargs):
    3.93 -        try:
    3.94 -            self.refresh()
    3.95 -            dominfo = self.domains.get(domid)
    3.96 -            if dominfo:
    3.97 -                return fn(dominfo, *args, **kwargs)
    3.98 -        except XendError:
    3.99 -            raise
   3.100 -        except Exception, exn:
   3.101 -            log.exception("")
   3.102 -            raise XendError(str(exn))
   3.103 -
   3.104  
   3.105  def instance():
   3.106      """Singleton constructor. Use this instead of the class constructor.
     4.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Sun Oct 09 11:59:37 2005 +0100
     4.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Sun Oct 09 12:14:46 2005 +0100
     4.3 @@ -30,6 +30,7 @@ import threading
     4.4  import errno
     4.5  
     4.6  import xen.lowlevel.xc
     4.7 +from xen.util import asserts
     4.8  from xen.util.blkif import blkdev_uname_to_file
     4.9  
    4.10  from xen.xend import image
    4.11 @@ -41,7 +42,8 @@ from xen.xend.XendLogging import log
    4.12  from xen.xend.XendError import XendError, VmError
    4.13  from xen.xend.XendRoot import get_component
    4.14  
    4.15 -from xen.xend.uuid import getUuid
    4.16 +from uuid import getUuid
    4.17 +
    4.18  from xen.xend.xenstore.xstransact import xstransact
    4.19  from xen.xend.xenstore.xsutil import GetDomainPath, IntroduceDomain
    4.20  
    4.21 @@ -793,10 +795,12 @@ class XendDomainInfo:
    4.22  
    4.23      def setMemoryTarget(self, target):
    4.24          """Set the memory target of this domain.
    4.25 -        @param target In KiB.
    4.26 +        @param target In MiB.
    4.27          """
    4.28 -        self.info['memory_KiB'] = target
    4.29 -        self.storeDom("memory/target", target)
    4.30 +        # Internally we use KiB, but the command interface uses MiB.
    4.31 +        t = target << 10
    4.32 +        self.info['memory_KiB'] = t
    4.33 +        self.storeDom("memory/target", t)
    4.34  
    4.35  
    4.36      def update(self, info = None):
    4.37 @@ -1366,7 +1370,10 @@ class XendDomainInfo:
    4.38          self.storeVm('vcpu_avail', self.info['vcpu_avail'])
    4.39          self.storeDom("cpu/%d/availability" % vcpu, availability)
    4.40  
    4.41 -    def send_sysrq(self, key=0):
    4.42 +
    4.43 +    def send_sysrq(self, key):
    4.44 +        asserts.isCharConvertible(key)
    4.45 +
    4.46          self.storeDom("control/sysrq", '%c' % key)
    4.47  
    4.48  
     5.1 --- a/tools/python/xen/xend/server/SrvDomain.py	Sun Oct 09 11:59:37 2005 +0100
     5.2 +++ b/tools/python/xen/xend/server/SrvDomain.py	Sun Oct 09 12:14:46 2005 +0100
     5.3 @@ -51,40 +51,28 @@ class SrvDomain(SrvDir):
     5.4          val = self.xd.domain_pause(self.dom.domid)
     5.5          return val
     5.6  
     5.7 -    def op_shutdown(self, op, req):
     5.8 -        fn = FormFn(self.xd.domain_shutdown,
     5.9 -                    [['dom',    'int'],
    5.10 -                     ['reason', 'str']])
    5.11 -        val = fn(req.args, {'dom': self.dom.domid})
    5.12 +    def acceptCommand(self, req):
    5.13          req.setResponseCode(http.ACCEPTED)
    5.14          req.setHeader("Location", "%s/.." % req.prePathURL())
    5.15 -        return val
    5.16 +
    5.17 +    def op_shutdown(self, op, req):
    5.18 +        self.acceptCommand(req)
    5.19 +        return self.dom.shutdown(req.args['reason'][0])
    5.20  
    5.21      def op_sysrq(self, op, req):
    5.22 -        fn = FormFn(self.xd.domain_sysrq,
    5.23 -                    [['dom',    'int'],
    5.24 -                     ['key',    'int']])
    5.25 -        val = fn(req.args, {'dom' : self.dom.domid})
    5.26 -        req.setResponseCode(http.ACCEPTED)
    5.27 -        req.setHeader("Location", "%s/.." % req.prePathURL())
    5.28 -        return val
    5.29 +        self.acceptCommand(req)
    5.30 +        return self.dom.send_sysrq(int(req.args['key'][0]))
    5.31  
    5.32      def op_destroy(self, op, req):
    5.33 -        fn = FormFn(self.xd.domain_destroy,
    5.34 -                    [['dom',    'int']])
    5.35 -        val = fn(req.args, {'dom': self.dom.domid})
    5.36 -        req.setHeader("Location", "%s/.." % req.prePathURL())
    5.37 -        return val
    5.38 +        self.acceptCommand(req)
    5.39 +        return self.xd.domain_destroy(self.dom.domid)
    5.40  
    5.41      def op_save(self, op, req):
    5.42 +        self.acceptCommand(req)
    5.43          return req.threadRequest(self.do_save, op, req)
    5.44  
    5.45      def do_save(self, op, req):
    5.46 -        fn = FormFn(self.xd.domain_save,
    5.47 -                    [['dom',  'int'],
    5.48 -                     ['file', 'str']])
    5.49 -        val = fn(req.args, {'dom': self.dom.domid})
    5.50 -        return 0
    5.51 +        return self.xd.domain_save(self.dom.domid, req.args['file'][0])
    5.52  
    5.53      def op_migrate(self, op, req):
    5.54          return req.threadRequest(self.do_migrate, op, req)
    5.55 @@ -134,43 +122,39 @@ class SrvDomain(SrvDir):
    5.56                       ['memory', 'int']])
    5.57          val = fn(req.args, {'dom': self.dom.domid})
    5.58          return val
    5.59 +
    5.60      
    5.61 +    def call(self, fn, args, req):
    5.62 +        return FormFn(fn, args)(req.args)
    5.63 +
    5.64 +
    5.65      def op_mem_target_set(self, op, req):
    5.66 -        fn = FormFn(self.xd.domain_mem_target_set,
    5.67 -                    [['dom',    'int'],
    5.68 -                     ['target', 'int']])
    5.69 -        val = fn(req.args, {'dom': self.dom.domid})
    5.70 -        return val
    5.71 +        return self.call(self.dom.setMemoryTarget
    5.72 +                         [['target', 'int']],
    5.73 +                         req)
    5.74  
    5.75      def op_devices(self, op, req):
    5.76 -        fn = FormFn(self.xd.domain_devtype_ls,
    5.77 -                    [['dom',    'int'],
    5.78 -                     ['type',   'str']])
    5.79 -        val = fn(req.args, {'dom': self.dom.domid})
    5.80 -        return val
    5.81 +        return self.call(self.dom.getDeviceSxprs,
    5.82 +                         [['deviceClass', 'str']],
    5.83 +                         req)
    5.84  
    5.85      def op_device_create(self, op, req):
    5.86 -        fn = FormFn(self.xd.domain_device_create,
    5.87 -                    [['dom',    'int'],
    5.88 -                     ['config', 'sxpr']])
    5.89 -        val = fn(req.args, {'dom': self.dom.domid})
    5.90 -        return val
    5.91 +        return self.call(self.dom.device_create,
    5.92 +                         [['dev_config', 'sxpr']],
    5.93 +                         req)
    5.94  
    5.95      def op_device_destroy(self, op, req):
    5.96 -        fn = FormFn(self.xd.domain_device_destroy,
    5.97 -                    [['dom',  'int'],
    5.98 -                     ['type', 'str'],
    5.99 -                     ['dev',  'str']])
   5.100 -        val = fn(req.args, {'dom': self.dom.domid})
   5.101 -        return val
   5.102 +        return self.call(self.dom.destroyDevice,
   5.103 +                         [['deviceClass', 'str'],
   5.104 +                          ['devid',       'int']],
   5.105 +                         req)
   5.106                  
   5.107      def op_device_configure(self, op, req):
   5.108 -        fn = FormFn(self.xd.domain_device_configure,
   5.109 -                    [['dom',    'int'],
   5.110 -                     ['config', 'sxpr'],
   5.111 -                     ['dev',    'str']])
   5.112 -        val = fn(req.args, {'dom': self.dom.domid})
   5.113 -        return val
   5.114 +        return self.call(self.dom.device_configure,
   5.115 +                         [['dev_config', 'sxpr'],
   5.116 +                          ['devid',       'int']],
   5.117 +                         req)
   5.118 +
   5.119  
   5.120      def op_vif_limit_set(self, op, req):
   5.121          fn = FormFn(self.xd.domain_vif_limit_set,
   5.122 @@ -182,12 +166,10 @@ class SrvDomain(SrvDir):
   5.123          return val
   5.124  
   5.125      def op_vcpu_hotplug(self, op, req):
   5.126 -        fn = FormFn(self.xd.domain_vcpu_hotplug,
   5.127 -                    [['dom', 'int'],
   5.128 -                     ['vcpu', 'int'],
   5.129 -                     ['state', 'int']])
   5.130 -        val = fn(req.args, {'dom': self.dom.domid})
   5.131 -        return val
   5.132 +        return self.call(self.dom.vcpu_hotplug,
   5.133 +                         [['vcpu', 'int'],
   5.134 +                          ['state', 'int']],
   5.135 +                         req)
   5.136  
   5.137      def render_POST(self, req):
   5.138          return self.perform(req)
   5.139 @@ -201,7 +183,6 @@ class SrvDomain(SrvDir):
   5.140          #
   5.141          # if op and op[0] in ['vifs', 'vif', 'vbds', 'vbd', 'mem_target_set']:
   5.142          #    return self.perform(req)
   5.143 -        self.dom.update()
   5.144          if self.use_sxp(req):
   5.145              req.setHeader("Content-Type", sxp.mime_type)
   5.146              sxp.show(self.dom.sxpr(), out=req)
     6.1 --- a/tools/python/xen/xend/server/SrvDomainDir.py	Sun Oct 09 11:59:37 2005 +0100
     6.2 +++ b/tools/python/xen/xend/server/SrvDomainDir.py	Sun Oct 09 12:14:46 2005 +0100
     6.3 @@ -22,6 +22,7 @@ from xen.web import http
     6.4  
     6.5  from xen.xend import sxp
     6.6  from xen.xend import XendDomain
     6.7 +from xen.xend.XendDomainInfo import XendDomainInfo
     6.8  from xen.xend.Args import FormFn
     6.9  from xen.xend.XendError import XendError
    6.10  from xen.xend.XendLogging import log
    6.11 @@ -29,6 +30,7 @@ from xen.xend.XendLogging import log
    6.12  from xen.web.SrvDir import SrvDir
    6.13  from SrvDomain import SrvDomain
    6.14  
    6.15 +
    6.16  class SrvDomainDir(SrvDir):
    6.17      """Service that manages the domain directory.
    6.18      """
    6.19 @@ -124,28 +126,41 @@ class SrvDomainDir(SrvDir):
    6.20              out.close()
    6.21              return val
    6.22  
    6.23 +
    6.24 +    def op_list(self, _, req):
    6.25 +        """List the details for this domain."""
    6.26 +        self._list(req, True)
    6.27 +
    6.28 +
    6.29      def render_POST(self, req):
    6.30          return self.perform(req)
    6.31  
    6.32      def render_GET(self, req):
    6.33 +        self._list(req, 'detail' in req.args and req.args['detail'] == ['1'])
    6.34 +
    6.35 +
    6.36 +    def _list(self, req, detail):
    6.37          if self.use_sxp(req):
    6.38              req.setHeader("Content-Type", sxp.mime_type)
    6.39 -            self.ls_domain(req, 1)
    6.40 +            self.ls_domain(req, detail, True)
    6.41          else:
    6.42              req.write("<html><head></head><body>")
    6.43              self.print_path(req)
    6.44              self.ls(req)
    6.45 -            self.ls_domain(req)
    6.46 +            self.ls_domain(req, detail, False)
    6.47              self.form(req)
    6.48              req.write("</body></html>")
    6.49  
    6.50 -    def ls_domain(self, req, use_sxp=0):
    6.51 +
    6.52 +    def ls_domain(self, req, detail, use_sxp):
    6.53          url = req.prePathURL()
    6.54          if not url.endswith('/'):
    6.55              url += '/'
    6.56          if use_sxp:
    6.57 -            domains = self.xd.list_names()
    6.58 -            sxp.show(domains, out=req)
    6.59 +            if detail:
    6.60 +                sxp.show(map(XendDomainInfo.sxpr, self.xd.list()), out=req)
    6.61 +            else:
    6.62 +                sxp.show(self.xd.list_names(), out=req)
    6.63          else:
    6.64              domains = self.xd.list_sorted()
    6.65              req.write('<ul>')
    6.66 @@ -158,6 +173,7 @@ class SrvDomainDir(SrvDir):
    6.67                  req.write('</li>')
    6.68              req.write('</ul>')
    6.69  
    6.70 +
    6.71      def form(self, req):
    6.72          """Generate the form(s) for domain dir operations.
    6.73          """
     7.1 --- a/tools/python/xen/xm/main.py	Sun Oct 09 11:59:37 2005 +0100
     7.2 +++ b/tools/python/xen/xm/main.py	Sun Oct 09 12:14:46 2005 +0100
     7.3 @@ -225,25 +225,22 @@ def xm_list(args):
     7.4          if k in ['-v', '--vcpus']:
     7.5              show_vcpus = 1
     7.6  
     7.7 -    domsinfo = []
     7.8      from xen.xend.XendClient import server
     7.9      if n == 0:
    7.10 -        doms = server.xend_domains()
    7.11 -        doms.sort()
    7.12 +        doms = server.xend_list_domains()
    7.13      else:
    7.14 -        doms = params
    7.15 -    for dom in doms:
    7.16 -        info = server.xend_domain(dom)
    7.17 -        domsinfo.append(parse_doms_info(info))
    7.18 +        doms = map(server.xend_domain, params)
    7.19                 
    7.20      if use_long:
    7.21          for dom in doms:
    7.22 -            info = server.xend_domain(dom)
    7.23 -            PrettyPrint.prettyprint(info)
    7.24 -    elif show_vcpus:
    7.25 -        xm_show_vcpus(domsinfo)
    7.26 +            PrettyPrint.prettyprint(doms)
    7.27      else:
    7.28 -        xm_brief_list(domsinfo)
    7.29 +        domsinfo = map(parse_doms_info, doms)
    7.30 +
    7.31 +        if show_vcpus:
    7.32 +            xm_show_vcpus(domsinfo)
    7.33 +        else:
    7.34 +            xm_brief_list(domsinfo)
    7.35  
    7.36  def parse_doms_info(info):
    7.37      dominfo = {}
    7.38 @@ -279,12 +276,12 @@ def parse_doms_info(info):
    7.39      return dominfo
    7.40          
    7.41  def xm_brief_list(domsinfo):
    7.42 -    print 'Name              Id  Mem(MB)  CPU VCPU(s)  State  Time(s)'
    7.43 +    print 'Name              ID  Mem(MiB)  CPU  VCPUs  State   Time(s)'
    7.44      for dominfo in domsinfo:
    7.45          if dominfo.has_key("ssidref1"):
    7.46 -            print ("%(name)-16s %(dom)3d  %(mem)7d  %(cpu)3s  %(vcpus)5d   %(state)5s  %(cpu_time)7.1f     s:%(ssidref2)02x/p:%(ssidref1)02x" % dominfo)
    7.47 +            print ("%(name)-16s %(dom)3d  %(mem)8d  %(cpu)3s  %(vcpus)5d  %(state)5s  %(cpu_time)7.1f     s:%(ssidref2)02x/p:%(ssidref1)02x" % dominfo)
    7.48          else:
    7.49 -            print ("%(name)-16s %(dom)3d  %(mem)7d  %(cpu)3s  %(vcpus)5d   %(state)5s  %(cpu_time)7.1f" % dominfo)
    7.50 +            print ("%(name)-16s %(dom)3d  %(mem)8d  %(cpu)3s  %(vcpus)5d  %(state)5s  %(cpu_time)7.1f" % dominfo)
    7.51  
    7.52  def xm_show_vcpus(domsinfo):
    7.53      print 'Name              Id  VCPU  CPU  CPUMAP'