ia64/xen-unstable

changeset 5479:ebef9f2fb49f

bitkeeper revision 1.1713.3.6 (42b2dc47kgG53fAZb70R3lHX96n7dw)

xsobj.py:
Handle attribute lookups for non-existing attributes.
Use setAttr consistently.
Fix access to data in convertFromDB.
console.py:
Cleanup whitespace.
channel.py:
Cleanup saveToDB.
blkif.py:
Save dev_handle in DB.
image.py:
Cleanup exportToDB.
XendDomainInfo.py:
Cleanup {save,export}toDB use.
Cleanup whitespace.
Change id type to be int.
Output store_mfn in sxpr.
Use id variable name consistently for domain id's.
Add eventChannel comment.
On restore, the uuid must be known.
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 17 14:20:55 2005 +0000 (2005-06-17)
parents dda0c275d413
children 7d4dd8aae709
files tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/image.py tools/python/xen/xend/server/blkif.py tools/python/xen/xend/server/channel.py tools/python/xen/xend/server/console.py tools/python/xen/xend/xenstore/xsobj.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Fri Jun 17 10:24:34 2005 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Fri Jun 17 14:20:55 2005 +0000
     1.3 @@ -157,7 +157,7 @@ class XendDomainInfo:
     1.4          db = parentdb.addChild(uuid)
     1.5          vm = cls(db)
     1.6          vm.construct(config)
     1.7 -        vm.saveDB(sync=True)
     1.8 +        vm.saveToDB(sync=True)
     1.9          return vm
    1.10  
    1.11      create = classmethod(create)
    1.12 @@ -193,7 +193,7 @@ class XendDomainInfo:
    1.13  
    1.14      recreate = classmethod(recreate)
    1.15  
    1.16 -    def restore(cls, parentdb, config, uuid=None):
    1.17 +    def restore(cls, parentdb, config, uuid):
    1.18          """Create a domain and a VM object to do a restore.
    1.19  
    1.20          @param parentdb:  parent db
    1.21 @@ -202,16 +202,20 @@ class XendDomainInfo:
    1.22          """
    1.23          db = parentdb.addChild(uuid)
    1.24          vm = cls(db)
    1.25 -        dom = xc.domain_create()
    1.26 -        vm.setdom(dom)
    1.27 -        vm.dom_construct(vm.id, config)
    1.28 -        vm.saveDB(sync=True)
    1.29 +        id = xc.domain_create()
    1.30 +        vm.setdom(id)
    1.31 +        try:
    1.32 +            vm.restore = True
    1.33 +            vm.construct(config)
    1.34 +        finally:
    1.35 +            vm.restore = False
    1.36 +        vm.exportToDB(save=True, sync=True)
    1.37          return vm
    1.38  
    1.39      restore = classmethod(restore)
    1.40  
    1.41      __exports__ = [
    1.42 -        DBVar('id',            ty='str'),
    1.43 +        DBVar('id',            ty='int'),
    1.44          DBVar('name',          ty='str'),
    1.45          DBVar('uuid',          ty='str'),
    1.46          DBVar('config',        ty='sxpr'),
    1.47 @@ -267,14 +271,17 @@ class XendDomainInfo:
    1.48      def setDB(self, db):
    1.49          self.db = db
    1.50  
    1.51 -    def saveDB(self, save=False, sync=False):
    1.52 +    def saveToDB(self, save=False, sync=False):
    1.53          self.db.saveDB(save=save, sync=sync)
    1.54  
    1.55      def exportToDB(self, save=False, sync=False):
    1.56          if self.channel:
    1.57 -            self.channel.saveToDB(self.db.addChild("channel"))
    1.58 +            self.channel.saveToDB(self.db.addChild("channel"), save=save)
    1.59          if self.store_channel:
    1.60 -            self.store_channel.saveToDB(self.db.addChild("store_channel"))
    1.61 +            self.store_channel.saveToDB(self.db.addChild("store_channel"),
    1.62 +                                        save=save)
    1.63 +        if self.image:
    1.64 +            self.image.exportToDB(save=save, sync=sync)
    1.65          self.db.exportToDB(self, fields=self.__exports__, save=save, sync=sync)
    1.66  
    1.67      def importFromDB(self):
    1.68 @@ -316,7 +323,7 @@ class XendDomainInfo:
    1.69              self.state = state
    1.70              self.state_updated.notifyAll()
    1.71          self.state_updated.release()
    1.72 -        self.saveDB()
    1.73 +        self.saveToDB()
    1.74  
    1.75      def state_wait(self, state):
    1.76          self.state_updated.acquire()
    1.77 @@ -325,14 +332,14 @@ class XendDomainInfo:
    1.78          self.state_updated.release()
    1.79  
    1.80      def __str__(self):
    1.81 -        s = "domain"
    1.82 +        s = "<domain"
    1.83          s += " id=" + str(self.id)
    1.84          s += " name=" + self.name
    1.85          s += " memory=" + str(self.memory)
    1.86          console = self.getConsole()
    1.87          if console:
    1.88              s += " console=" + str(console.console_port)
    1.89 -        s += ""
    1.90 +        s += ">"
    1.91          return s
    1.92  
    1.93      __repr__ = __str__
    1.94 @@ -422,15 +429,19 @@ class XendDomainInfo:
    1.95              sxpr.append(self.channel.sxpr())
    1.96          if self.store_channel:
    1.97              sxpr.append(self.store_channel.sxpr())
    1.98 +        if self.store_mfn:
    1.99 +            sxpr.append(['store_mfn', self.store_mfn])
   1.100          console = self.getConsole()
   1.101          if console:
   1.102              sxpr.append(console.sxpr())
   1.103 +
   1.104          if self.restart_count:
   1.105              sxpr.append(['restart_count', self.restart_count])
   1.106          if self.restart_state:
   1.107              sxpr.append(['restart_state', self.restart_state])
   1.108          if self.restart_time:
   1.109              sxpr.append(['restart_time', str(self.restart_time)])
   1.110 +
   1.111          devs = self.sxpr_devices()
   1.112          if devs:
   1.113              sxpr.append(devs)
   1.114 @@ -546,7 +557,7 @@ class XendDomainInfo:
   1.115          """
   1.116          self.create_channel()
   1.117          self.image.createImage()
   1.118 -        self.image.exportToDB()
   1.119 +        self.exportToDB()
   1.120          #if self.store_channel:
   1.121          #    self.db.introduceDomain(self.id,
   1.122          #                            self.store_mfn,
   1.123 @@ -558,7 +569,7 @@ class XendDomainInfo:
   1.124          if self.dom_get(self.id):
   1.125              return
   1.126          self.id = None
   1.127 -        self.saveDB(sync=True)
   1.128 +        self.saveToDB(sync=True)
   1.129          try:
   1.130              # Todo: eventually will have to wait for devices to signal
   1.131              # destruction before can delete the db.
   1.132 @@ -614,7 +625,7 @@ class XendDomainInfo:
   1.133          """
   1.134          self.cleanup()
   1.135          self.destroy_domain()
   1.136 -        self.saveDB()
   1.137 +        self.saveToDB()
   1.138          return 0
   1.139  
   1.140      def is_terminated(self):
   1.141 @@ -649,14 +660,13 @@ class XendDomainInfo:
   1.142              cpu = int(sxp.child_value(self.config, 'cpu', '-1'))
   1.143          except:
   1.144              raise VmError('invalid cpu')
   1.145 -        dom = self.image.initDomain(self.id, self.memory, cpu, self.cpu_weight)
   1.146 +        id = self.image.initDomain(self.id, self.memory, cpu, self.cpu_weight)
   1.147          log.debug('init_domain> Created domain=%d name=%s memory=%d',
   1.148 -                  dom, self.name, self.memory)
   1.149 -        if not self.restore:
   1.150 -            self.setdom(dom)
   1.151 +                  id, self.name, self.memory)
   1.152 +        self.setdom(id)
   1.153  
   1.154      def openChannel(self, key, local, remote):
   1.155 -        """Create a channel to the domain.
   1.156 +        """Create a control channel to the domain.
   1.157          If saved info is available recreate the channel.
   1.158          
   1.159          @param key db key for the saved data (if any)
   1.160 @@ -670,6 +680,11 @@ class XendDomainInfo:
   1.161          return chan
   1.162  
   1.163      def eventChannel(self, key):
   1.164 +        """Create an event channel to the domain.
   1.165 +        If saved info is available recreate the channel.
   1.166 +        
   1.167 +        @param key db key for the saved data (if any)
   1.168 +        """
   1.169          db = self.db.addChild(key)
   1.170          return EventChannel.restoreFromDB(db, 0, self.id)
   1.171          
   1.172 @@ -832,11 +847,12 @@ class XendDomainInfo:
   1.173              self.state = STATE_VM_OK
   1.174              self.shutdown_pending = None
   1.175              self.restart_check()
   1.176 +            self.exportToDB()
   1.177              self.restart_state = STATE_RESTART_BOOTING
   1.178              if self.bootloader:
   1.179                  self.config = self.bootloader_config()
   1.180              self.construct(self.config)
   1.181 -            self.saveDB()
   1.182 +            self.saveToDB()
   1.183          finally:
   1.184              self.restart_state = None
   1.185  
   1.186 @@ -910,23 +926,6 @@ class XendDomainInfo:
   1.187              backend = blkif.getBackend(0)
   1.188              backend.connect(recreate=self.recreate)
   1.189  
   1.190 -    def dom_construct(self, dom, config):
   1.191 -        """Construct a vm for an existing domain.
   1.192 -
   1.193 -        @param dom: domain id
   1.194 -        @param config: domain configuration
   1.195 -        """
   1.196 -        d = dom_get(dom)
   1.197 -        if not d:
   1.198 -            raise VmError("Domain not found: %d" % dom)
   1.199 -        try:
   1.200 -            self.restore = True
   1.201 -            self.setdom(dom)
   1.202 -            self.memory = d['mem_kb']/1024
   1.203 -            self.construct(config)
   1.204 -        finally:
   1.205 -            self.restore = False
   1.206 -
   1.207      def configure_fields(self):
   1.208          """Process the vm configuration fields using the registered handlers.
   1.209          """
     2.1 --- a/tools/python/xen/xend/image.py	Fri Jun 17 10:24:34 2005 +0000
     2.2 +++ b/tools/python/xen/xend/image.py	Fri Jun 17 14:20:55 2005 +0000
     2.3 @@ -96,8 +96,8 @@ class ImageHandler:
     2.4          self.db = vm.db.addChild('/image')
     2.5          self.config = config
     2.6  
     2.7 -    def exportToDB(self, save=False):
     2.8 -        self.db.exportToDB(self, fields=self.__exports__, save=save)
     2.9 +    def exportToDB(self, save=False, sync=False):
    2.10 +        self.db.exportToDB(self, fields=self.__exports__, save=save, sync=sync)
    2.11  
    2.12      def importFromDB(self):
    2.13          self.db.importFromDB(self, fields=self.__exports__)
     3.1 --- a/tools/python/xen/xend/server/blkif.py	Fri Jun 17 10:24:34 2005 +0000
     3.2 +++ b/tools/python/xen/xend/server/blkif.py	Fri Jun 17 14:20:55 2005 +0000
     3.3 @@ -167,6 +167,7 @@ class BlkDev(Dev):
     3.4          DBVar('params',       ty='str'),
     3.5          DBVar('node',         ty='str'),
     3.6          DBVar('device',       ty='long'),
     3.7 +        DBVar('dev_handle',   ty='long'),
     3.8          DBVar('start_sector', ty='long'),
     3.9          DBVar('nr_sectors',   ty='long'),
    3.10          ]
     4.1 --- a/tools/python/xen/xend/server/channel.py	Fri Jun 17 10:24:34 2005 +0000
     4.2 +++ b/tools/python/xen/xend/server/channel.py	Fri Jun 17 14:20:55 2005 +0000
     4.3 @@ -81,7 +81,7 @@ class EventChannel(dict):
     4.4          evtchn_close(self.dom1, self.port1)
     4.5          evtchn_close(self.dom2, self.port2)
     4.6  
     4.7 -    def saveToDB(self, db):
     4.8 +    def saveToDB(self, db, save=False):
     4.9          """Save the event channel to the db so it can be restored later,
    4.10          using restoreFromDB() on the class.
    4.11  
    4.12 @@ -91,7 +91,7 @@ class EventChannel(dict):
    4.13          db['dom2']  = str(self.dom2)
    4.14          db['port1'] = str(self.port1)
    4.15          db['port2'] = str(self.port2)
    4.16 -        db.saveDB()
    4.17 +        db.saveDB(save=save)
    4.18  
    4.19      def sxpr(self):
    4.20          return ['event-channel',
    4.21 @@ -339,7 +339,7 @@ class Channel:
    4.22          # Make sure the port will deliver all the messages.
    4.23          self.port.register(TYPE_WILDCARD)
    4.24  
    4.25 -    def saveToDB(self, db):
    4.26 +    def saveToDB(self, db, save=False):
    4.27          """Save the channel ports to the db so the channel can be restored later,
    4.28          using restoreFromDB() on the factory.
    4.29  
    4.30 @@ -348,7 +348,7 @@ class Channel:
    4.31          if self.closed: return
    4.32          db['local_port'] = str(self.getLocalPort())
    4.33          db['remote_port'] = str(self.getRemotePort())
    4.34 -        db.saveDB()
    4.35 +        db.saveDB(save=save)
    4.36  
    4.37      def getKey(self):
    4.38          """Get the channel key.
     5.1 --- a/tools/python/xen/xend/server/console.py	Fri Jun 17 10:24:34 2005 +0000
     5.2 +++ b/tools/python/xen/xend/server/console.py	Fri Jun 17 14:20:55 2005 +0000
     5.3 @@ -214,7 +214,8 @@ class ConsoleDev(Dev, protocol.ServerFac
     5.4                      self.unix_listener = reactor.listenUNIX(path, self)
     5.5                  if xroot.get_xend_http_server():
     5.6                      interface = xroot.get_console_address()
     5.7 -                    self.tcp_listener = reactor.listenTCP(self.console_port, self, interface=interface)
     5.8 +                    self.tcp_listener = reactor.listenTCP(
     5.9 +                        self.console_port, self, interface=interface)
    5.10          finally:
    5.11              self.lock.release()
    5.12  
     6.1 --- a/tools/python/xen/xend/xenstore/xsobj.py	Fri Jun 17 10:24:34 2005 +0000
     6.2 +++ b/tools/python/xen/xend/xenstore/xsobj.py	Fri Jun 17 14:20:55 2005 +0000
     6.3 @@ -1,6 +1,8 @@
     6.4  import string
     6.5  import types
     6.6  
     6.7 +from xen.xend.XendLogging import log
     6.8 +
     6.9  from xen.xend import sxp
    6.10  from xsnode import XenNode
    6.11  from xen.util.mac import macToString, macFromString
    6.12 @@ -14,14 +16,19 @@ def hasAttr(obj, attr):
    6.13          return hasattr(obj, attr)
    6.14  
    6.15  def getAttr(obj, attr):
    6.16 -    if isinstance(obj, dict):
    6.17 -        return dict.get(attr)
    6.18 -    else:
    6.19 -        return getattr(obj, attr, None)
    6.20 +    try:
    6.21 +        if isinstance(obj, dict):
    6.22 +            return obj.get(attr)
    6.23 +        else:
    6.24 +            return getattr(obj, attr, None)
    6.25 +    except AttributeError:
    6.26 +        return None
    6.27 +    except LookupError:
    6.28 +        return None
    6.29  
    6.30  def setAttr(obj, attr, val):
    6.31      if isinstance(obj, dict):
    6.32 -        dict[attr] = val
    6.33 +        obj[attr] = val
    6.34      else:
    6.35          setattr(obj, attr, val)
    6.36  
    6.37 @@ -53,8 +60,8 @@ class DBConverter:
    6.38  
    6.39      convertToDB = classmethod(convertToDB)
    6.40  
    6.41 -    def convertFromDB(cls, val, ty=None):
    6.42 -        return cls.getConverter(ty).fromDB(val)
    6.43 +    def convertFromDB(cls, data, ty=None):
    6.44 +        return cls.getConverter(ty).fromDB(data.getData())
    6.45  
    6.46      convertFromDB = classmethod(convertFromDB)
    6.47  
    6.48 @@ -201,9 +208,8 @@ class DBVar:
    6.49          setAttr(o, self.attr, val)
    6.50  
    6.51      def getDB(self, db):
    6.52 -        try:
    6.53 -            data = getattr(db, self.path)
    6.54 -        except AttributeError:
    6.55 +        data = getAttr(db, self.path)
    6.56 +        if data is None:
    6.57              return None
    6.58          return DBConverter.convertFromDB(data, ty=self.ty)
    6.59  
    6.60 @@ -214,8 +220,7 @@ class DBVar:
    6.61              return
    6.62          data = DBConverter.convertToDB(val, ty=self.ty)
    6.63          #print 'DBVar>setDB>', self.path, 'data=', data
    6.64 -        setattr(db, self.path, data)
    6.65 -        
    6.66 +        setAttr(db, self.path, data)
    6.67  
    6.68  class DBMap(dict):
    6.69      """A persistent map. Extends dict with persistence.