ia64/xen-unstable

changeset 5306:9672db054b6d

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>
author cl349@firebug.cl.cam.ac.uk
date Fri Jun 03 16:17:30 2005 +0000 (2005-06-03)
parents 6946d70596e8
children 46ed74bb2921
files tools/python/xen/lowlevel/xc/xc.c tools/python/xen/xend/PrettyPrint.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Fri Jun 03 15:03:33 2005 +0000
     1.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Fri Jun 03 16:17:30 2005 +0000
     1.3 @@ -833,6 +833,7 @@ static PyMethodDef pyxc_methods[] = {
     1.4        0, "\n"
     1.5        "Query the xc control interface file descriptor.\n\n"
     1.6        "Returns: [int] file descriptor\n" },
     1.7 +
     1.8      { "domain_create", 
     1.9        (PyCFunction)pyxc_domain_create, 
    1.10        METH_VARARGS | METH_KEYWORDS, "\n"
    1.11 @@ -844,7 +845,7 @@ static PyMethodDef pyxc_methods[] = {
    1.12        (PyCFunction)pyxc_domain_dumpcore, 
    1.13        METH_VARARGS | METH_KEYWORDS, "\n"
    1.14        "Dump core of a domain.\n"
    1.15 -      " dom [int]: Identifier of domain to dump core of.\n\n"
    1.16 +      " dom [int]: Identifier of domain to dump core of.\n"
    1.17        " corefile [string]: Name of corefile to be created.\n\n"
    1.18        "Returns: [int] 0 on success; -1 on error.\n" },
    1.19  
     2.1 --- a/tools/python/xen/xend/PrettyPrint.py	Fri Jun 03 15:03:33 2005 +0000
     2.2 +++ b/tools/python/xen/xend/PrettyPrint.py	Fri Jun 03 16:17:30 2005 +0000
     2.3 @@ -285,7 +285,7 @@ def prettyprint(sxpr, out=sys.stdout, wi
     2.4          sxp.show(sxpr, out=out)
     2.5      print >> out
     2.6  
     2.7 -def prettyprintstring(sxp, width=80):
     2.8 +def prettyprintstring(sxpr, width=80):
     2.9      """Prettyprint an SXP form to a string.
    2.10  
    2.11      sxpr	s-expression
     3.1 --- a/tools/python/xen/xend/XendDomain.py	Fri Jun 03 15:03:33 2005 +0000
     3.2 +++ b/tools/python/xen/xend/XendDomain.py	Fri Jun 03 16:17:30 2005 +0000
     3.3 @@ -133,7 +133,7 @@ class XendDomain:
     3.4          @param info:      domain info from xen
     3.5          @return: domain
     3.6          """
     3.7 -        dominfo = XendDomainInfo.vm_recreate(savedinfo, info)
     3.8 +        dominfo = XendDomainInfo.recreate(savedinfo, info)
     3.9          self.domains[dominfo.id] = dominfo
    3.10          return dominfo
    3.11  
    3.12 @@ -282,8 +282,7 @@ class XendDomain:
    3.13          @param config: configuration
    3.14          @return: domain
    3.15          """
    3.16 -        dominfo = XendDomainInfo.vm_create(config)
    3.17 -        self._add_domain(dominfo)
    3.18 +        dominfo = XendDomainInfo.create(config)
    3.19          return dominfo
    3.20  
    3.21      def domain_restart(self, dominfo):
    3.22 @@ -316,7 +315,7 @@ class XendDomain:
    3.23          @param vmconfig: vm configuration
    3.24          """
    3.25          config = sxp.child_value(vmconfig, 'config')
    3.26 -        dominfo = XendDomainInfo.vm_restore(config)
    3.27 +        dominfo = XendDomainInfo.restore(config)
    3.28          self._add_domain(dominfo)
    3.29          return dominfo
    3.30      
    3.31 @@ -352,7 +351,7 @@ class XendDomain:
    3.32                  info = self.xen_domain(id)
    3.33                  if info:
    3.34                      log.info("Creating entry for unknown domain: id=%s", name)
    3.35 -                    dominfo = XendDomainInfo.vm_recreate(None, info)
    3.36 +                    dominfo = XendDomainInfo.recreate(None, info, unknown=True)
    3.37                      self._add_domain(dominfo)
    3.38              except Exception, ex:
    3.39                  log.exception("Error creating domain info: id=%s", name)
     4.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Fri Jun 03 15:03:33 2005 +0000
     4.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Fri Jun 03 16:17:30 2005 +0000
     4.3 @@ -144,61 +144,7 @@ def add_device_handler(name, type):
     4.4  
     4.5  def get_device_handler(name):
     4.6      return device_handlers[name]
     4.7 -    
     4.8  
     4.9 -def vm_create(config):
    4.10 -    """Create a VM from a configuration.
    4.11 -    If a vm has been partially created and there is an error it
    4.12 -    is destroyed.
    4.13 -
    4.14 -    @param config    configuration
    4.15 -    @raise: VmError for invalid configuration
    4.16 -    """
    4.17 -    vm = XendDomainInfo()
    4.18 -    vm.construct(config)
    4.19 -    return vm
    4.20 -
    4.21 -def vm_restore(config):
    4.22 -    """Create a domain and a VM object to do a restore.
    4.23 -
    4.24 -    @param config:    domain configuration
    4.25 -    """
    4.26 -    vm = XendDomainInfo()
    4.27 -    dom = xc.domain_create()
    4.28 -    vm.dom_construct(dom, config)
    4.29 -    return vm
    4.30 -
    4.31 -def vm_recreate(savedinfo, info):
    4.32 -    """Create the VM object for an existing domain.
    4.33 -
    4.34 -    @param savedinfo: saved info from the domain DB
    4.35 -    @type  savedinfo: sxpr
    4.36 -    @param info:      domain info from xc
    4.37 -    @type  info:      xc domain dict
    4.38 -    """
    4.39 -    log.debug('savedinfo=' + prettyprintstring(savedinfo))
    4.40 -    log.debug('info=' + str(info))
    4.41 -    vm = XendDomainInfo()
    4.42 -    vm.recreate = True
    4.43 -    vm.savedinfo = savedinfo
    4.44 -    vm.setdom(info['dom'])
    4.45 -    vm.memory = info['mem_kb']/1024
    4.46 -    start_time = sxp.child_value(savedinfo, 'start_time')
    4.47 -    if start_time is not None:
    4.48 -        vm.start_time = float(start_time)
    4.49 -    vm.restart_state = sxp.child_value(savedinfo, 'restart_state')
    4.50 -    vm.restart_count = int(sxp.child_value(savedinfo, 'restart_count', 0))
    4.51 -    restart_time = sxp.child_value(savedinfo, 'restart_time')
    4.52 -    if restart_time is not None:
    4.53 -        vm.restart_time = float(restart_time)
    4.54 -    config = sxp.child_value(savedinfo, 'config')
    4.55 -    if config:
    4.56 -        vm.construct(config)
    4.57 -    else:
    4.58 -        vm.name = sxp.child_value(savedinfo, 'name', "Domain-%d" % info['dom'])
    4.59 -    vm.recreate = False
    4.60 -    vm.savedinfo = None
    4.61 -    return vm
    4.62  
    4.63  def dom_get(dom):
    4.64      """Get info from xen for an existing domain.
    4.65 @@ -218,9 +164,88 @@ class XendDomainInfo:
    4.66      """
    4.67      MINIMUM_RESTART_TIME = 20
    4.68  
    4.69 +    def _create(cls):
    4.70 +        """Create a vm object.
    4.71 +
    4.72 +        @return vm
    4.73 +        """
    4.74 +        vm = cls()
    4.75 +        return vm
    4.76 +
    4.77 +    _create = classmethod(_create)
    4.78 +
    4.79 +    def create(cls, config):
    4.80 +        """Create a VM from a configuration.
    4.81 +        If a vm has been partially created and there is an error it
    4.82 +        is destroyed.
    4.83 +
    4.84 +        @param config    configuration
    4.85 +        @raise: VmError for invalid configuration
    4.86 +        """
    4.87 +        vm = cls._create()
    4.88 +        vm.construct(config)
    4.89 +        return vm
    4.90 +
    4.91 +    create = classmethod(create)
    4.92 +
    4.93 +    def recreate(cls, savedinfo, info, unknown=False):
    4.94 +        """Create the VM object for an existing domain.
    4.95 +
    4.96 +        @param savedinfo: saved info from the domain DB
    4.97 +        @param info:      domain info from xc
    4.98 +        @type  info:      xc domain dict
    4.99 +        """
   4.100 +        if unknown:
   4.101 +            vm = cls._create()
   4.102 +        else:
   4.103 +            vm = cls()
   4.104 +
   4.105 +        log.debug('savedinfo=' + prettyprintstring(savedinfo))
   4.106 +        log.debug('info=' + str(info))
   4.107 +
   4.108 +        vm.recreate = True
   4.109 +        vm.savedinfo = savedinfo
   4.110 +        vm.setdom(info['dom'])
   4.111 +        vm.memory = info['mem_kb']/1024
   4.112 +
   4.113 +        start_time = sxp.child_value(savedinfo, 'start_time')
   4.114 +        if start_time is not None:
   4.115 +            vm.start_time = float(start_time)
   4.116 +        vm.restart_state = sxp.child_value(savedinfo, 'restart_state')
   4.117 +        vm.restart_count = int(sxp.child_value(savedinfo, 'restart_count', 0))
   4.118 +        restart_time = sxp.child_value(savedinfo, 'restart_time')
   4.119 +        if restart_time is not None:
   4.120 +            vm.restart_time = float(restart_time)
   4.121 +        config = sxp.child_value(savedinfo, 'config')
   4.122 +
   4.123 +        if config:
   4.124 +            vm.construct(config)
   4.125 +        else:
   4.126 +            vm.name = sxp.child_value(savedinfo, 'name', "Domain-%d" % info['dom'])
   4.127 +        vm.recreate = False
   4.128 +        vm.savedinfo = None
   4.129 +
   4.130 +        return vm
   4.131 +
   4.132 +    recreate = classmethod(recreate)
   4.133 +
   4.134 +    def restore(cls, config):
   4.135 +        """Create a domain and a VM object to do a restore.
   4.136 +
   4.137 +        @param config:    domain configuration
   4.138 +        """
   4.139 +        vm = cls._create()
   4.140 +        dom = xc.domain_create()
   4.141 +        vm.setdom(dom)
   4.142 +        vm.dom_construct(dom, config)
   4.143 +        return vm
   4.144 +
   4.145 +    restore = classmethod(restore)
   4.146 +
   4.147      def __init__(self):
   4.148          self.recreate = 0
   4.149          self.restore = 0
   4.150 +        
   4.151          self.config = None
   4.152          self.id = None
   4.153          self.dom = None