[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] Many files:
ChangeSet 1.1662.1.5, 2005/06/06 16:02:32+01:00, cl349@xxxxxxxxxxxxxxxxxxxx Many files: Remove device indexing. Signed-off-by: Mike Wray <mike.wray@xxxxxx> Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx> XendDomain.py | 4 +-- XendDomainInfo.py | 68 ++++++++++++++------------------------------------- server/blkif.py | 1 server/console.py | 1 server/controller.py | 39 +++++++++-------------------- server/netif.py | 1 server/usbif.py | 1 7 files changed, 34 insertions(+), 81 deletions(-) diff -Nru a/tools/python/xen/xend/XendDomain.py b/tools/python/xen/xend/XendDomain.py --- a/tools/python/xen/xend/XendDomain.py 2005-06-09 13:05:07 -04:00 +++ b/tools/python/xen/xend/XendDomain.py 2005-06-09 13:05:07 -04:00 @@ -650,13 +650,13 @@ @return: device object (or None) """ dominfo = self.domain_lookup(id) - return dominfo.getDeviceByIndex(type, devid) + return dominfo.getDevice(type, devid) def domain_vif_limit_set(self, id, vif, credit, period): """Limit the vif's transmission rate """ dominfo = self.domain_lookup(id) - dev = dominfo.getDeviceById('vif', vif) + dev = dominfo.getDevice('vif', vif) if not dev: raise XendError("invalid vif") return dev.setCreditLimit(credit, period) diff -Nru a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py --- a/tools/python/xen/xend/XendDomainInfo.py 2005-06-09 13:05:07 -04:00 +++ b/tools/python/xen/xend/XendDomainInfo.py 2005-06-09 13:05:07 -04:00 @@ -353,7 +353,7 @@ self.controllers[type] = ctrl return ctrl - def createDevice(self, type, devconfig, recreate=False): + def createDevice(self, type, devconfig): ctrl = self.findDeviceController(type) return ctrl.createDevice(devconfig, recreate=self.recreate) @@ -369,30 +369,14 @@ ctrl = self.getDeviceController(type) return ctrl.deleteDevice(id) - def getDevice(self, type, id): + def getDevice(self, type, id, error=True): ctrl = self.getDeviceController(type) - return ctrl.getDevice(id) + return ctrl.getDevice(id, error=error) - def getDeviceByIndex(self, type, idx): - ctrl = self.getDeviceController(type) - return ctrl.getDeviceByIndex(idx) - - def getDeviceConfig(self, type, id): - ctrl = self.getDeviceController(type) - return ctrl.getDeviceConfig(id) - def getDeviceIds(self, type): ctrl = self.getDeviceController(type) return ctrl.getDeviceIds() - def getDeviceIndexes(self, type): - ctrl = self.getDeviceController(type) - return ctrl.getDeviceIndexes() - - def getDeviceConfigs(self, type): - ctrl = self.getDeviceController(type) - return ctrl.getDeviceConfigs() - def getDeviceSxprs(self, type): ctrl = self.getDeviceController(type) return ctrl.getDeviceSxprs() @@ -578,24 +562,23 @@ devices.append(dev) return devices - def get_device_savedinfo(self, type, index): + def get_device_savedinfo(self, type, id): val = None if self.savedinfo is None: return val devices = sxp.child(self.savedinfo, 'devices') if devices is None: return val - index = str(index) for d in sxp.children(devices, type): - dindex = sxp.child_value(d, 'index') - if dindex is None: continue - if str(dindex) == index: + did = sxp.child_value(d, 'id') + if did is None: continue + if int(did) == id: val = d break return val - def get_device_recreate(self, type, index): - return self.get_device_savedinfo(type, index) or self.recreate + def get_device_recreate(self, type, id): + return self.get_device_savedinfo(type, id) or self.recreate def add_config(self, val): """Add configuration data to a virtual machine. @@ -765,7 +748,6 @@ def create_configured_devices(self): devices = sxp.children(self.config, 'device') - indexes = {} for d in devices: dev_config = sxp.child0(d) if dev_config is None: @@ -774,13 +756,7 @@ ctrl_type = get_device_handler(dev_type) if ctrl_type is None: raise VmError('unknown device type: ' + dev_type) - # Keep track of device indexes by type, so we can fish - # out saved info for recreation. - idx = indexes.get(dev_type, -1) - idx += 1 - indexes[ctrl_type] = idx - recreate = self.get_device_recreate(dev_type, idx) - self.createDevice(ctrl_type, dev_config, recreate=recreate) + self.createDevice(ctrl_type, dev_config) def create_devices(self): """Create the devices for a vm. @@ -840,16 +816,14 @@ self.config.append(['device', dev.getConfig()]) return dev.sxpr() - def device_configure(self, dev_config, idx): + def device_configure(self, dev_config, id): """Configure an existing device. @param dev_config: device configuration - @param idx: device index + @param id: device id """ type = sxp.name(dev_config) - dev = self.getDeviceByIndex(type, idx) - if not dev: - raise VmError('invalid device: %s %s' % (type, idx)) + dev = self.getDevice(type, id) old_config = dev.getConfig() new_config = dev.configure(dev_config, change=True) # Patch new config into vm config. @@ -859,26 +833,22 @@ self.config[old_index] = new_full_config return new_config - def device_refresh(self, type, idx): + def device_refresh(self, type, id): """Refresh a device. @param type: device type - @param idx: device index + @param id: device id """ - dev = self.getDeviceByIndex(type, idx) - if not dev: - raise VmError('invalid device: %s %s' % (type, idx)) + dev = self.getDevice(type, id) dev.refresh() - def device_delete(self, type, idx): + def device_delete(self, type, id): """Destroy and remove a device. @param type: device type - @param idx: device index + @param id: device id """ - dev = self.getDeviceByIndex(type, idx) - if not dev: - raise VmError('invalid device: %s %s' % (type, idx)) + dev = self.getDevice(type, id) dev_config = dev.getConfig() if dev_config: self.config.remove(['device', dev_config]) diff -Nru a/tools/python/xen/xend/server/blkif.py b/tools/python/xen/xend/server/blkif.py --- a/tools/python/xen/xend/server/blkif.py 2005-06-09 13:05:07 -04:00 +++ b/tools/python/xen/xend/server/blkif.py 2005-06-09 13:05:07 -04:00 @@ -293,7 +293,6 @@ val.append(['uname', self.uname]) if self.node: val.append(['node', self.node]) - val.append(['index', self.getIndex()]) return val def getBackend(self): diff -Nru a/tools/python/xen/xend/server/console.py b/tools/python/xen/xend/server/console.py --- a/tools/python/xen/xend/server/console.py 2005-06-09 13:05:07 -04:00 +++ b/tools/python/xen/xend/server/console.py 2005-06-09 13:05:07 -04:00 @@ -129,7 +129,6 @@ val.append(['local_port', self.getLocalPort() ]) val.append(['remote_port', self.getRemotePort() ]) val.append(['console_port', self.console_port ]) - val.append(['index', self.getIndex()]) if self.addr: val.append(['connected', self.addr[0], self.addr[1]]) finally: diff -Nru a/tools/python/xen/xend/server/controller.py b/tools/python/xen/xend/server/controller.py --- a/tools/python/xen/xend/server/controller.py 2005-06-09 13:05:07 -04:00 +++ b/tools/python/xen/xend/server/controller.py 2005-06-09 13:05:07 -04:00 @@ -228,19 +228,20 @@ If change is true the device is a change to an existing domain, i.e. it is being added at runtime rather than when the domain is created. """ - dev = self.newDevice(self.nextDeviceId(), config, recreate=recreate) + # skanky hack: we use the device ids to maybe find the savedinfo + # of the device... + id = self.nextDeviceId() + if recreate: + recreate = self.vm.get_device_savedinfo(self.getType(), id) + dev = self.newDevice(id, config, recreate=recreate) dev.init(recreate=recreate) self.addDevice(dev) - idx = self.getDeviceIndex(dev) - recreate = self.vm.get_device_recreate(self.getType(), idx) dev.attach(recreate=recreate, change=change) def configureDevice(self, id, config, change=False): """Reconfigure an existing device. May be defined in subclass.""" - dev = self.getDevice(id) - if not dev: - raise XendError("invalid device id: " + id) + dev = self.getDevice(id, error=True) dev.configure(config, change=change) def destroyDevice(self, id, change=False, reboot=False): @@ -251,9 +252,7 @@ The device is not deleted, since it may be recreated later. """ - dev = self.getDevice(id) - if not dev: - raise XendError("invalid device id: " + id) + dev = self.getDevice(id, error=True) dev.destroy(change=change, reboot=reboot) return dev @@ -278,24 +277,15 @@ def isDestroyed(self): return self.destroyed - def getDevice(self, id): - return self.devices.get(id) - - def getDeviceByIndex(self, idx): - if 0 <= idx < len(self.device_order): - return self.device_order[idx] - else: - return None - - def getDeviceIndex(self, dev): - return self.device_order.index(dev) + def getDevice(self, id, error=False): _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |