ia64/xen-unstable

changeset 2359:159487c5dc02

bitkeeper revision 1.1159.1.111 (412ef44aeLKE7Ni8u9PHp6mOfGp8ow)

Add some more events for domains and migrate/save.
author mjw@wray-m-3.hpl.hp.com
date Fri Aug 27 08:43:54 2004 +0000 (2004-08-27)
parents 5db55dc7f66a
children 11be1dfb262b
files tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendMigrate.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Fri Aug 27 08:42:25 2004 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Fri Aug 27 08:43:54 2004 +0000
     1.3 @@ -256,7 +256,10 @@ class XendDomain:
     1.4                          eserver.inject('xend.domain.suspended', [name, id])
     1.5                          continue
     1.6                  if reason in ['poweroff', 'reboot']:
     1.7 +                    eserver.inject('xend.domain.exit', [name, id, reason])
     1.8                      self.domain_restart_schedule(id, reason)
     1.9 +            else:
    1.10 +               eserver.inject('xend.domain.exit', [name, id, 'crash']) 
    1.11              destroyed += 1
    1.12              self.final_domain_destroy(id)
    1.13          if self.domain_restarts_exist():
     2.1 --- a/tools/python/xen/xend/XendMigrate.py	Fri Aug 27 08:42:25 2004 +0000
     2.2 +++ b/tools/python/xen/xend/XendMigrate.py	Fri Aug 27 08:43:54 2004 +0000
     2.3 @@ -17,6 +17,7 @@ import sxp
     2.4  import XendDB
     2.5  import EventServer; eserver = EventServer.instance()
     2.6  from XendError import XendError
     2.7 +from XendLogging import log
     2.8          
     2.9  """The port for the migrate/save daemon xfrd."""
    2.10  XFRD_PORT = 8002
    2.11 @@ -289,6 +290,8 @@ class XendMigrateInfo(XfrdInfo):
    2.12          if not vmconfig:
    2.13              xfrd.loseConnection()
    2.14              return
    2.15 +        log.info('Migrate BEGIN: ' + str(self.sxpr()))
    2.16 +        eserver.inject('xend.migrate.begin', self.sxpr())
    2.17          xfrd.request(['xfr.migrate',
    2.18                        self.src_dom,
    2.19                        vmconfig,
    2.20 @@ -308,10 +311,12 @@ class XendMigrateInfo(XfrdInfo):
    2.21          print 'XfrdMigrateInfo>connectionLost>', reason
    2.22          XfrdInfo.connectionLost(self, reason)
    2.23          if self.state =='ok':
    2.24 +            log.info('Migrate OK: ' + str(self.sxpr()))
    2.25              eserver.inject('xend.migrate.ok', self.sxpr())
    2.26          else:
    2.27              self.state = 'error'
    2.28              self.error(XendError("migrate failed"))
    2.29 +            log.info('Migrate ERROR: ' + str(self.sxpr()))
    2.30              eserver.inject('xend.migrate.error', self.sxpr())
    2.31  
    2.32  class XendSaveInfo(XfrdInfo):
    2.33 @@ -335,10 +340,14 @@ class XendSaveInfo(XfrdInfo):
    2.34          return sxpr
    2.35  
    2.36      def request(self, xfrd):
    2.37 +        print '***request>', self.vmconfig()
    2.38          vmconfig = self.vmconfig()
    2.39          if not vmconfig:
    2.40              xfrd.loseConnection()
    2.41              return
    2.42 +        print '***request> begin'
    2.43 +        log.info('Save BEGIN: ' + str(self.sxpr()))
    2.44 +        eserver.inject('xend.save.begin', self.sxpr())
    2.45          xfrd.request(['xfr.save', self.src_dom, vmconfig, self.file ])
    2.46          
    2.47      def xfr_save_ok(self, xfrd, val):
    2.48 @@ -351,10 +360,12 @@ class XendSaveInfo(XfrdInfo):
    2.49          print 'XfrdSaveInfo>connectionLost>', reason
    2.50          XfrdInfo.connectionLost(self, reason)
    2.51          if self.state =='ok':
    2.52 +            log.info('Save OK: ' + str(self.sxpr()))
    2.53              eserver.inject('xend.save.ok', self.sxpr())
    2.54          else:
    2.55              self.state = 'error'
    2.56              self.error(XendError("save failed"))
    2.57 +            log.info('Save ERROR: ' + str(self.sxpr()))
    2.58              eserver.inject('xend.save.error', self.sxpr())
    2.59      
    2.60  
    2.61 @@ -388,17 +399,19 @@ class XendMigrate:
    2.62      def close(self):
    2.63          pass
    2.64  
    2.65 -    def _add_session(self, xid, info):
    2.66 +    def _add_session(self, info):
    2.67 +        xid = info.xid
    2.68          self.session[xid] = info
    2.69          self.session_db[xid] = info.sxpr()
    2.70          self.sync_session(xid)
    2.71 -        #eserver.inject('xend.migrate.begin', info.sxpr())
    2.72  
    2.73      def _delete_session(self, xid):
    2.74 -        #eserver.inject('xend.migrate.end', xid)
    2.75 -        del self.session[xid]
    2.76 -        del self.session_db[xid]
    2.77 -        self.db.delete(xid)
    2.78 +        print '***_delete_session>', xid
    2.79 +        if xid in self.session:
    2.80 +            del self.session[xid]
    2.81 +        if xid in self.session_db:
    2.82 +            del self.session_db[xid]
    2.83 +            self.db.delete(xid)
    2.84  
    2.85      def session_ls(self):
    2.86          return self.session.keys()
    2.87 @@ -410,10 +423,23 @@ class XendMigrate:
    2.88          return self.session.get(xid)
    2.89  
    2.90      def session_begin(self, info):
    2.91 -        self._add_session(info.xid, info)
    2.92 +        """Add the session to the table and start it.
    2.93 +        Set up callbacks to remove the session from the table
    2.94 +        when it finishes.
    2.95 +
    2.96 +        @param info: session
    2.97 +        @return: deferred
    2.98 +        """
    2.99 +        def cbremove(val):
   2.100 +            print '***cbremove>', val
   2.101 +            self._delete_session(info.xid)
   2.102 +            return val
   2.103 +        self._add_session(info)
   2.104 +        info.deferred.addCallback(cbremove)
   2.105 +        info.deferred.addErrback(cbremove)
   2.106          xcf = XfrdClientFactory(info)
   2.107          reactor.connectTCP('localhost', XFRD_PORT, xcf)
   2.108 -        return info
   2.109 +        return info.deferred
   2.110      
   2.111      def migrate_begin(self, dom, host, port=XFRD_PORT, live=0):
   2.112          """Begin to migrate a domain to another host.
   2.113 @@ -423,12 +449,9 @@ class XendMigrate:
   2.114          @param port: destination port
   2.115          @return: deferred
   2.116          """
   2.117 -        # Check dom for existence, not migrating already.
   2.118 -        # Subscribe to migrate notifications (for updating).
   2.119          xid = self.nextid()
   2.120          info = XendMigrateInfo(xid, dom, host, port, live)
   2.121 -        self.session_begin(info)
   2.122 -        return info.deferred
   2.123 +        return self.session_begin(info)
   2.124  
   2.125      def save_begin(self, dom, file):
   2.126          """Begin saving a domain to file.
   2.127 @@ -439,8 +462,7 @@ class XendMigrate:
   2.128          """
   2.129          xid = self.nextid()
   2.130          info = XendSaveInfo(xid, dom, file)
   2.131 -        self.session_begin(info)
   2.132 -        return info.deferred
   2.133 +        return self.session_begin(info)
   2.134  
   2.135  def instance():
   2.136      global inst