ia64/xen-unstable

changeset 6940:b75771a12f79

Added getVCpuCount to XendDomainInfo and use that and getName, getDomain,
getTargetMemory inside image.py to decouple the latter from the internals of
the former. Move the definition of xc inside image.py to please pylint.

Signed-off-by: Ewan Mellor<ewan@xensource.com>
author emellor@ewan
date Sat Sep 17 17:34:58 2005 +0100 (2005-09-17)
parents adbf85204d29
children 8462eff90433
files tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/image.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Sat Sep 17 16:11:49 2005 +0100
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Sat Sep 17 17:34:58 2005 +0100
     1.3 @@ -334,6 +334,9 @@ class XendDomainInfo:
     1.4      def getName(self):
     1.5          return self.name
     1.6  
     1.7 +    def getVCpuCount(self):
     1.8 +        return self.vcpus
     1.9 +
    1.10      def getSsidref(self):
    1.11          return self.ssidref
    1.12  
     2.1 --- a/tools/python/xen/xend/image.py	Sat Sep 17 16:11:49 2005 +0100
     2.2 +++ b/tools/python/xen/xend/image.py	Sat Sep 17 17:34:58 2005 +0100
     2.3 @@ -18,7 +18,7 @@
     2.4  import os, string
     2.5  import re
     2.6  
     2.7 -import xen.lowlevel.xc; xc = xen.lowlevel.xc.new()
     2.8 +import xen.lowlevel.xc
     2.9  from xen.xend import sxp
    2.10  from xen.xend.XendError import VmError
    2.11  from xen.xend.XendLogging import log
    2.12 @@ -27,6 +27,10 @@ from xen.xend.xenstore.xstransact import
    2.13  
    2.14  from xen.xend.server import channel
    2.15  
    2.16 +
    2.17 +xc = xen.lowlevel.xc.new()
    2.18 +
    2.19 +
    2.20  MAX_GUEST_CMDLINE = 1024
    2.21  
    2.22  class ImageHandler:
    2.23 @@ -155,7 +159,8 @@ class ImageHandler:
    2.24                  self.unlink(self.kernel)
    2.25                  self.unlink(self.ramdisk)
    2.26              if dom <= 0:
    2.27 -                raise VmError('Creating domain failed: name=%s' % self.vm.name)
    2.28 +                raise VmError('Creating domain failed: name=%s' %
    2.29 +                              self.vm.getName())
    2.30          log.debug("initDomain: cpu=%d mem_kb=%d ssidref=%d dom=%d", cpu, mem_kb, ssidref, dom)
    2.31          xc.domain_setcpuweight(dom, cpu_weight)
    2.32          xc.domain_setmaxmem(dom, mem_kb)
    2.33 @@ -190,14 +195,15 @@ class ImageHandler:
    2.34          if self.ramdisk and not os.path.isfile(self.ramdisk):
    2.35              raise VmError('Kernel ramdisk does not exist: %s' % self.ramdisk)
    2.36          if len(self.cmdline) >= MAX_GUEST_CMDLINE:
    2.37 -            log.warning('kernel cmdline too long, domain %d', self.vm.domid)
    2.38 +            log.warning('kernel cmdline too long, domain %d',
    2.39 +                        self.vm.getDomain())
    2.40          
    2.41          log.info("buildDomain os=%s dom=%d vcpus=%d", self.ostype,
    2.42 -                 self.vm.domid, self.vm.vcpus)
    2.43 +                 self.vm.getDomain(), self.vm.getVCpuCount())
    2.44          err = self.buildDomain()
    2.45          if err != 0:
    2.46              raise VmError('Building domain failed: ostype=%s dom=%d err=%d'
    2.47 -                          % (self.ostype, self.vm.domid, err))
    2.48 +                          % (self.ostype, self.vm.getDomain(), err))
    2.49  
    2.50      def getDomainMemory(self, mem_mb):
    2.51          """Memory (in KB) the domain will need for mem_mb (in MB)."""
    2.52 @@ -237,23 +243,23 @@ class LinuxImageHandler(ImageHandler):
    2.53          else:
    2.54              console_evtchn = 0
    2.55  
    2.56 -        log.debug("dom            = %d", self.vm.domid)
    2.57 +        log.debug("dom            = %d", self.vm.getDomain())
    2.58          log.debug("image          = %s", self.kernel)
    2.59          log.debug("store_evtchn   = %d", store_evtchn)
    2.60          log.debug("console_evtchn = %d", console_evtchn)
    2.61          log.debug("cmdline        = %s", self.cmdline)
    2.62          log.debug("ramdisk        = %s", self.ramdisk)
    2.63          log.debug("flags          = %d", self.flags)
    2.64 -        log.debug("vcpus          = %d", self.vm.vcpus)
    2.65 +        log.debug("vcpus          = %d", self.vm.getVCpuCount())
    2.66  
    2.67 -        ret = xc.linux_build(dom            = self.vm.domid,
    2.68 +        ret = xc.linux_build(dom            = self.vm.getDomain(),
    2.69                               image          = self.kernel,
    2.70                               store_evtchn   = store_evtchn,
    2.71                               console_evtchn = console_evtchn,
    2.72                               cmdline        = self.cmdline,
    2.73                               ramdisk        = self.ramdisk,
    2.74                               flags          = self.flags,
    2.75 -                             vcpus          = self.vm.vcpus)
    2.76 +                             vcpus          = self.vm.getVCpuCount())
    2.77          if isinstance(ret, dict):
    2.78              self.set_vminfo(ret)
    2.79              return 0
    2.80 @@ -297,22 +303,22 @@ class VmxImageHandler(ImageHandler):
    2.81  
    2.82      def buildDomain(self):
    2.83          # Create an event channel
    2.84 -        self.device_channel = channel.eventChannel(0, self.vm.domid)
    2.85 +        self.device_channel = channel.eventChannel(0, self.vm.getDomain())
    2.86          log.info("VMX device model port: %d", self.device_channel.port2)
    2.87          if self.vm.store_channel:
    2.88              store_evtchn = self.vm.store_channel.port2
    2.89          else:
    2.90              store_evtchn = 0
    2.91 -        ret = xc.vmx_build(dom            = self.vm.domid,
    2.92 +        ret = xc.vmx_build(dom            = self.vm.getDomain(),
    2.93                             image          = self.kernel,
    2.94                             control_evtchn = self.device_channel.port2,
    2.95                             store_evtchn   = store_evtchn,
    2.96 -                           memsize        = self.vm.memory,
    2.97 +                           memsize        = self.vm.getTargetMemory(),
    2.98                             memmap         = self.memmap_value,
    2.99                             cmdline        = self.cmdline,
   2.100                             ramdisk        = self.ramdisk,
   2.101                             flags          = self.flags,
   2.102 -                           vcpus          = self.vm.vcpus)
   2.103 +                           vcpus          = self.vm.getVCpuCount())
   2.104          if isinstance(ret, dict):
   2.105              self.set_vminfo(ret)
   2.106              return 0
   2.107 @@ -391,7 +397,7 @@ class VmxImageHandler(ImageHandler):
   2.108          elif vnc:
   2.109              ret = ret + ['-vnc', '-k', 'en-us']
   2.110          if vnc:
   2.111 -            vncport = int(self.vm.domid) + 5900
   2.112 +            vncport = int(self.vm.getDomain()) + 5900
   2.113              ret = ret + ['-vncport', '%d' % vncport]
   2.114          return ret
   2.115  
   2.116 @@ -405,9 +411,9 @@ class VmxImageHandler(ImageHandler):
   2.117          vnc = self.vncParams()
   2.118          if len(vnc):
   2.119              args = args + vnc
   2.120 -        args = args + ([ "-d",  "%d" % self.vm.domid,
   2.121 +        args = args + ([ "-d",  "%d" % self.vm.getDomain(),
   2.122                    "-p", "%d" % self.device_channel.port1,
   2.123 -                  "-m", "%s" % self.vm.memory ])
   2.124 +                  "-m", "%s" % self.vm.getTargetMemory() ])
   2.125          args = args + self.dmargs
   2.126          env = dict(os.environ)
   2.127          env['DISPLAY'] = self.display