def plug(self, device_name, port_id, mac_address, bridge=None, namespace=None, prefix=None): """Plug in the interface.""" if not bridge: bridge = self.conf.ovs_integration_bridge self.check_bridge_exists(bridge) ip = ip_lib.IPWrapper() ns_dev = ip.device(device_name) if not ip_lib.device_exists(device_name, namespace=namespace): tap_name = self._get_tap_name(device_name) self._ovs_add_port(bridge, tap_name, port_id, mac_address) ns_dev.link.set_address(mac_address) # Add an interface created by ovs to the namespace. if namespace: namespace_obj = ip.ensure_namespace(namespace) namespace_obj.add_device_to_namespace(ns_dev) else: LOG.warn(_("Device %s already exists"), device_name) ns_dev.link.set_up()
def plug(self, device_name, port_id, mac_address, bridge=None, namespace=None, prefix=None): """Plugin the interface.""" ip = ip_lib.IPWrapper() if prefix: tap_name = device_name.replace(prefix, 'tap') else: tap_name = device_name.replace(self.DEV_NAME_PREFIX, 'tap') if not ip_lib.device_exists(device_name, namespace=namespace): # Create ns_veth in a namespace if one is configured. root_veth, ns_veth = ip.add_veth(tap_name, device_name, namespace2=namespace) ns_veth.link.set_address(mac_address) else: ns_veth = ip.device(device_name) root_veth = ip.device(tap_name) LOG.warn(_("Device %s already exists"), device_name) root_veth.link.set_up() ns_veth.link.set_up()
def plug(self, device_name, port_id, mac_address, bridge=None, namespace=None, prefix=None): """Plug in the interface.""" if not bridge: bridge = self.conf.ovs_integration_bridge self.check_bridge_exists(bridge) ip = ip_lib.IPWrapper() ns_dev = ip.device(device_name) if not ip_lib.device_exists(device_name, namespace=namespace): tap_name = self._get_tap_name(device_name) self._ovs_add_port(bridge, tap_name, port_id, mac_address) ns_dev.link.set_address(mac_address) # Add an interface created by ovs to the namespace. if namespace: namespace_obj = ip.ensure_namespace(namespace) namespace_obj.add_device_to_namespace(ns_dev) else: LOG.warn(_LW("Device %s already exists"), device_name) ns_dev.link.set_up()
def plug(self, device_name, port_id, mac_address, bridge=None, namespace=None, prefix=None): """Plugin the interface.""" ip = ip_lib.IPWrapper() if prefix: tap_name = device_name.replace(prefix, 'tap') else: tap_name = device_name.replace(self.DEV_NAME_PREFIX, 'tap') if not ip_lib.device_exists(device_name, namespace=namespace): # Create ns_veth in a namespace if one is configured. root_veth, ns_veth = ip.add_veth(tap_name, device_name, namespace2=namespace) ns_veth.link.set_address(mac_address) else: ns_veth = ip.device(device_name) root_veth = ip.device(tap_name) LOG.warn(_LW("Device %s already exists"), device_name) root_veth.link.set_up() ns_veth.link.set_up()
def check_bridge_exists(self, bridge): if not ip_lib.device_exists(bridge): raise exception.BridgeDoesNotExist(bridge=bridge)
def test_device_does_not_exist(self): with mock.patch.object(ip_lib.IPDevice, '_execute') as _execute: _execute.return_value = '' _execute.side_effect = RuntimeError('Device does not exist.') self.assertFalse(ip_lib.device_exists('eth0'))
def test_device_exists(self): with mock.patch.object(ip_lib.IPDevice, '_execute') as _execute: _execute.return_value = LINK_SAMPLE[1] self.assertTrue(ip_lib.device_exists('eth0')) _execute.assert_called_once_with('o', 'link', ('show', 'eth0'))