mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 02:30:03 +01:00
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>
This commit is contained in:
1 parent
d057c5ef08
commit
57fbe22719
4 files changed
+86
-61
No files matched your search
@@ -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" },
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||