ia64/xen-unstable

changeset 5338:c3febeed5ba7

bitkeeper revision 1.1662.1.5 (42a46588UuohS0CHY1F3XZtrchaAwA)

Many files:
Remove device indexing.
Signed-off-by: Mike Wray <mike.wray@hp.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Mon Jun 06 15:02:32 2005 +0000 (2005-06-06)
parents 7d8015b52943
children a3b60b641063
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/console.py tools/python/xen/xend/server/controller.py tools/python/xen/xend/server/netif.py tools/python/xen/xend/server/usbif.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Mon Jun 06 13:04:01 2005 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Mon Jun 06 15:02:32 2005 +0000
     1.3 @@ -650,13 +650,13 @@ class XendDomain:
     1.4          @return: device object (or None)
     1.5          """
     1.6          dominfo = self.domain_lookup(id)
     1.7 -        return dominfo.getDeviceByIndex(type, devid)
     1.8 +        return dominfo.getDevice(type, devid)
     1.9  
    1.10      def domain_vif_limit_set(self, id, vif, credit, period):
    1.11          """Limit the vif's transmission rate
    1.12          """
    1.13          dominfo = self.domain_lookup(id)
    1.14 -        dev = dominfo.getDeviceById('vif', vif)
    1.15 +        dev = dominfo.getDevice('vif', vif)
    1.16          if not dev:
    1.17              raise XendError("invalid vif")
    1.18          return dev.setCreditLimit(credit, period)
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Mon Jun 06 13:04:01 2005 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Mon Jun 06 15:02:32 2005 +0000
     2.3 @@ -353,7 +353,7 @@ class XendDomainInfo:
     2.4          self.controllers[type] = ctrl
     2.5          return ctrl
     2.6  
     2.7 -    def createDevice(self, type, devconfig, recreate=False):
     2.8 +    def createDevice(self, type, devconfig):
     2.9          ctrl = self.findDeviceController(type)
    2.10          return ctrl.createDevice(devconfig, recreate=self.recreate)
    2.11  
    2.12 @@ -369,30 +369,14 @@ class XendDomainInfo:
    2.13          ctrl = self.getDeviceController(type)
    2.14          return ctrl.deleteDevice(id)
    2.15  
    2.16 -    def getDevice(self, type, id):
    2.17 -        ctrl = self.getDeviceController(type)
    2.18 -        return ctrl.getDevice(id)
    2.19 -        
    2.20 -    def getDeviceByIndex(self, type, idx):
    2.21 +    def getDevice(self, type, id, error=True):
    2.22          ctrl = self.getDeviceController(type)
    2.23 -        return ctrl.getDeviceByIndex(idx)
    2.24 -
    2.25 -    def getDeviceConfig(self, type, id):
    2.26 -        ctrl = self.getDeviceController(type)
    2.27 -        return ctrl.getDeviceConfig(id)
    2.28 -
    2.29 +        return ctrl.getDevice(id, error=error)
    2.30 +        
    2.31      def getDeviceIds(self, type):
    2.32          ctrl = self.getDeviceController(type)
    2.33          return ctrl.getDeviceIds()
    2.34      
    2.35 -    def getDeviceIndexes(self, type):
    2.36 -        ctrl = self.getDeviceController(type)
    2.37 -        return ctrl.getDeviceIndexes()
    2.38 -    
    2.39 -    def getDeviceConfigs(self, type):
    2.40 -        ctrl = self.getDeviceController(type)
    2.41 -        return ctrl.getDeviceConfigs()
    2.42 -
    2.43      def getDeviceSxprs(self, type):
    2.44          ctrl = self.getDeviceController(type)
    2.45          return ctrl.getDeviceSxprs()
    2.46 @@ -578,24 +562,23 @@ class XendDomainInfo:
    2.47                  devices.append(dev)
    2.48          return devices
    2.49  
    2.50 -    def get_device_savedinfo(self, type, index):
    2.51 +    def get_device_savedinfo(self, type, id):
    2.52          val = None
    2.53          if self.savedinfo is None:
    2.54              return val
    2.55          devices = sxp.child(self.savedinfo, 'devices')
    2.56          if devices is None:
    2.57              return val
    2.58 -        index = str(index)
    2.59          for d in sxp.children(devices, type):
    2.60 -            dindex = sxp.child_value(d, 'index')
    2.61 -            if dindex is None: continue
    2.62 -            if str(dindex) == index:
    2.63 +            did = sxp.child_value(d, 'id')
    2.64 +            if did is None: continue
    2.65 +            if int(did) == id:
    2.66                  val = d
    2.67                  break
    2.68          return val
    2.69  
    2.70 -    def get_device_recreate(self, type, index):
    2.71 -        return self.get_device_savedinfo(type, index) or self.recreate
    2.72 +    def get_device_recreate(self, type, id):
    2.73 +        return self.get_device_savedinfo(type, id) or self.recreate
    2.74  
    2.75      def add_config(self, val):
    2.76          """Add configuration data to a virtual machine.
    2.77 @@ -765,7 +748,6 @@ class XendDomainInfo:
    2.78  
    2.79      def create_configured_devices(self):
    2.80          devices = sxp.children(self.config, 'device')
    2.81 -        indexes = {}
    2.82          for d in devices:
    2.83              dev_config = sxp.child0(d)
    2.84              if dev_config is None:
    2.85 @@ -774,13 +756,7 @@ class XendDomainInfo:
    2.86              ctrl_type = get_device_handler(dev_type)
    2.87              if ctrl_type is None:
    2.88                  raise VmError('unknown device type: ' + dev_type)
    2.89 -            # Keep track of device indexes by type, so we can fish
    2.90 -            # out saved info for recreation.
    2.91 -            idx = indexes.get(dev_type, -1)
    2.92 -            idx += 1
    2.93 -            indexes[ctrl_type] = idx
    2.94 -            recreate = self.get_device_recreate(dev_type, idx)
    2.95 -            self.createDevice(ctrl_type, dev_config, recreate=recreate)
    2.96 +            self.createDevice(ctrl_type, dev_config)
    2.97          
    2.98      def create_devices(self):
    2.99          """Create the devices for a vm.
   2.100 @@ -840,16 +816,14 @@ class XendDomainInfo:
   2.101          self.config.append(['device', dev.getConfig()])
   2.102          return dev.sxpr()
   2.103  
   2.104 -    def device_configure(self, dev_config, idx):
   2.105 +    def device_configure(self, dev_config, id):
   2.106          """Configure an existing device.
   2.107  
   2.108          @param dev_config: device configuration
   2.109 -        @param idx:  device index
   2.110 +        @param id:         device id
   2.111          """
   2.112          type = sxp.name(dev_config)
   2.113 -        dev = self.getDeviceByIndex(type, idx)
   2.114 -        if not dev:
   2.115 -            raise VmError('invalid device: %s %s' % (type, idx))
   2.116 +        dev = self.getDevice(type, id)
   2.117          old_config = dev.getConfig()
   2.118          new_config = dev.configure(dev_config, change=True)
   2.119          # Patch new config into vm config.
   2.120 @@ -859,26 +833,22 @@ class XendDomainInfo:
   2.121          self.config[old_index] = new_full_config
   2.122          return new_config
   2.123  
   2.124 -    def device_refresh(self, type, idx):
   2.125 +    def device_refresh(self, type, id):
   2.126          """Refresh a device.
   2.127  
   2.128          @param type: device type
   2.129 -        @param idx:  device index
   2.130 +        @param id:   device id
   2.131          """
   2.132 -        dev = self.getDeviceByIndex(type, idx)
   2.133 -        if not dev:
   2.134 -            raise VmError('invalid device: %s %s' % (type, idx))
   2.135 +        dev = self.getDevice(type, id)
   2.136          dev.refresh()
   2.137          
   2.138 -    def device_delete(self, type, idx):
   2.139 +    def device_delete(self, type, id):
   2.140          """Destroy and remove a device.
   2.141  
   2.142          @param type: device type
   2.143 -        @param idx:  device index
   2.144 +        @param id:   device id
   2.145          """
   2.146 -        dev = self.getDeviceByIndex(type, idx)
   2.147 -        if not dev:
   2.148 -            raise VmError('invalid device: %s %s' % (type, idx))
   2.149 +        dev = self.getDevice(type, id)
   2.150          dev_config = dev.getConfig()
   2.151          if dev_config:
   2.152              self.config.remove(['device', dev_config])
     3.1 --- a/tools/python/xen/xend/server/blkif.py	Mon Jun 06 13:04:01 2005 +0000
     3.2 +++ b/tools/python/xen/xend/server/blkif.py	Mon Jun 06 15:02:32 2005 +0000
     3.3 @@ -293,7 +293,6 @@ class BlkDev(Dev):
     3.4              val.append(['uname', self.uname])
     3.5          if self.node:
     3.6              val.append(['node', self.node])
     3.7 -        val.append(['index', self.getIndex()])
     3.8          return val
     3.9  
    3.10      def getBackend(self):
     4.1 --- a/tools/python/xen/xend/server/console.py	Mon Jun 06 13:04:01 2005 +0000
     4.2 +++ b/tools/python/xen/xend/server/console.py	Mon Jun 06 15:02:32 2005 +0000
     4.3 @@ -129,7 +129,6 @@ class ConsoleDev(Dev, protocol.ServerFac
     4.4              val.append(['local_port',   self.getLocalPort()  ])
     4.5              val.append(['remote_port',  self.getRemotePort() ])
     4.6              val.append(['console_port', self.console_port    ])
     4.7 -            val.append(['index', self.getIndex()])
     4.8              if self.addr:
     4.9                  val.append(['connected', self.addr[0], self.addr[1]])
    4.10          finally:
     5.1 --- a/tools/python/xen/xend/server/controller.py	Mon Jun 06 13:04:01 2005 +0000
     5.2 +++ b/tools/python/xen/xend/server/controller.py	Mon Jun 06 15:02:32 2005 +0000
     5.3 @@ -228,19 +228,20 @@ class DevController:
     5.4          If change is true the device is a change to an existing domain,
     5.5          i.e. it is being added at runtime rather than when the domain is created.
     5.6          """
     5.7 -        dev = self.newDevice(self.nextDeviceId(), config, recreate=recreate)
     5.8 +        # skanky hack: we use the device ids to maybe find the savedinfo
     5.9 +        # of the device...
    5.10 +        id = self.nextDeviceId()
    5.11 +        if recreate:
    5.12 +            recreate = self.vm.get_device_savedinfo(self.getType(), id)
    5.13 +        dev = self.newDevice(id, config, recreate=recreate)
    5.14          dev.init(recreate=recreate)
    5.15          self.addDevice(dev)
    5.16 -        idx = self.getDeviceIndex(dev)
    5.17 -        recreate = self.vm.get_device_recreate(self.getType(), idx)
    5.18          dev.attach(recreate=recreate, change=change)
    5.19  
    5.20      def configureDevice(self, id, config, change=False):
    5.21          """Reconfigure an existing device.
    5.22          May be defined in subclass."""
    5.23 -        dev = self.getDevice(id)
    5.24 -        if not dev:
    5.25 -            raise XendError("invalid device id: " + id)
    5.26 +        dev = self.getDevice(id, error=True)
    5.27          dev.configure(config, change=change)
    5.28  
    5.29      def destroyDevice(self, id, change=False, reboot=False):
    5.30 @@ -251,9 +252,7 @@ class DevController:
    5.31  
    5.32          The device is not deleted, since it may be recreated later.
    5.33          """
    5.34 -        dev = self.getDevice(id)
    5.35 -        if not dev:
    5.36 -            raise XendError("invalid device id: " + id)
    5.37 +        dev = self.getDevice(id, error=True)
    5.38          dev.destroy(change=change, reboot=reboot)
    5.39          return dev
    5.40  
    5.41 @@ -278,24 +277,15 @@ class DevController:
    5.42      def isDestroyed(self):
    5.43          return self.destroyed
    5.44  
    5.45 -    def getDevice(self, id):
    5.46 -        return self.devices.get(id)
    5.47 -
    5.48 -    def getDeviceByIndex(self, idx):
    5.49 -        if 0 <= idx < len(self.device_order):
    5.50 -            return self.device_order[idx]
    5.51 -        else:
    5.52 -            return None
    5.53 -
    5.54 -    def getDeviceIndex(self, dev):
    5.55 -        return self.device_order.index(dev)
    5.56 +    def getDevice(self, id, error=False):
    5.57 +        dev = self.devices.get(id)
    5.58 +        if error and not dev:
    5.59 +            raise XendError("invalid device id: " + id)
    5.60 +        return dev
    5.61  
    5.62      def getDeviceIds(self):
    5.63          return [ dev.getId() for dev in self.device_order ]
    5.64  
    5.65 -    def getDeviceIndexes(self):
    5.66 -        return range(0, len(self.device_order))
    5.67 -    
    5.68      def getDevices(self):
    5.69          return self.device_order
    5.70  
    5.71 @@ -380,9 +370,6 @@ class Dev:
    5.72      def getId(self):
    5.73          return self.id
    5.74  
    5.75 -    def getIndex(self):
    5.76 -        return self.controller.getDeviceIndex(self)
    5.77 -
    5.78      def getConfig(self):
    5.79          return self.config
    5.80  
     6.1 --- a/tools/python/xen/xend/server/netif.py	Mon Jun 06 13:04:01 2005 +0000
     6.2 +++ b/tools/python/xen/xend/server/netif.py	Mon Jun 06 15:02:32 2005 +0000
     6.3 @@ -199,7 +199,6 @@ class NetDev(Dev):
     6.4              val.append(['evtchn',
     6.5                          self.evtchn['port1'],
     6.6                          self.evtchn['port2']])
     6.7 -        val.append(['index', self.getIndex()])
     6.8          return val
     6.9  
    6.10      def get_vifname(self):
     7.1 --- a/tools/python/xen/xend/server/usbif.py	Mon Jun 06 13:04:01 2005 +0000
     7.2 +++ b/tools/python/xen/xend/server/usbif.py	Mon Jun 06 15:02:32 2005 +0000
     7.3 @@ -186,7 +186,6 @@ class UsbDev(Dev):
     7.4                 ['port', self.port],
     7.5                 ['path', self.path],
     7.6                 ]
     7.7 -        val.append(['index', self.getIndex()])
     7.8          return val
     7.9  
    7.10      def getBackend(self):