ia64/xen-unstable

changeset 16625:44a98411d230

xend: Prevent XenD touching externally managed bridges

With current XenD 3.0.4 or later try the following:

brctl addbr demo
ifconfig demo up

/etc/init.d/xend start
/etc/init.d/xend stop

ifconfig demo down
brctl delbr demo

Now, start XenD again....

/etc/init.d/xend start

And watch in horror as it re-creates your 'demo' bridge.

The problem is that the 'XendNetwork' class does not distinguish
between bridge devices that it is managing (ie those created via
XenAPI) and those which it does not manage (ie those created by OS
distro init scripts, or by apps like libvirt).

While initially I thought I could just make XenD ignore
externally-managed bridges completely, it seems to needs to know about
them otherwise it can't hook up guest VIFs to them correctly. So the
attached patch adds a 'managed' flag to the XendNetwork
class. Externally managed bridges have this set to False. At startup
XenD will now only re-create bridge devices which have the 'managed'
flag set to 'True' - ie those created via XenAPI.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
author Keir Fraser <keir.fraser@citrix.com>
date Sat Dec 15 18:26:52 2007 +0000 (2007-12-15)
parents 257ca4017b41
children d9ab9eb2bfee
files tools/python/xen/xend/XendNetwork.py
line diff
     1.1 --- a/tools/python/xen/xend/XendNetwork.py	Sat Dec 15 18:23:13 2007 +0000
     1.2 +++ b/tools/python/xen/xend/XendNetwork.py	Sat Dec 15 18:26:52 2007 +0000
     1.3 @@ -52,7 +52,8 @@ class XendNetwork(XendBase):
     1.4  
     1.5      def getAttrRO(self):
     1.6          attrRO =  ['VIFs',
     1.7 -                   'PIFs']
     1.8 +                   'PIFs',
     1.9 +                   'managed']
    1.10          return XendBase.getAttrRO() + attrRO
    1.11  
    1.12      def getAttrInst(self):
    1.13 @@ -88,7 +89,8 @@ class XendNetwork(XendBase):
    1.14                  'name_description': '',
    1.15                  'other_config':     {},
    1.16                  'default_gateway':  '',
    1.17 -                'default_netmask':  ''
    1.18 +                'default_netmask':  '',
    1.19 +                'managed':          False,
    1.20              }
    1.21          network = XendNetwork(record, uuid)
    1.22  
    1.23 @@ -106,7 +108,10 @@ class XendNetwork(XendBase):
    1.24  
    1.25          # Create network if it doesn't already exist
    1.26          if not bridge_exists(network.name_label):
    1.27 -            Brctl.bridge_create(network.name_label)
    1.28 +            if network.managed:
    1.29 +                Brctl.bridge_create(network.name_label)
    1.30 +            else:
    1.31 +                log.info("Not recreating missing unmanaged network %s" % network.name_label)
    1.32  
    1.33          return uuid
    1.34  
    1.35 @@ -143,7 +148,13 @@ class XendNetwork(XendBase):
    1.36      create            = classmethod(create)
    1.37      get_by_name_label = classmethod(get_by_name_label)
    1.38          
    1.39 -    def __init__(self, record, uuid):       
    1.40 +    def __init__(self, record, uuid):
    1.41 +        # This is a read-only attr, so we need to
    1.42 +        # set it here, as super class won't try to
    1.43 +        if record.has_key("managed"):
    1.44 +            self.managed = record["managed"]
    1.45 +        else:
    1.46 +            self.managed = True
    1.47          XendBase.__init__(self, uuid, record)
    1.48          
    1.49      #
    1.50 @@ -177,6 +188,9 @@ class XendNetwork(XendBase):
    1.51          self.name_description = new_desc
    1.52          XendNode.instance().save_networks()
    1.53  
    1.54 +    def get_managed(self):
    1.55 +        return self.managed
    1.56 +
    1.57      def get_VIFs(self):
    1.58          result = []
    1.59          vms = XendDomain.instance().get_all_vms()