ia64/xen-unstable

changeset 2142:1157e187afb2

bitkeeper revision 1.1159.6.5 (41179cd0aGJI1_zvJCg05dqagSOrlw)

Fix problem with wrong domain name in vifctl down.
Add generic support to XendRoot to solve recursive
mutual import problem.
author mjw@wray-m-3.hpl.hp.com
date Mon Aug 09 15:48:32 2004 +0000 (2004-08-09)
parents 05bd2a6ec4b2
children 19d6528c3d3d
files tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/XendRoot.py tools/python/xen/xend/server/netif.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Mon Aug 09 12:52:35 2004 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Mon Aug 09 15:48:32 2004 +0000
     1.3 @@ -53,9 +53,8 @@ class XendDomain:
     1.4          # Hack alert. Python does not support mutual imports, but XendDomainInfo
     1.5          # needs access to the XendDomain instance to look up domains. Attempting
     1.6          # to import XendDomain from XendDomainInfo causes unbounded recursion.
     1.7 -        # So we stuff the XendDomain instance (self) into XendDomainInfo's
     1.8 -        # namespace as 'xd'.
     1.9 -        XendDomainInfo.xd = self
    1.10 +        # So we stuff the XendDomain instance (self) into xroot's components.
    1.11 +        xroot.add_component("xen.xend.XendDomain", self)
    1.12          # Table of domain info indexed by domain id.
    1.13          self.db = XendDB.XendDB(self.dbpath)
    1.14          self.domain_db = self.db.fetchall("")
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Mon Aug 09 12:52:35 2004 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Mon Aug 09 15:48:32 2004 +0000
     2.3 @@ -27,6 +27,7 @@ import sxp
     2.4  import XendConsole
     2.5  xendConsole = XendConsole.instance()
     2.6  from XendLogging import log
     2.7 +from XendRoot import get_component
     2.8  
     2.9  import server.SrvDaemon
    2.10  xend = server.SrvDaemon.instance()
    2.11 @@ -460,7 +461,8 @@ class XendDomainInfo:
    2.12              if c in '_-.': continue
    2.13              if c in string.ascii_letters: continue
    2.14              raise VmError('invalid vm name')
    2.15 -        # See comment in XendDomain constructor about 'xd'.
    2.16 +        # See comment in XendDomain constructor.
    2.17 +        xd = get_component('xen.xend.XendDomain')
    2.18          if xd.domain_exists(name):
    2.19              raise VmError('vm name clash: ' + name)
    2.20          
     3.1 --- a/tools/python/xen/xend/XendRoot.py	Mon Aug 09 12:52:35 2004 +0000
     3.2 +++ b/tools/python/xen/xend/XendRoot.py	Mon Aug 09 15:48:32 2004 +0000
     3.3 @@ -50,6 +50,8 @@ class XendRoot:
     3.4  
     3.5      loglevel_default = 'DEBUG'
     3.6  
     3.7 +    components = {}
     3.8 +
     3.9      def __init__(self):
    3.10          self.rebooted = 0
    3.11          self.last_reboot = None
    3.12 @@ -62,6 +64,24 @@ class XendRoot:
    3.13          #eserver.subscribe('xend.domain.created', self.event_handler)
    3.14          #eserver.subscribe('xend.domain.died', self.event_handler)
    3.15  
    3.16 +    def add_component(self, name, val):
    3.17 +        """Add a xend component.
    3.18 +
    3.19 +        @param name: component name
    3.20 +        @param val:  component object
    3.21 +        """
    3.22 +        self.components[name] = val
    3.23 +
    3.24 +    def get_component(self, name):
    3.25 +        """Get a xend component from its name.
    3.26 +        This is used as a work-round for problems caused by mutually
    3.27 +        recursive imports.
    3.28 +
    3.29 +        @param name: component name
    3.30 +        @return: component object (or None)
    3.31 +        """
    3.32 +        return self.components.get(name)
    3.33 +
    3.34      def start(self):
    3.35          eserver.inject('xend.start', self.rebooted)
    3.36  
    3.37 @@ -202,3 +222,9 @@ def instance():
    3.38  
    3.39  def logger():
    3.40      return instance().get_logger()
    3.41 +
    3.42 +def add_component(name, val):
    3.43 +    return instance().add_component(name, val)
    3.44 +
    3.45 +def get_component(name):
    3.46 +    return instance().get_component(name)
     4.1 --- a/tools/python/xen/xend/server/netif.py	Mon Aug 09 12:52:35 2004 +0000
     4.2 +++ b/tools/python/xen/xend/server/netif.py	Mon Aug 09 15:48:32 2004 +0000
     4.3 @@ -10,6 +10,7 @@ from xen.xend import Vifctl
     4.4  from xen.xend.XendError import XendError
     4.5  from xen.xend.XendLogging import log
     4.6  from xen.xend import XendVnet
     4.7 +from xen.xend.XendRoot import get_component
     4.8  
     4.9  import channel
    4.10  import controller
    4.11 @@ -168,8 +169,14 @@ class NetDev(controller.Dev):
    4.12  
    4.13      def vifctl_params(self, vmname=None):
    4.14          dom = self.controller.dom
    4.15 -        name = vmname or ('DOM%d' % dom)
    4.16 -        return { 'domain': name,
    4.17 +        if vmname is None:
    4.18 +            xd = get_component('xen.xend.XendDomain')
    4.19 +            try:
    4.20 +                vm = xd.domain_lookup(dom)
    4.21 +                vmname = vm.name
    4.22 +            except:
    4.23 +                vmname = 'DOM%d' % dom
    4.24 +        return { 'domain': vmname,
    4.25                   'vif'   : self.get_vifname(), 
    4.26                   'mac'   : self.get_mac(),
    4.27                   'bridge': self.bridge,