aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>2005-06-03 16:17:30 +0000
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>2005-06-03 16:17:30 +0000
commit57fbe22719d3bee4786a76f9eaf74f9ec78db2be (patch)
tree0adf2e5ce7e78faecf87b02cf7cdfee970a4bfb5 /tools
parentd057c5ef08bf78313c6fa0740d2fe9f40b05fefe (diff)
downloadxen-57fbe22719d3bee4786a76f9eaf74f9ec78db2be.tar.gz
xen-57fbe22719d3bee4786a76f9eaf74f9ec78db2be.tar.bz2
xen-57fbe22719d3bee4786a76f9eaf74f9ec78db2be.zip
bitkeeper revision 1.1662.1.2 (42a0829aeBxkGIvlJ51XXxy6MTXerA)
XendDomainInfo.py, XendDomain.py: Make create, recreate and restore XendDomainInfo class methods. XendDomain.py: Still need XendDomainInfo. PrettyPrint.py: Fix typo. xc.c: Cleanup whitespace. Signed-off-by: Mike Wray <mike.wray@hp.com> Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Diffstat (limited to 'tools')
-rw-r--r--tools/python/xen/lowlevel/xc/xc.c3
-rw-r--r--tools/python/xen/xend/PrettyPrint.py2
-rw-r--r--tools/python/xen/xend/XendDomain.py9
-rw-r--r--tools/python/xen/xend/XendDomainInfo.py133
4 files changed, 86 insertions, 61 deletions
diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c
index 03f7468d1a..5b548c77e4 100644
--- a/tools/python/xen/lowlevel/xc/xc.c
+++ b/tools/python/xen/lowlevel/xc/xc.c
@@ -833,6 +833,7 @@ static PyMethodDef pyxc_methods[] = {
0, "\n"
"Query the xc control interface file descriptor.\n\n"
"Returns: [int] file descriptor\n" },
+
{ "domain_create",
(PyCFunction)pyxc_domain_create,
METH_VARARGS | METH_KEYWORDS, "\n"
@@ -844,7 +845,7 @@ static PyMethodDef pyxc_methods[] = {
(PyCFunction)pyxc_domain_dumpcore,
METH_VARARGS | METH_KEYWORDS, "\n"
"Dump core of a domain.\n"
- " dom [int]: Identifier of domain to dump core of.\n\n"
+ " dom [int]: Identifier of domain to dump core of.\n"
" corefile [string]: Name of corefile to be created.\n\n"
"Returns: [int] 0 on success; -1 on error.\n" },
diff --git a/tools/python/xen/xend/PrettyPrint.py b/tools/python/xen/xend/PrettyPrint.py
index 8c6d690856..a57a3c6b52 100644
--- a/tools/python/xen/xend/PrettyPrint.py
+++ b/tools/python/xen/xend/PrettyPrint.py
@@ -285,7 +285,7 @@ def prettyprint(sxpr, out=sys.stdout, width=80):
sxp.show(sxpr, out=out)
print >> out
-def prettyprintstring(sxp, width=80):
+def prettyprintstring(sxpr, width=80):
"""Prettyprint an SXP form to a string.
sxpr s-expression
diff --git a/tools/python/xen/xend/XendDomain.py b/tools/python/xen/xend/XendDomain.py
index 3cc2346064..60474c1c25 100644
--- a/tools/python/xen/xend/XendDomain.py
+++ b/tools/python/xen/xend/XendDomain.py
@@ -133,7 +133,7 @@ class XendDomain:
@param info: domain info from xen
@return: domain
"""
- dominfo = XendDomainInfo.vm_recreate(savedinfo, info)
+ dominfo = XendDomainInfo.recreate(savedinfo, info)
self.domains[dominfo.id] = dominfo
return dominfo
@@ -282,8 +282,7 @@ class XendDomain:
@param config: configuration
@return: domain
"""
- dominfo = XendDomainInfo.vm_create(config)
- self._add_domain(dominfo)
+ dominfo = XendDomainInfo.create(config)
return dominfo
def domain_restart(self, dominfo):
@@ -316,7 +315,7 @@ class XendDomain:
@param vmconfig: vm configuration
"""
config = sxp.child_value(vmconfig, 'config')
- dominfo = XendDomainInfo.vm_restore(config)
+ dominfo = XendDomainInfo.restore(config)
self._add_domain(dominfo)
return dominfo
@@ -352,7 +351,7 @@ class XendDomain:
info = self.xen_domain(id)
if info:
log.info("Creating entry for unknown domain: id=%s", name)
- dominfo = XendDomainInfo.vm_recreate(None, info)
+ dominfo = XendDomainInfo.recreate(None, info, unknown=True)
self._add_domain(dominfo)
except Exception, ex:
log.exception("Error creating domain info: id=%s", name)
diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py
index 05286fae20..3906c0e657 100644
--- a/tools/python/xen/xend/XendDomainInfo.py
+++ b/tools/python/xen/xend/XendDomainInfo.py
@@ -144,61 +144,7 @@ def add_device_handler(name, type):
def get_device_handler(name):
return device_handlers[name]
-
-
-def vm_create(config):
- """Create a VM from a configuration.
- If a vm has been partially created and there is an error it
- is destroyed.
-
- @param config configuration
- @raise: VmError for invalid configuration
- """
- vm = XendDomainInfo()
- vm.construct(config)
- return vm
-
-def vm_restore(config):
- """Create a domain and a VM object to do a restore.
-
- @param config: domain configuration
- """
- vm = XendDomainInfo()
- dom = xc.domain_create()
- vm.dom_construct(dom, config)
- return vm
-def vm_recreate(savedinfo, info):
- """Create the VM object for an existing domain.
-
- @param savedinfo: saved info from the domain DB
- @type savedinfo: sxpr
- @param info: domain info from xc
- @type info: xc domain dict
- """
- log.debug('savedinfo=' + prettyprintstring(savedinfo))
- log.debug('info=' + str(info))
- vm = XendDomainInfo()
- vm.recreate = True
- vm.savedinfo = savedinfo
- vm.setdom(info['dom'])
- vm.memory = info['mem_kb']/1024
- start_time = sxp.child_value(savedinfo, 'start_time')
- if start_time is not None:
- vm.start_time = float(start_time)
- vm.restart_state = sxp.child_value(savedinfo, 'restart_state')
- vm.restart_count = int(sxp.child_value(savedinfo, 'restart_count', 0))
- restart_time = sxp.child_value(savedinfo, 'restart_time')
- if restart_time is not None:
- vm.restart_time = float(restart_time)
- config = sxp.child_value(savedinfo, 'config')
- if config:
- vm.construct(config)
- else:
- vm.name = sxp.child_value(savedinfo, 'name', "Domain-%d" % info['dom'])
- vm.recreate = False
- vm.savedinfo = None
- return vm
def dom_get(dom):
"""Get info from xen for an existing domain.
@@ -218,9 +164,88 @@ class XendDomainInfo:
"""
MINIMUM_RESTART_TIME = 20
+ def _create(cls):
+ """Create a vm object.
+
+ @return vm
+ """
+ vm = cls()
+ return vm
+
+ _create = classmethod(_create)
+
+ def create(cls, config):
+ """Create a VM from a configuration.
+ If a vm has been partially created and there is an error it
+ is destroyed.
+
+ @param config configuration
+ @raise: VmError for invalid configuration
+ """
+ vm = cls._create()
+ vm.construct(config)
+ return vm
+
+ create = classmethod(create)
+
+ def recreate(cls, savedinfo, info, unknown=False):
+ """Create the VM object for an existing domain.
+
+ @param savedinfo: saved info from the domain DB
+ @param info: domain info from xc
+ @type info: xc domain dict
+ """
+ if unknown:
+ vm = cls._create()
+ else:
+ vm = cls()
+
+ log.debug('savedinfo=' + prettyprintstring(savedinfo))
+ log.debug('info=' + str(info))
+
+ vm.recreate = True
+ vm.savedinfo = savedinfo
+ vm.setdom(info['dom'])
+ vm.memory = info['mem_kb']/1024
+
+ start_time = sxp.child_value(savedinfo, 'start_time')
+ if start_time is not None:
+ vm.start_time = float(start_time)
+ vm.restart_state = sxp.child_value(savedinfo, 'restart_state')
+ vm.restart_count = int(sxp.child_value(savedinfo, 'restart_count', 0))
+ restart_time = sxp.child_value(savedinfo, 'restart_time')
+ if restart_time is not None:
+ vm.restart_time = float(restart_time)
+ config = sxp.child_value(savedinfo, 'config')
+
+ if config:
+ vm.construct(config)
+ else:
+ vm.name = sxp.child_value(savedinfo, 'name', "Domain-%d" % info['dom'])
+ vm.recreate = False
+ vm.savedinfo = None
+
+ return vm
+
+ recreate = classmethod(recreate)
+
+ def restore(cls, config):
+ """Create a domain and a VM object to do a restore.
+
+ @param config: domain configuration
+ """
+ vm = cls._create()
+ dom = xc.domain_create()
+ vm.setdom(dom)
+ vm.dom_construct(dom, config)
+ return vm
+
+ restore = classmethod(restore)
+
def __init__(self):
self.recreate = 0
self.restore = 0
+
self.config = None
self.id = None
self.dom = None