# HG changeset patch
# User emellor@ewan
# Node ID 909172f2aa54035d5b918528eea0bcc4aaf15429
# Parent 74b05ac4706ffc9f00655183725221c20f93171b
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@xxxxxxxxxxxxx>
diff -r 74b05ac4706f -r 909172f2aa54 tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py Sat Sep 24 21:57:26 2005
+++ b/tools/python/xen/xend/XendDomain.py Sat Sep 24 22:10:31 2005
@@ -433,12 +433,11 @@
self.domain_shutdowns()
return val
+
def domain_sysrq(self, id, key):
- """Send a SysRq to a domain
- """
- dominfo = self.domain_lookup(id)
- val = dominfo.send_sysrq(key)
- return val
+ """Send a SysRq to the specified domain."""
+ return self.callInfo(id, XendDomainInfo.send_sysrq, key)
+
def domain_shutdowns(self):
"""Process pending domain shutdowns.
@@ -630,73 +629,45 @@
except Exception, ex:
raise XendError(str(ex))
- def domain_device_create(self, id, devconfig):
- """Create a new device for a domain.
-
- @param id: domain id
- @param devconfig: device configuration
- """
- dominfo = self.domain_lookup(id)
- val = dominfo.device_create(devconfig)
- dominfo.exportToDB()
- return val
-
- def domain_device_configure(self, id, devconfig, devid):
- """Configure an existing device for a domain.
-
- @param id: domain id
- @param devconfig: device configuration
- @param devid: device id
+
+ def domain_device_create(self, domid, devconfig):
+ """Create a new device for the specified domain.
+ """
+ return self.callInfo(domid, XendDomainInfo.device_create, devconfig)
+
+
+ def domain_device_configure(self, domid, devconfig, devid):
+ """Configure an existing device in the specified domain.
@return: updated device configuration
"""
- dominfo = self.domain_lookup(id)
- val = dominfo.device_configure(devconfig, devid)
- dominfo.exportToDB()
- return val
+ return self.callInfo(domid, XendDomainInfo.device_configure,
+ devconfig, devid)
+
- def domain_device_refresh(self, id, type, devid):
- """Refresh a device.
-
- @param id: domain id
- @param devid: device id
- @param type: device type
- """
- dominfo = self.domain_lookup(id)
- val = dominfo.device_refresh(type, devid)
- dominfo.exportToDB()
- return val
-
- def domain_device_destroy(self, id, type, devid):
- """Destroy a device.
-
- @param id: domain id
- @param devid: device id
- @param type: device type
- """
- dominfo = self.domain_lookup(id)
- return dominfo.destroyDevice(type, devid)
-
-
- def domain_devtype_ls(self, id, type):
- """Get list of device sxprs for a domain.
-
- @param id: domain
- @param type: device type
- @return: device sxprs
- """
- dominfo = self.domain_lookup(id)
- return dominfo.getDeviceSxprs(type)
-
- def domain_devtype_get(self, id, type, devid):
+ def domain_device_refresh(self, domid, devtype, devid):
+ """Refresh a device."""
+ return self.callInfo(domid, XendDomainInfo.device_refresh, devtype,
+ devid)
+
+
+ def domain_device_destroy(self, domid, devtype, devid):
+ """Destroy a device."""
+ return self.callInfo(domid, XendDomainInfo.destroyDevice, devtype,
+ devid)
+
+
+ def domain_devtype_ls(self, domid, devtype):
+ """Get list of device sxprs for the specified domain."""
+ return self.callInfo(domid, XendDomainInfo.getDeviceSxprs, devtype)
+
+
+ def domain_devtype_get(self, domid, devtype, devid):
"""Get a device from a domain.
- @param id: domain
- @param type: device type
- @param devid: device id
@return: device object (or None)
"""
- dominfo = self.domain_lookup(id)
- return dominfo.getDevice(type, devid)
+ return self.callInfo(domid, XendDomainInfo.getDevice, devtype, devid)
+
def domain_vif_limit_set(self, id, vif, credit, period):
"""Limit the vif's transmission rate
@@ -723,7 +694,7 @@
"""Set the memory limit for a domain.
@param id: domain
- @param mem: memory limit (in MB)
+ @param mem: memory limit (in MiB)
@return: 0 on success, -1 on error
"""
dominfo = self.domain_lookup(id)
@@ -734,42 +705,37 @@
except Exception, ex:
raise XendError(str(ex))
- def domain_mem_target_set(self, id, mem):
+ def domain_mem_target_set(self, domid, mem):
"""Set the memory target for a domain.
- @param id: domain
- @param mem: memory target (in MB)
- @return: 0 on success, -1 on error
- """
- dominfo = self.domain_lookup(id)
- return dominfo.setMemoryTarget(mem << 10)
-
- def domain_vcpu_hotplug(self, id, vcpu, state):
- """Enable or disable VCPU vcpu in DOM id
-
- @param id: domain
+ @param mem: memory target (in MiB)
+ """
+ self.callInfo(domid, XendDomainInfo.setMemoryTarget, mem << 10)
+
+
+ def domain_vcpu_hotplug(self, domid, vcpu, state):
+ """Enable or disable specified VCPU in specified domain
+
@param vcpu: target VCPU in domain
@param state: which state VCPU will become
- @return: 0 on success, -1 on error
- """
-
- dominfo = self.domain_lookup(id)
- return dominfo.vcpu_hotplug(vcpu, state)
-
- def domain_dumpcore(self, id):
- """Save a core dump for a crashed domain.
-
- @param id: domain
- """
- dominfo = self.domain_lookup(id)
- corefile = "/var/xen/dump/%s.%s.core" % (dominfo.getName(),
- dominfo.getDomid())
- try:
- xc.domain_dumpcore(dom=dominfo.getDomid(), corefile=corefile)
- except Exception, ex:
- log.warning("Dumpcore failed, id=%s name=%s: %s",
- dominfo.getDomid(), dominfo.getName(), ex)
-
+ """
+ self.callInfo(domid, XendDomainInfo.vcpu_hotplug, vcpu, state)
+
+
+ def domain_dumpcore(self, domid):
+ """Save a core dump for a crashed domain."""
+ self.callInfo(domid, XendDomainInfo.dumpCore)
+
+
+ ## private:
+
+ def callInfo(self, domid, fn, *args, **kwargs):
+ self.refresh()
+ dominfo = self.domains.get(domid)
+ if dominfo:
+ return fn(dominfo, *args, **kwargs)
+
+
def instance():
"""Singleton constructor. Use this instead of the class constructor.
"""
diff -r 74b05ac4706f -r 909172f2aa54 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py Sat Sep 24 21:57:26 2005
+++ b/tools/python/xen/xend/XendDomainInfo.py Sat Sep 24 22:10:31 2005
@@ -511,6 +511,19 @@
def getBackendFlags(self):
return reduce(lambda x, y: x | backendFlags[y],
self.info['backend'], 0)
+
+
+ def dumpCore(self):
+ """Create a core dump for this domain. Nothrow guarantee."""
+
+ try:
+ corefile = "/var/xen/dump/%s.%s.core" % (self.info['name'],
+ self.domid)
+ xc.domain_dumpcore(dom = self.domid, corefile = corefile)
+
+ except Exception, exn:
+ log.error("XendDomainInfo.dumpCore failed: id = %s name = %s: %s",
+ self.domid, self.info['name'], str(exn))
def closeStoreChannel(self):
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|