Esempio n. 1
0
 def remove_interface(self, bridge_name, interface_name):
     bridge_device = bridge_lib.BridgeDevice(bridge_name)
     if bridge_device.exists():
         if not bridge_lib.is_bridged_interface(interface_name):
             return True
         LOG.debug(
             "Removing device %(interface_name)s from bridge "
             "%(bridge_name)s", {
                 'interface_name': interface_name,
                 'bridge_name': bridge_name
             })
         if bridge_device.delif(interface_name):
             return False
         LOG.debug(
             "Done removing device %(interface_name)s from bridge "
             "%(bridge_name)s", {
                 'interface_name': interface_name,
                 'bridge_name': bridge_name
             })
         return True
     else:
         LOG.debug(
             "Cannot remove device %(interface_name)s bridge "
             "%(bridge_name)s does not exist", {
                 'interface_name': interface_name,
                 'bridge_name': bridge_name
             })
         return False
 def remove_interface(self, bridge_name, interface_name, down=False):
     return not ip_lib.IPDevice(interface).link.set_master(None, down=down)
     # Ignore the rest
     bridge_device = bridge_lib.BridgeDevice(bridge_name)
     if bridge_device.exists():
         if not bridge_lib.is_bridged_interface(interface_name):
             return True
         LOG.debug(
             "Removing device %(interface_name)s from bridge "
             "%(bridge_name)s", {
                 'interface_name': interface_name,
                 'bridge_name': bridge_name
             })
         if bridge_device.delif(interface_name):
             return False
         LOG.debug(
             "Done removing device %(interface_name)s from bridge "
             "%(bridge_name)s", {
                 'interface_name': interface_name,
                 'bridge_name': bridge_name
             })
         return True
     else:
         LOG.debug(
             "Cannot remove device %(interface_name)s bridge "
             "%(bridge_name)s does not exist", {
                 'interface_name': interface_name,
                 'bridge_name': bridge_name
             })
         return False
    def ensure_bridge(self, bridge_name, interface=None, ips=None, gateway=None):
        """Create a bridge unless it already exists."""
        # _bridge_exists_and_ensure_up instead of device_exists is used here
        # because there are cases where the bridge exists but it's not UP,
        # for example:
        # 1) A greenthread was executing this function and had not yet executed
        # "ip link set bridge_name up" before eventlet switched to this
        # thread running the same function
        # 2) The Nova VIF driver was running concurrently and had just created
        #    the bridge, but had not yet put it UP
        if not self._bridge_exists_and_ensure_up(bridge_name):
            LOG.debug(
                "Starting bridge %(bridge_name)s for subinterface " "%(interface)s",
                {"bridge_name": bridge_name, "interface": interface},
            )
            bridge_device = bridge_lib.BridgeDevice.addbr(bridge_name)
            if bridge_device.setfd(0):
                return
            if bridge_device.disable_stp():
                return
            if bridge_device.link.set_up():
                return
            LOG.debug(
                "Done starting bridge %(bridge_name)s for " "subinterface %(interface)s",
                {"bridge_name": bridge_name, "interface": interface},
            )
        else:
            bridge_device = bridge_lib.BridgeDevice(bridge_name)

        if not interface:
            return bridge_name

        # Update IP info if necessary
        self.update_interface_ip_details(bridge_name, interface, ips, gateway)

        # Check if the interface is part of the bridge
        if not bridge_device.owns_interface(interface):
            try:
                # Check if the interface is not enslaved in another bridge
                if bridge_lib.is_bridged_interface(interface):
                    bridge = self.get_bridge_for_tap_device(interface)
                    bridge.delif(interface)

                bridge_device.addif(interface)
            except Exception as e:
                LOG.error(
                    _LE("Unable to add %(interface)s to %(bridge_name)s" "! Exception: %(e)s"),
                    {"interface": interface, "bridge_name": bridge_name, "e": e},
                )
                return
        return bridge_name
Esempio n. 4
0
 def remove_interface(self, bridge_name, interface_name):
     bridge_device = bridge_lib.BridgeDevice(bridge_name)
     if bridge_device.exists():
         if not bridge_lib.is_bridged_interface(interface_name):
             return True
         LOG.debug("Removing device %(interface_name)s from bridge "
                   "%(bridge_name)s",
                   {'interface_name': interface_name,
                    'bridge_name': bridge_name})
         if bridge_device.delif(interface_name):
             return False
         LOG.debug("Done removing device %(interface_name)s from bridge "
                   "%(bridge_name)s",
                   {'interface_name': interface_name,
                    'bridge_name': bridge_name})
         return True
     else:
         LOG.debug("Cannot remove device %(interface_name)s bridge "
                   "%(bridge_name)s does not exist",
                   {'interface_name': interface_name,
                    'bridge_name': bridge_name})
         return False
 def remove_interface(self, bridge_name, interface_name, down=False):
     return not ip_lib.IPDevice(interface).link.set_master(None, down=down)
     # Ignore the rest
     bridge_device = bridge_lib.BridgeDevice(bridge_name)
     if bridge_device.exists():
         if not bridge_lib.is_bridged_interface(interface_name):
             return True
         LOG.debug("Removing device %(interface_name)s from bridge "
                   "%(bridge_name)s",
                   {'interface_name': interface_name,
                    'bridge_name': bridge_name})
         if bridge_device.delif(interface_name):
             return False
         LOG.debug("Done removing device %(interface_name)s from bridge "
                   "%(bridge_name)s",
                   {'interface_name': interface_name,
                    'bridge_name': bridge_name})
         return True
     else:
         LOG.debug("Cannot remove device %(interface_name)s bridge "
                   "%(bridge_name)s does not exist",
                   {'interface_name': interface_name,
                    'bridge_name': bridge_name})
         return False
Esempio n. 6
0
 def test_is_bridged_interface(self):
     exists = lambda path: path == "/sys/class/net/tapOK/brport"
     with mock.patch('os.path.exists', side_effect=exists):
         self.assertTrue(bridge_lib.is_bridged_interface("tapOK"))
         self.assertFalse(bridge_lib.is_bridged_interface("tapKO"))
Esempio n. 7
0
 def test_is_not_bridged_interface(self):
     self.assertFalse(
         bridge_lib.is_bridged_interface(self.port_fixture.port.name))
Esempio n. 8
0
 def test_is_bridged_interface(self):
     self.assertTrue(
         bridge_lib.is_bridged_interface(self.port_fixture.br_port.name))
Esempio n. 9
0
 def test_is_not_bridged_interface(self):
     self.assertFalse(
         bridge_lib.is_bridged_interface(self.port_fixture.port.name))
Esempio n. 10
0
 def test_is_bridged_interface(self):
     self.assertTrue(
         bridge_lib.is_bridged_interface(self.port_fixture.br_port.name))
Esempio n. 11
0
 def test_is_bridged_interface(self):
     exists = lambda path: path == "/sys/class/net/tapOK/brport"
     with mock.patch('os.path.exists', side_effect=exists):
         self.assertTrue(bridge_lib.is_bridged_interface("tapOK"))
         self.assertFalse(bridge_lib.is_bridged_interface("tapKO"))
Esempio n. 12
0
 def test_is_bridged_interface_and_remove(self):
     bridge = bridge_lib.BridgeDevice(self.bridge.name)
     bridge_port = self.port_fixture.br_port.name
     self.assertTrue(bridge_lib.is_bridged_interface(bridge_port))
     bridge.delif(bridge_port)
     self.assertFalse(bridge_lib.is_bridged_interface(bridge_port))