mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
Add a function for creating a domain from an existing XendConfig, and use that
on reboot, rather than writing out sxp and reparsing. Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
1 parent
0317e15cfc
commit
a72da7c894
2 files changed
+45
-9
No files matched your search
@@ -869,6 +869,26 @@ class XendDomain:
|
||||
self.domains_lock.release()
|
||||
|
||||
|
||||
def domain_create_from_dict(self, config_dict):
|
||||
"""Create a domain from a configuration dictionary.
|
||||
|
||||
@param config_dict: configuration
|
||||
@rtype: XendDomainInfo
|
||||
"""
|
||||
self.domains_lock.acquire()
|
||||
try:
|
||||
self._refresh()
|
||||
|
||||
dominfo = XendDomainInfo.create_from_dict(config_dict)
|
||||
self._add_domain(dominfo)
|
||||
self.domain_sched_credit_set(dominfo.getDomid(),
|
||||
dominfo.getWeight(),
|
||||
dominfo.getCap())
|
||||
return dominfo
|
||||
finally:
|
||||
self.domains_lock.release()
|
||||
|
||||
|
||||
def domain_new(self, config):
|
||||
"""Create a domain from a configuration but do not start it.
|
||||
|
||||
|
||||
@@ -81,13 +81,12 @@ log = logging.getLogger("xend.XendDomainInfo")
|
||||
|
||||
def create(config):
|
||||
"""Creates and start a VM using the supplied configuration.
|
||||
(called from XMLRPCServer directly)
|
||||
|
||||
@param config: A configuration object involving lists of tuples.
|
||||
@type config: list of lists, eg ['vm', ['image', 'xen.gz']]
|
||||
|
||||
@rtype: XendDomainInfo
|
||||
@return: A up and running XendDomainInfo instance
|
||||
@return: An up and running XendDomainInfo instance
|
||||
@raise VmError: Invalid configuration or failure to start.
|
||||
"""
|
||||
|
||||
@@ -102,6 +101,28 @@ def create(config):
|
||||
|
||||
return vm
|
||||
|
||||
def create_from_dict(config_dict):
|
||||
"""Creates and start a VM using the supplied configuration.
|
||||
|
||||
@param config_dict: An configuration dictionary.
|
||||
|
||||
@rtype: XendDomainInfo
|
||||
@return: An up and running XendDomainInfo instance
|
||||
@raise VmError: Invalid configuration or failure to start.
|
||||
"""
|
||||
|
||||
log.debug("XendDomainInfo.create_from_dict(%s)",
|
||||
scrub_password(config_dict))
|
||||
vm = XendDomainInfo(XendConfig.XendConfig(xapi = config_dict))
|
||||
try:
|
||||
vm.start()
|
||||
except:
|
||||
log.exception('Domain construction failed')
|
||||
vm.destroy()
|
||||
raise
|
||||
|
||||
return vm
|
||||
|
||||
def recreate(info, priv):
|
||||
"""Create the VM object for an existing domain. The domain must not
|
||||
be dying, as the paths in the store should already have been removed,
|
||||
@@ -1051,12 +1072,6 @@ class XendDomainInfo:
|
||||
"""
|
||||
from xen.xend import XendDomain
|
||||
|
||||
config = self.sxpr()
|
||||
|
||||
if self._infoIsSet('cpus') and len(self.info['cpus']) != 0:
|
||||
config.append(['cpus', reduce(lambda x, y: str(x) + "," + str(y),
|
||||
self.info['cpus'])])
|
||||
|
||||
if self._readVm(RESTART_IN_PROGRESS):
|
||||
log.error('Xend failed during restart of domain %s. '
|
||||
'Refusing to restart to avoid loops.',
|
||||
@@ -1097,7 +1112,8 @@ class XendDomainInfo:
|
||||
|
||||
new_dom = None
|
||||
try:
|
||||
new_dom = XendDomain.instance().domain_create(config)
|
||||
new_dom = XendDomain.instance().domain_create_from_dict(
|
||||
self.info)
|
||||
new_dom.unpause()
|
||||
rst_cnt = self._readVm('xend/restart_count')
|
||||
rst_cnt = int(rst_cnt) + 1
|
||||
|
||||