def setup_connectivity_with_service_instances(self): """Sets up connectivity with service instances. Creates host port in service network and/or admin network, creating and setting up required network devices. """ if self.use_service_network: LOG.debug("Plugging service instance into service network %s.", self.service_network_id) port = self._get_service_port(self.service_network_id, None, 'manila-share') port = self._add_fixed_ips_to_service_port(port) interface_name = self.vif_driver.get_device_name(port) device = ip_lib.IPDevice(interface_name) self._plug_interface_in_host(interface_name, device, port) if self.use_admin_port: LOG.debug("Plugging service instance into admin network %s.", self.admin_network_id) port = self._get_service_port(self.admin_network_id, self.admin_subnet_id, 'manila-admin-share') interface_name = self.vif_driver.get_device_name(port) device = ip_lib.IPDevice(interface_name) self._plug_interface_in_host(interface_name, device, port, clear_outdated_routes=True)
def test_get_devices_malformed_line(self): self.execute.return_value = '\n'.join(LINK_SAMPLE + ['gibberish']) retval = ip_lib.IPWrapper().get_devices() self.assertEqual([ip_lib.IPDevice('lo'), ip_lib.IPDevice('eth0'), ip_lib.IPDevice('br-int'), ip_lib.IPDevice('gw-ddc717df-49'), ip_lib.IPDevice('eth0.50')], retval) self.execute.assert_called_once_with('o', 'link', ('list',), None)
def _setup_connectivity_with_service_instances(self): """Sets up connectivity with service instances. Creates creating port in service network, creating and setting up required network devices. """ port = self._get_service_port() port = self._add_fixed_ips_to_service_port(port) interface_name = self.vif_driver.get_device_name(port) self.vif_driver.plug(interface_name, port['id'], port['mac_address']) ip_cidrs = [] for fixed_ip in port['fixed_ips']: subnet = self.neutron_api.get_subnet(fixed_ip['subnet_id']) net = netaddr.IPNetwork(subnet['cidr']) ip_cidr = '%s/%s' % (fixed_ip['ip_address'], net.prefixlen) ip_cidrs.append(ip_cidr) self.vif_driver.init_l3(interface_name, ip_cidrs) # ensure that interface is first in the list device = ip_lib.IPDevice(interface_name) device.route.pullup_route(interface_name) # here we are checking for garbage devices from removed service port self._remove_outdated_interfaces(device)
def init_l3(self, device_name, ip_cidrs, namespace=None, clear_cidrs=[]): """Set the L3 settings for the interface using data from the port. ip_cidrs: list of 'X.X.X.X/YY' strings """ device = ip_lib.IPDevice(device_name, namespace=namespace) for cidr in clear_cidrs: device.route.clear_outdated_routes(cidr) previous = {} for address in device.addr.list(scope='global', filters=['permanent']): previous[address['cidr']] = address['ip_version'] # add new addresses for ip_cidr in ip_cidrs: net = netaddr.IPNetwork(ip_cidr) if ip_cidr in previous: del previous[ip_cidr] continue device.addr.add(net.version, ip_cidr, str(net.broadcast)) # clean up any old addresses for ip_cidr, ip_version in previous.items(): device.addr.delete(ip_version, ip_cidr) # ensure that interface is first in the list device.route.pullup_route(device_name) # here we are checking for garbage devices from removed service port self._remove_outdated_interfaces(device)
def unplug(self, device_name, bridge=None, namespace=None, prefix=None): """Unplug the interface.""" device = ip_lib.IPDevice(device_name, namespace) try: device.link.delete() LOG.debug("Unplugged interface '%s'", device_name) except RuntimeError: LOG.error(_("Failed unplugging interface '%s'"), device_name)
def setup_connectivity_with_service_instances(self): """Sets up connectivity with service instances. Creates host port in service network and/or admin network, creating and setting up required network devices. """ if self.use_service_network: port = self._get_service_port(self.service_network_id, None, 'manila-share') port = self._add_fixed_ips_to_service_port(port) interface_name = self.vif_driver.get_device_name(port) device = ip_lib.IPDevice(interface_name) self._plug_interface_in_host(interface_name, device, port) if self.use_admin_port: port = self._get_service_port(self.admin_network_id, self.admin_subnet_id, 'manila-admin-share') interface_name = self.vif_driver.get_device_name(port) device = ip_lib.IPDevice(interface_name) for fixed_ip in port['fixed_ips']: subnet = self.neutron_api.get_subnet(fixed_ip['subnet_id']) device.route.clear_outdated_routes(subnet['cidr']) self._plug_interface_in_host(interface_name, device, port)
def init_l3(self, device_name, ip_cidrs, namespace=None): """Set the L3 settings for the interface using data from the port. ip_cidrs: list of 'X.X.X.X/YY' strings """ device = ip_lib.IPDevice(device_name, namespace=namespace) previous = {} for address in device.addr.list(scope='global', filters=['permanent']): previous[address['cidr']] = address['ip_version'] # add new addresses for ip_cidr in ip_cidrs: net = netaddr.IPNetwork(ip_cidr) if ip_cidr in previous: del previous[ip_cidr] continue device.addr.add(net.version, ip_cidr, str(net.broadcast)) # clean up any old addresses for ip_cidr, ip_version in previous.items(): device.addr.delete(ip_version, ip_cidr)
def test_str(self): self.assertEqual(str(ip_lib.IPDevice('tap0')), 'tap0')
def test_eq_other_is_none(self): dev1 = ip_lib.IPDevice('tap0', 'ns1') self.assertNotEqual(dev1, None)
def test_eq_diff_namespace(self): dev1 = ip_lib.IPDevice('tap0', 'ns1') dev2 = ip_lib.IPDevice('tap0', 'ns2') self.assertNotEqual(dev1, dev2)
def test_eq_same_name(self): dev1 = ip_lib.IPDevice('tap0') dev2 = ip_lib.IPDevice('tap0') self.assertEqual(dev1, dev2)