ia64/xen-unstable

changeset 7147:82e8a1d7230f

Added DevController.configuration and configurations methods. These parse the
store for the current device configuration, and convert it back into the
s-expression used in the config files and the save files. This means that we
can bring the devices up properly on restore.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Fri Sep 30 10:48:49 2005 +0100 (2005-09-30)
parents b9e5573785bb
children 41b1f86628a0
files tools/python/xen/xend/server/DevController.py tools/python/xen/xend/server/blkif.py tools/python/xen/xend/server/netif.py
line diff
     1.1 --- a/tools/python/xen/xend/server/DevController.py	Thu Sep 29 16:57:23 2005 +0100
     1.2 +++ b/tools/python/xen/xend/server/DevController.py	Fri Sep 30 10:48:49 2005 +0100
     1.3 @@ -75,12 +75,28 @@ class DevController:
     1.4          """
     1.5  
     1.6          frontpath = self.frontendPath(devid)
     1.7 -        backpath = xstransact.Read("%s/backend" % frontpath)
     1.8 +        backpath = xstransact.Read(frontpath, "backend")
     1.9  
    1.10          xstransact.Remove(frontpath)
    1.11          xstransact.Remove(backpath)
    1.12  
    1.13  
    1.14 +    def configurations(self):
    1.15 +        return map(lambda x: self.configuration(int(x)),
    1.16 +                   xstransact.List(self.frontendRoot()))
    1.17 +
    1.18 +
    1.19 +    def configuration(self, devid):
    1.20 +        """@return an s-expression giving the current configuration of the
    1.21 +        specified device.  This would be suitable for giving to {@link
    1.22 +        #createDevice} in order to recreate that device."""
    1.23 +
    1.24 +        backdomid = int(xstransact.Read(self.frontendPath(devid),
    1.25 +                                        "backend-id"))
    1.26 +
    1.27 +        return [self.deviceClass, ['backend', backdomid]]
    1.28 +
    1.29 +
    1.30      def sxprs(self):
    1.31          """@return an s-expression describing all the devices of this
    1.32          controller's device-class.
    1.33 @@ -150,6 +166,12 @@ class DevController:
    1.34                  raise
    1.35  
    1.36  
    1.37 +    def readBackend(self, devid, *args):
    1.38 +        frontpath = self.frontendPath(devid)
    1.39 +        backpath = xstransact.Read(frontpath, "backend")
    1.40 +        return xstransact.Read(backpath, *args)
    1.41 +
    1.42 +
    1.43      ## private:
    1.44  
    1.45      def writeDetails(self, config, devid, backDetails, frontDetails):
    1.46 @@ -211,4 +233,5 @@ class DevController:
    1.47  
    1.48  
    1.49      def frontendMiscPath(self):
    1.50 -        return "%s/device-misc/%s" % (self.vm.getPath(), self.deviceClass)
    1.51 +        return "%s/device-misc/%s" % (self.vm.getPath(),
    1.52 +                                      self.deviceClass)
     2.1 --- a/tools/python/xen/xend/server/blkif.py	Thu Sep 29 16:57:23 2005 +0100
     2.2 +++ b/tools/python/xen/xend/server/blkif.py	Fri Sep 30 10:48:49 2005 +0100
     2.3 @@ -40,14 +40,15 @@ class BlkifController(DevController):
     2.4      def getDeviceDetails(self, config):
     2.5          """@see DevController.getDeviceDetails"""
     2.6          
     2.7 -        typedev = sxp.child_value(config, 'dev')
     2.8 -        if re.match('^ioemu:', typedev):
     2.9 +        dev = sxp.child_value(config, 'dev')
    2.10 +        if re.match('^ioemu:', dev):
    2.11              return (0,{},{})
    2.12  
    2.13 -        devid = blkif.blkdev_name_to_number(sxp.child_value(config, 'dev'))
    2.14 +        devid = blkif.blkdev_name_to_number(dev)
    2.15  
    2.16          (typ, params) = string.split(sxp.child_value(config, 'uname'), ':', 1)
    2.17 -        back = { 'type' : typ,
    2.18 +        back = { 'dev' : dev,
    2.19 +                 'type' : typ,
    2.20                   'params' : params
    2.21                   }
    2.22  
    2.23 @@ -57,3 +58,22 @@ class BlkifController(DevController):
    2.24          front = { 'virtual-device' : "%i" % devid }
    2.25  
    2.26          return (devid, back, front)
    2.27 +
    2.28 +
    2.29 +    def configuration(self, devid):
    2.30 +        """@see DevController.configuration"""
    2.31 +
    2.32 +        result = DevController.configuration(self, devid)
    2.33 +
    2.34 +        (dev, typ, params, ro) = self.readBackend(devid,
    2.35 +                                                  'dev', 'type', 'params',
    2.36 +                                                  'read-only')
    2.37 +
    2.38 +        result.append(['dev', dev])
    2.39 +        result.append(['uname', typ + ":" + params])
    2.40 +        if ro:
    2.41 +            result.append(['mode', 'r'])
    2.42 +        else:
    2.43 +            result.append(['mode', 'w'])
    2.44 +
    2.45 +        return result
     3.1 --- a/tools/python/xen/xend/server/netif.py	Thu Sep 29 16:57:23 2005 +0100
     3.2 +++ b/tools/python/xen/xend/server/netif.py	Fri Sep 30 10:48:49 2005 +0100
     3.3 @@ -23,10 +23,14 @@
     3.4  import os
     3.5  
     3.6  from xen.xend import sxp
     3.7 +from xen.xend import XendRoot
     3.8  
     3.9  from xen.xend.server.DevController import DevController
    3.10  
    3.11  
    3.12 +xroot = XendRoot.instance()
    3.13 +
    3.14 +
    3.15  class NetifController(DevController):
    3.16      """Network interface controller. Handles all network devices for a domain.
    3.17      """
    3.18 @@ -38,9 +42,6 @@ class NetifController(DevController):
    3.19      def getDeviceDetails(self, config):
    3.20          """@see DevController.getDeviceDetails"""
    3.21  
    3.22 -        from xen.xend import XendRoot
    3.23 -        xroot = XendRoot.instance()
    3.24 -
    3.25          def _get_config_ipaddr(config):
    3.26              val = []
    3.27              for ipaddr in sxp.children(config, elt='ip'):
    3.28 @@ -68,3 +69,22 @@ class NetifController(DevController):
    3.29                    'mac' : mac }
    3.30  
    3.31          return (devid, back, front)
    3.32 +
    3.33 +
    3.34 +    def configuration(self, devid):
    3.35 +        """@see DevController.configuration"""
    3.36 +
    3.37 +        result = DevController.configuration(self, devid)
    3.38 +
    3.39 +        (script, ip, bridge, mac) = self.readBackend(devid,
    3.40 +                                                     'script', 'ip', 'bridge',
    3.41 +                                                     'mac')
    3.42 +
    3.43 +        result.append(['script',
    3.44 +                       script.replace(xroot.network_script_dir + os.sep, "")])
    3.45 +        if ip:
    3.46 +            result.append(['ip', ip.split(" ")])
    3.47 +        result.append(['bridge', bridge])
    3.48 +        result.append(['mac', mac])
    3.49 +
    3.50 +        return result