[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] Add a function for creating a domain from an existing XendConfig, and use that



# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Date 1166722772 0
# Node ID 63bd462b1f457354459c6865a0d1659b53904e95
# Parent  2ae2204bbef30d05d62ea33a8febc3a25139659b
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@xxxxxxxxxxxxx>
---
 tools/python/xen/xend/XendDomain.py     |   20 ++++++++++++++++++
 tools/python/xen/xend/XendDomainInfo.py |   34 +++++++++++++++++++++++---------
 2 files changed, 45 insertions(+), 9 deletions(-)

diff -r 2ae2204bbef3 -r 63bd462b1f45 tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py       Thu Dec 21 17:38:02 2006 +0000
+++ b/tools/python/xen/xend/XendDomain.py       Thu Dec 21 17:39:32 2006 +0000
@@ -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.
         
diff -r 2ae2204bbef3 -r 63bd462b1f45 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Thu Dec 21 17:38:02 2006 +0000
+++ b/tools/python/xen/xend/XendDomainInfo.py   Thu Dec 21 17:39:32 2006 +0000
@@ -81,18 +81,39 @@ log = logging.getLogger("xend.XendDomain
 
 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.
     """
 
     log.debug("XendDomainInfo.create(%s)", scrub_password(config))
     vm = XendDomainInfo(XendConfig.XendConfig(sxp_obj = config))
+    try:
+        vm.start()
+    except:
+        log.exception('Domain construction failed')
+        vm.destroy()
+        raise
+
+    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:
@@ -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

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.