direct-io.hg
changeset 7054:909172f2aa54
Add helper method XendDomain.callInfo that stubs through into XendDomainInfo.
This is used to remove much of the code duplication in the public methods there.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
This is used to remove much of the code duplication in the public methods there.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
author | emellor@ewan |
---|---|
date | Sat Sep 24 23:10:31 2005 +0100 (2005-09-24) |
parents | 74b05ac4706f |
children | 5ea81e640509 b6e58e2daff8 |
files | tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py |
line diff
1.1 --- a/tools/python/xen/xend/XendDomain.py Sat Sep 24 22:57:26 2005 +0100 1.2 +++ b/tools/python/xen/xend/XendDomain.py Sat Sep 24 23:10:31 2005 +0100 1.3 @@ -433,12 +433,11 @@ class XendDomain: 1.4 self.domain_shutdowns() 1.5 return val 1.6 1.7 + 1.8 def domain_sysrq(self, id, key): 1.9 - """Send a SysRq to a domain 1.10 - """ 1.11 - dominfo = self.domain_lookup(id) 1.12 - val = dominfo.send_sysrq(key) 1.13 - return val 1.14 + """Send a SysRq to the specified domain.""" 1.15 + return self.callInfo(id, XendDomainInfo.send_sysrq, key) 1.16 + 1.17 1.18 def domain_shutdowns(self): 1.19 """Process pending domain shutdowns. 1.20 @@ -630,73 +629,45 @@ class XendDomain: 1.21 except Exception, ex: 1.22 raise XendError(str(ex)) 1.23 1.24 - def domain_device_create(self, id, devconfig): 1.25 - """Create a new device for a domain. 1.26 1.27 - @param id: domain id 1.28 - @param devconfig: device configuration 1.29 + def domain_device_create(self, domid, devconfig): 1.30 + """Create a new device for the specified domain. 1.31 """ 1.32 - dominfo = self.domain_lookup(id) 1.33 - val = dominfo.device_create(devconfig) 1.34 - dominfo.exportToDB() 1.35 - return val 1.36 + return self.callInfo(domid, XendDomainInfo.device_create, devconfig) 1.37 + 1.38 1.39 - def domain_device_configure(self, id, devconfig, devid): 1.40 - """Configure an existing device for a domain. 1.41 - 1.42 - @param id: domain id 1.43 - @param devconfig: device configuration 1.44 - @param devid: device id 1.45 + def domain_device_configure(self, domid, devconfig, devid): 1.46 + """Configure an existing device in the specified domain. 1.47 @return: updated device configuration 1.48 """ 1.49 - dominfo = self.domain_lookup(id) 1.50 - val = dominfo.device_configure(devconfig, devid) 1.51 - dominfo.exportToDB() 1.52 - return val 1.53 - 1.54 - def domain_device_refresh(self, id, type, devid): 1.55 - """Refresh a device. 1.56 + return self.callInfo(domid, XendDomainInfo.device_configure, 1.57 + devconfig, devid) 1.58 1.59 - @param id: domain id 1.60 - @param devid: device id 1.61 - @param type: device type 1.62 - """ 1.63 - dominfo = self.domain_lookup(id) 1.64 - val = dominfo.device_refresh(type, devid) 1.65 - dominfo.exportToDB() 1.66 - return val 1.67 - 1.68 - def domain_device_destroy(self, id, type, devid): 1.69 - """Destroy a device. 1.70 - 1.71 - @param id: domain id 1.72 - @param devid: device id 1.73 - @param type: device type 1.74 - """ 1.75 - dominfo = self.domain_lookup(id) 1.76 - return dominfo.destroyDevice(type, devid) 1.77 + 1.78 + def domain_device_refresh(self, domid, devtype, devid): 1.79 + """Refresh a device.""" 1.80 + return self.callInfo(domid, XendDomainInfo.device_refresh, devtype, 1.81 + devid) 1.82 1.83 1.84 - def domain_devtype_ls(self, id, type): 1.85 - """Get list of device sxprs for a domain. 1.86 + def domain_device_destroy(self, domid, devtype, devid): 1.87 + """Destroy a device.""" 1.88 + return self.callInfo(domid, XendDomainInfo.destroyDevice, devtype, 1.89 + devid) 1.90 + 1.91 1.92 - @param id: domain 1.93 - @param type: device type 1.94 - @return: device sxprs 1.95 - """ 1.96 - dominfo = self.domain_lookup(id) 1.97 - return dominfo.getDeviceSxprs(type) 1.98 + def domain_devtype_ls(self, domid, devtype): 1.99 + """Get list of device sxprs for the specified domain.""" 1.100 + return self.callInfo(domid, XendDomainInfo.getDeviceSxprs, devtype) 1.101 1.102 - def domain_devtype_get(self, id, type, devid): 1.103 + 1.104 + def domain_devtype_get(self, domid, devtype, devid): 1.105 """Get a device from a domain. 1.106 1.107 - @param id: domain 1.108 - @param type: device type 1.109 - @param devid: device id 1.110 @return: device object (or None) 1.111 """ 1.112 - dominfo = self.domain_lookup(id) 1.113 - return dominfo.getDevice(type, devid) 1.114 + return self.callInfo(domid, XendDomainInfo.getDevice, devtype, devid) 1.115 + 1.116 1.117 def domain_vif_limit_set(self, id, vif, credit, period): 1.118 """Limit the vif's transmission rate 1.119 @@ -723,7 +694,7 @@ class XendDomain: 1.120 """Set the memory limit for a domain. 1.121 1.122 @param id: domain 1.123 - @param mem: memory limit (in MB) 1.124 + @param mem: memory limit (in MiB) 1.125 @return: 0 on success, -1 on error 1.126 """ 1.127 dominfo = self.domain_lookup(id) 1.128 @@ -734,42 +705,37 @@ class XendDomain: 1.129 except Exception, ex: 1.130 raise XendError(str(ex)) 1.131 1.132 - def domain_mem_target_set(self, id, mem): 1.133 + def domain_mem_target_set(self, domid, mem): 1.134 """Set the memory target for a domain. 1.135 1.136 - @param id: domain 1.137 - @param mem: memory target (in MB) 1.138 - @return: 0 on success, -1 on error 1.139 + @param mem: memory target (in MiB) 1.140 """ 1.141 - dominfo = self.domain_lookup(id) 1.142 - return dominfo.setMemoryTarget(mem << 10) 1.143 + self.callInfo(domid, XendDomainInfo.setMemoryTarget, mem << 10) 1.144 + 1.145 1.146 - def domain_vcpu_hotplug(self, id, vcpu, state): 1.147 - """Enable or disable VCPU vcpu in DOM id 1.148 + def domain_vcpu_hotplug(self, domid, vcpu, state): 1.149 + """Enable or disable specified VCPU in specified domain 1.150 1.151 - @param id: domain 1.152 @param vcpu: target VCPU in domain 1.153 @param state: which state VCPU will become 1.154 - @return: 0 on success, -1 on error 1.155 """ 1.156 + self.callInfo(domid, XendDomainInfo.vcpu_hotplug, vcpu, state) 1.157 + 1.158 1.159 - dominfo = self.domain_lookup(id) 1.160 - return dominfo.vcpu_hotplug(vcpu, state) 1.161 + def domain_dumpcore(self, domid): 1.162 + """Save a core dump for a crashed domain.""" 1.163 + self.callInfo(domid, XendDomainInfo.dumpCore) 1.164 1.165 - def domain_dumpcore(self, id): 1.166 - """Save a core dump for a crashed domain. 1.167 1.168 - @param id: domain 1.169 - """ 1.170 - dominfo = self.domain_lookup(id) 1.171 - corefile = "/var/xen/dump/%s.%s.core" % (dominfo.getName(), 1.172 - dominfo.getDomid()) 1.173 - try: 1.174 - xc.domain_dumpcore(dom=dominfo.getDomid(), corefile=corefile) 1.175 - except Exception, ex: 1.176 - log.warning("Dumpcore failed, id=%s name=%s: %s", 1.177 - dominfo.getDomid(), dominfo.getName(), ex) 1.178 - 1.179 + ## private: 1.180 + 1.181 + def callInfo(self, domid, fn, *args, **kwargs): 1.182 + self.refresh() 1.183 + dominfo = self.domains.get(domid) 1.184 + if dominfo: 1.185 + return fn(dominfo, *args, **kwargs) 1.186 + 1.187 + 1.188 def instance(): 1.189 """Singleton constructor. Use this instead of the class constructor. 1.190 """
2.1 --- a/tools/python/xen/xend/XendDomainInfo.py Sat Sep 24 22:57:26 2005 +0100 2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py Sat Sep 24 23:10:31 2005 +0100 2.3 @@ -513,6 +513,19 @@ class XendDomainInfo: 2.4 self.info['backend'], 0) 2.5 2.6 2.7 + def dumpCore(self): 2.8 + """Create a core dump for this domain. Nothrow guarantee.""" 2.9 + 2.10 + try: 2.11 + corefile = "/var/xen/dump/%s.%s.core" % (self.info['name'], 2.12 + self.domid) 2.13 + xc.domain_dumpcore(dom = self.domid, corefile = corefile) 2.14 + 2.15 + except Exception, exn: 2.16 + log.error("XendDomainInfo.dumpCore failed: id = %s name = %s: %s", 2.17 + self.domid, self.info['name'], str(exn)) 2.18 + 2.19 + 2.20 def closeStoreChannel(self): 2.21 """Close the store channel, if any. Nothrow guarantee.""" 2.22