ia64/xen-unstable

changeset 1985:7fdc6f3e894c

bitkeeper revision 1.1108.35.3 (4109068aJLiAygvPcLaayrwLbvNnyw)

Add vif and vbd commands, including adding vbds to
an existing domain.
author mjw@wray-m-3.hpl.hp.com
date Thu Jul 29 14:15:38 2004 +0000 (2004-07-29)
parents 4b46fe967cdd
children cfbc2a2c3fea
files tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/blkif.py tools/python/xen/xend/server/netif.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Thu Jul 29 12:45:53 2004 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Thu Jul 29 14:15:38 2004 +0000
     1.3 @@ -417,7 +417,10 @@ class XendDomain:
     1.4          """
     1.5          dominfo = self.domain_lookup(id)
     1.6          eserver.inject('xend.domain.unpause', dominfo.name)
     1.7 -        return xc.domain_unpause(dom=dominfo.dom)
     1.8 +        try:
     1.9 +            return xc.domain_unpause(dom=dominfo.dom)
    1.10 +        except Exception, ex:
    1.11 +            raise XendError(str(ex))
    1.12      
    1.13      def domain_pause(self, id):
    1.14          """Pause domain execution.
    1.15 @@ -426,7 +429,10 @@ class XendDomain:
    1.16          """
    1.17          dominfo = self.domain_lookup(id)
    1.18          eserver.inject('xend.domain.pause', dominfo.name)
    1.19 -        return xc.domain_pause(dom=dominfo.dom)
    1.20 +        try:
    1.21 +            return xc.domain_pause(dom=dominfo.dom)
    1.22 +        except Exception, ex:
    1.23 +            raise XendError(str(ex))
    1.24      
    1.25      def domain_shutdown(self, id, reason='poweroff'):
    1.26          """Shutdown domain (nicely).
    1.27 @@ -581,45 +587,66 @@ class XendDomain:
    1.28          @param cpu: cpu number
    1.29          """
    1.30          dominfo = self.domain_lookup(id)
    1.31 -        return xc.domain_pincpu(itn(dominfo.id), cpu)
    1.32 +        try:
    1.33 +            return xc.domain_pincpu(itn(dominfo.id), cpu)
    1.34 +        except Exception, ex:
    1.35 +            raise XendError(str(ex))
    1.36  
    1.37      def domain_cpu_bvt_set(self, id, mcuadv, warp, warpl, warpu):
    1.38          """Set BVT (Borrowed Virtual Time) scheduler parameters for a domain.
    1.39          """
    1.40          dominfo = self.domain_lookup(id)
    1.41 -        return xc.bvtsched_domain_set(dom=dominfo.dom, mcuadv=mcuadv,
    1.42 -                                      warp=warp, warpl=warpl, warpu=warpu)
    1.43 +        try:
    1.44 +            return xc.bvtsched_domain_set(dom=dominfo.dom, mcuadv=mcuadv,
    1.45 +                                          warp=warp, warpl=warpl, warpu=warpu)
    1.46 +        except Exception, ex:
    1.47 +            raise XendError(str(ex))
    1.48  
    1.49      def domain_cpu_bvt_get(self, id):
    1.50          """Get BVT (Borrowed Virtual Time) scheduler parameters for a domain.
    1.51          """
    1.52          dominfo = self.domain_lookup(id)
    1.53 -        return xc.bvtsched_domain_get(dominfo.dom)
    1.54 +        try:
    1.55 +            return xc.bvtsched_domain_get(dominfo.dom)
    1.56 +        except Exception, ex:
    1.57 +            raise XendError(str(ex))
    1.58      
    1.59      def domain_cpu_fbvt_set(self, id, mcuadv, warp, warpl, warpu):
    1.60          """Set FBVT (Fair Borrowed Virtual Time) scheduler parameters for a domain.
    1.61          """
    1.62          dominfo = self.domain_lookup(id)
    1.63 -        return xc.fbvtsched_domain_set(dom=dominfo.dom, mcuadv=mcuadv,
    1.64 -                                       warp=warp, warpl=warpl, warpu=warpu)
    1.65 +        try:
    1.66 +            return xc.fbvtsched_domain_set(dom=dominfo.dom, mcuadv=mcuadv,
    1.67 +                                           warp=warp, warpl=warpl, warpu=warpu)
    1.68 +        except Exception, ex:
    1.69 +            raise XendError(str(ex))
    1.70  
    1.71      def domain_cpu_fbvt_get(self, id):
    1.72          """Get FBVT (Fair Borrowed Virtual Time) scheduler parameters for a domain.
    1.73          """
    1.74          dominfo = self.domain_lookup(id)
    1.75 -        return xc.fbvtsched_domain_get(dominfo.dom)
    1.76 +        try:
    1.77 +            return xc.fbvtsched_domain_get(dominfo.dom)
    1.78 +        except Exception, ex:
    1.79 +            raise XendError(str(ex))
    1.80          
    1.81      def domain_cpu_atropos_set(self, id, period, slice, latency, xtratime):
    1.82          """Set Atropos scheduler parameters for a domain.
    1.83          """
    1.84          dominfo = self.domain_lookup(id)
    1.85 -        return xc.atropos_domain_set(dominfo.dom, period, slice, latency, xtratime)
    1.86 +        try:
    1.87 +            return xc.atropos_domain_set(dominfo.dom, period, slice, latency, xtratime)
    1.88 +        except Exception, ex:
    1.89 +            raise XendError(str(ex))
    1.90  
    1.91      def domain_cpu_atropos_get(self, id):
    1.92          """Get Atropos scheduler parameters for a domain.
    1.93          """
    1.94          dominfo = self.domain_lookup(id)
    1.95 -        return xc.atropos_domain_get(dominfo.dom)
    1.96 +        try:
    1.97 +            return xc.atropos_domain_get(dominfo.dom)
    1.98 +        except Exception, ex:
    1.99 +            raise XendError(str(ex))
   1.100  
   1.101      def domain_device_create(self, id, devconfig):
   1.102          """Create a new device for a domain.
   1.103 @@ -711,7 +738,10 @@ class XendDomain:
   1.104          @param op:  operation
   1.105          """
   1.106          dominfo = self.domain_lookup(id)
   1.107 -        return xc.shadow_control(dominfo.dom, op)
   1.108 +        try:
   1.109 +            return xc.shadow_control(dominfo.dom, op)
   1.110 +        except Exception, ex:
   1.111 +            raise XendError(str(ex))
   1.112  
   1.113      def domain_maxmem_set(self, id, mem):
   1.114          """Set the memory limit for a domain.
   1.115 @@ -722,7 +752,10 @@ class XendDomain:
   1.116          """
   1.117          dominfo = self.domain_lookup(id)
   1.118          maxmem = int(mem) * 1024
   1.119 -        return xc.domain_setmaxmem(dominfo.dom, maxmem_kb = maxmem)
   1.120 +        try:
   1.121 +            return xc.domain_setmaxmem(dominfo.dom, maxmem_kb = maxmem)
   1.122 +        except Exception, ex:
   1.123 +            raise XendError(str(ex))
   1.124  
   1.125  
   1.126  def instance():
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Jul 29 12:45:53 2004 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Jul 29 14:15:38 2004 +0000
     2.3 @@ -622,7 +622,10 @@ class XendDomainInfo:
     2.4          if chan:
     2.5              log.debug("Closing channel to domain %d", self.dom)
     2.6              chan.close()
     2.7 -        return xc.domain_destroy(dom=self.dom)
     2.8 +        try:
     2.9 +            return xc.domain_destroy(dom=self.dom)
    2.10 +        except Exception, err:
    2.11 +            log.exception("Domain destroy failed: ", self.name)
    2.12  
    2.13      def cleanup(self):
    2.14          """Cleanup vm resources: release devices.
    2.15 @@ -855,6 +858,7 @@ class XendDomainInfo:
    2.16          if self.restart_time is not None:
    2.17              tdelta = tnow - self.restart_time
    2.18              if tdelta < self.MINIMUM_RESTART_TIME:
    2.19 +                self.restart_cancel()
    2.20                  msg = 'VM %s restarting too fast' % self.name
    2.21                  log.error(msg)
    2.22                  raise VmError(msg)
    2.23 @@ -1036,7 +1040,6 @@ def vm_dev_vbd(vm, val, index):
    2.24      """
    2.25      if vm.blkif_backend:
    2.26          raise VmError('vbd: vbd in blkif backend domain')
    2.27 -    vdev = vm.next_device_index('vif')
    2.28      uname = sxp.child_value(val, 'uname')
    2.29      if not uname:
    2.30          raise VmError('vbd: Missing uname')
    2.31 @@ -1047,8 +1050,9 @@ def vm_dev_vbd(vm, val, index):
    2.32      log.debug("Creating vbd dom=%d uname=%s dev=%s", vm.dom, uname, dev)
    2.33      defer = make_disk(vm.dom, uname, dev, mode, vm.recreate)
    2.34      def fn(vbd):
    2.35 -        dev = xend.blkif_dev(vm.dom, vdev)
    2.36 -        vm.add_device('vbd', dev)
    2.37 +        vbd.dev = dev
    2.38 +        vbd.uname = uname
    2.39 +        vm.add_device('vbd', vbd)
    2.40          return vbd
    2.41      defer.addCallback(fn)
    2.42      return defer
     3.1 --- a/tools/python/xen/xend/server/blkif.py	Thu Jul 29 12:45:53 2004 +0000
     3.2 +++ b/tools/python/xen/xend/server/blkif.py	Thu Jul 29 14:15:38 2004 +0000
     3.3 @@ -160,13 +160,15 @@ class BlkifControllerFactory(controller.
     3.4          else:
     3.5              pass
     3.6      
     3.7 -    def respond_be_vbd_create(self, msg, d):
     3.8 +    def respond_be_vbd_create(self, msg, dev, d):
     3.9          """Response handler for a be_vbd_create message.
    3.10          Tries to grow the vbd, and passes the deferred I{d} on for
    3.11          the grow to call.
    3.12  
    3.13          @param msg: message
    3.14          @type  msg: xu message
    3.15 +        @param dev: device
    3.16 +        @type  dev: BlkDev
    3.17          @param d: deferred to call
    3.18          @type  d: Deferred
    3.19          """
    3.20 @@ -174,17 +176,19 @@ class BlkifControllerFactory(controller.
    3.21          blkif = self.getInstanceByDom(val['domid'])
    3.22          if blkif:
    3.23              d1 = defer.Deferred()
    3.24 -            d1.addCallback(self.respond_be_vbd_grow, d)
    3.25 +            d1.addCallback(self.respond_be_vbd_grow, dev, d)
    3.26              if d: d1.addErrback(d.errback)
    3.27              blkif.send_be_vbd_grow(val['vdevice'], response=d1)
    3.28          else:
    3.29              pass
    3.30      
    3.31 -    def respond_be_vbd_grow(self, msg, d):
    3.32 +    def respond_be_vbd_grow(self, msg, dev, d):
    3.33          """Response handler for a be_vbd_grow message.
    3.34  
    3.35          @param msg: message
    3.36          @type  msg: xu message
    3.37 +        @param dev: device
    3.38 +        @type  dev: BlkDev
    3.39          @param d: deferred to call
    3.40          @type  d: Deferred or None
    3.41          """
    3.42 @@ -192,7 +196,7 @@ class BlkifControllerFactory(controller.
    3.43          # Check status?
    3.44          if self.attached:
    3.45              if d:
    3.46 -                d.callback(0)
    3.47 +                d.callback(dev)
    3.48          else:
    3.49              self.reattachDevice(val['domid'], val['vdevice'])
    3.50  
    3.51 @@ -216,6 +220,8 @@ class BlkDev(controller.Dev):
    3.52  
    3.53      def __init__(self, ctrl, vdev, mode, segment):
    3.54          controller.Dev.__init__(self,  segment['device'], ctrl)
    3.55 +        self.dev = None
    3.56 +        self.uname = None
    3.57          self.vdev = vdev
    3.58          self.mode = mode
    3.59          self.device = segment['device']
    3.60 @@ -232,6 +238,10 @@ class BlkDev(controller.Dev):
    3.61                 ['vdev', self.vdev],
    3.62                 ['device', self.device],
    3.63                 ['mode', self.mode]]
    3.64 +        if self.dev:
    3.65 +            val.append(['dev', self.dev])
    3.66 +        if self.uname:
    3.67 +            val.append(['uname', self.uname])
    3.68          return val
    3.69  
    3.70      def destroy(self):
    3.71 @@ -292,6 +302,7 @@ class BlkifController(controller.Control
    3.72  
    3.73      def attachDevice(self, vdev, mode, segment, recreate=0):
    3.74          """Attach a device to the specified interface.
    3.75 +        On success the returned deferred will be called with the device.
    3.76  
    3.77          @param vdev:     device index
    3.78          @type  vdev:     int
    3.79 @@ -308,10 +319,10 @@ class BlkifController(controller.Control
    3.80          if not dev: return -1
    3.81          d = defer.Deferred()
    3.82          if recreate:
    3.83 -            d.callback(self)
    3.84 +            d.callback(dev)
    3.85          else:
    3.86              d1 = defer.Deferred()
    3.87 -            d1.addCallback(self.factory.respond_be_vbd_create, d)
    3.88 +            d1.addCallback(self.factory.respond_be_vbd_create, dev, d)
    3.89              d1.addErrback(d.errback)
    3.90              self.send_be_vbd_create(vdev, response=d1)
    3.91          return d
    3.92 @@ -335,7 +346,7 @@ class BlkifController(controller.Control
    3.93          for dev in self.devices.values():
    3.94              dev.attached = 0
    3.95              d1 = defer.Deferred()
    3.96 -            d1.addCallback(self.factory.respond_be_vbd_create, None)
    3.97 +            d1.addCallback(self.factory.respond_be_vbd_create, None, None)
    3.98              self.send_be_vbd_create(vdev, response=d1)
    3.99  
   3.100      def reattachDevice(self, vdev):
     4.1 --- a/tools/python/xen/xend/server/netif.py	Thu Jul 29 12:45:53 2004 +0000
     4.2 +++ b/tools/python/xen/xend/server/netif.py	Thu Jul 29 14:15:38 2004 +0000
     4.3 @@ -122,7 +122,7 @@ class NetDev(controller.Dev):
     4.4          self.mac = None
     4.5          self.bridge = None
     4.6          self.script = None
     4.7 -        self.ipaddr = None
     4.8 +        self.ipaddr = []
     4.9          
    4.10          vmac = sxp.child_value(config, 'mac')
    4.11          if not vmac: raise XendError("invalid mac")
     5.1 --- a/tools/python/xen/xm/main.py	Thu Jul 29 12:45:53 2004 +0000
     5.2 +++ b/tools/python/xen/xm/main.py	Thu Jul 29 14:15:38 2004 +0000
     5.3 @@ -209,6 +209,20 @@ class GroupConsole(Group):
     5.4  
     5.5  xm.group(GroupConsole)
     5.6  
     5.7 +class GroupVbd(Group):
     5.8 +
     5.9 +    name = "vbd"
    5.10 +    info = "Commands related to virtual block devices:"
    5.11 +
    5.12 +xm.group(GroupVbd)
    5.13 +
    5.14 +class GroupVif(Group):
    5.15 +
    5.16 +    name = "vif"
    5.17 +    info = "Commands related to virtual network interfaces:"
    5.18 +
    5.19 +xm.group(GroupVif)
    5.20 +
    5.21  class ProgHelp(Prog):
    5.22  
    5.23      name = "help"
    5.24 @@ -630,5 +644,86 @@ class ProgLog(Prog):
    5.25  
    5.26  xm.prog(ProgLog)
    5.27  
    5.28 +class ProgVifList(Prog):
    5.29 +    group = 'vif'
    5.30 +    name  = 'vif-list'
    5.31 +    info  = """List virtual network interfaces for a domain."""
    5.32 +
    5.33 +    def help(self, args):
    5.34 +        print args[0], "DOM"
    5.35 +        print "\nList virtual network interfaces for domain DOM"
    5.36 +
    5.37 +    def main(self, args):
    5.38 +        if len(args) != 2: self.err("%s: Invalid argument(s)" % args[0])
    5.39 +        dom = args[1]
    5.40 +        for x in server.xend_domain_vifs(dom):
    5.41 +            sxp.show(x)
    5.42 +            print
    5.43 +
    5.44 +xm.prog(ProgVifList)
    5.45 +
    5.46 +class ProgVbdList(Prog):
    5.47 +    group = 'vbd'
    5.48 +    name  = 'vbd-list'
    5.49 +    info  = """List virtual block devices for a domain."""
    5.50 +
    5.51 +    def help(self, args):
    5.52 +        print args[0], "DOM"
    5.53 +        print "\nList virtual block devices for domain DOM"
    5.54 +
    5.55 +    def main(self, args):
    5.56 +        if len(args) != 2: self.err("%s: Invalid argument(s)" % args[0])
    5.57 +        dom = args[1]
    5.58 +        for x in server.xend_domain_vbds(dom):
    5.59 +            sxp.show(x)
    5.60 +            print
    5.61 +
    5.62 +xm.prog(ProgVbdList)
    5.63 +
    5.64 +class ProgVbdCreate(Prog):
    5.65 +    group = 'vbd'
    5.66 +    name  = 'vbd-create'
    5.67 +    info = """Create a new virtual block device for a domain"""
    5.68 +
    5.69 +    def help(self, args):
    5.70 +        print args[0], "DOM UNAME DEV MODE"
    5.71 +        print """
    5.72 +Create a virtual block device for a domain.
    5.73 +
    5.74 +  UNAME - device to export, e.g. phys:hda2
    5.75 +  DEV   - device name in the domain, e.g. xda1
    5.76 +  MODE  - access mode: r for read, w for read-write
    5.77 +"""
    5.78 +
    5.79 +    def main(self, args):
    5.80 +        if len(args) != 5: self.err("%s: Invalid argument(s)" % args[0])
    5.81 +        dom = args[1]
    5.82 +        vbd = ['vbd',
    5.83 +               ['uname', args[2]],
    5.84 +               ['dev',   args[3]],
    5.85 +               ['mode',  args[4]]]
    5.86 +        server.xend_domain_device_create(dom, vbd)
    5.87 +
    5.88 +xm.prog(ProgVbdCreate)
    5.89 +
    5.90 +class ProgVbdDestroy(Prog):
    5.91 +    group = 'vbd'
    5.92 +    name = 'vbd-destroy'
    5.93 +    info = """Destroy a domain's virtual block device"""
    5.94 +
    5.95 +    def help(self, args):
    5.96 +        print args[0], "DOM DEV"
    5.97 +        print """
    5.98 +Destroy vbd DEV attached to domain DOM. Detaches the device
    5.99 +from the domain, but does not destroy the device contents."""
   5.100 +
   5.101 +    def main(self, args):
   5.102 +        if len(args!=3): self.err("%s: Invalid argument(s)" % args[0])
   5.103 +        dom = args[1]
   5.104 +        dev = args[2]
   5.105 +        sever.xend_domain_device_destroy(dom, "vbd", dev)
   5.106 +
   5.107 +xm.prog(ProgVbdDestroy)
   5.108 +
   5.109  def main(args):
   5.110      xm.main(args)