def plug(self, network_id, port_id, device_name, mac_address, bridge=None, namespace=None, prefix=None): """Plugin the interface.""" if not ip_lib.device_exists(device_name, self.root_helper, namespace=namespace): ip = ip_lib.IPWrapper(self.root_helper) # Enable agent to define the prefix if prefix: tap_name = device_name.replace(prefix, 'tap') else: tap_name = device_name.replace(self.DEV_NAME_PREFIX, 'tap') # 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) if self.conf.network_device_mtu: root_veth.link.set_mtu(self.conf.network_device_mtu) ns_veth.link.set_mtu(self.conf.network_device_mtu) root_veth.link.set_up() ns_veth.link.set_up() else: LOG.info(_("Device %s already exists"), device_name)
def plug(self, network_id, port_id, device_name, mac_address, bridge=None, namespace=None, prefix=None): """This method is called by the Dhcp agent or by the L3 agent when a new network is created """ if not ip_lib.device_exists(device_name, self.root_helper, namespace=namespace): ip = ip_lib.IPWrapper(self.root_helper) tap_name = device_name.replace(prefix or 'tap', 'tap') # Create ns_dev in a namespace if one is configured. root_dev, ns_dev = ip.add_veth(tap_name, device_name, namespace2=namespace) ns_dev.link.set_address(mac_address) # Add an interface created by ovs to the namespace. namespace_obj = ip.ensure_namespace(namespace) namespace_obj.add_device_to_namespace(ns_dev) ns_dev.link.set_up() root_dev.link.set_up() cmd = ['mm-ctl', '--bind-port', port_id, device_name] utils.execute(cmd, self.root_helper) else: LOG.info(_("Device %s already exists"), device_name)
def plug(self, network_id, port_id, device_name, mac_address, bridge=None, namespace=None, prefix=None): """Plug in the interface.""" if not ip_lib.device_exists(device_name, self.root_helper, namespace=namespace): ip = ip_lib.IPWrapper(self.root_helper) tap_name = self._get_tap_name(device_name, prefix) root_dev, ns_dev = ip.add_veth(tap_name, device_name) self._ivs_add_port(tap_name, port_id, mac_address) ns_dev = ip.device(device_name) ns_dev.link.set_address(mac_address) if self.conf.network_device_mtu: ns_dev.link.set_mtu(self.conf.network_device_mtu) root_dev.link.set_mtu(self.conf.network_device_mtu) if namespace: namespace_obj = ip.ensure_namespace(namespace) namespace_obj.add_device_to_namespace(ns_dev) ns_dev.link.set_up() root_dev.link.set_up() else: LOG.info(_("Device %s already exists"), device_name)
def internal_network_removed(self, ri, port_id, internal_cidr): interface_name = self.get_internal_device_name(port_id) if ip_lib.device_exists(interface_name, root_helper=self.root_helper, namespace=ri.ns_name): self.driver.unplug(interface_name, namespace=ri.ns_name, prefix=INTERNAL_DEV_PREFIX)
def delete_neutron_ports(ports, root_helper): """Delete non-internal ports created by Crd Non-internal OVS ports need to be removed manually. """ for port in ports: if ip_lib.device_exists(port): device = ip_lib.IPDevice(port, root_helper) device.link.delete() LOG.info(_("Delete %s"), port)
def internal_network_added(self, ri, network_id, port_id, internal_cidr, mac_address): interface_name = self.get_internal_device_name(port_id) if not ip_lib.device_exists(interface_name, root_helper=self.root_helper, namespace=ri.ns_name): self.driver.plug(network_id, port_id, interface_name, mac_address, namespace=ri.ns_name, prefix=INTERNAL_DEV_PREFIX) self.driver.init_l3(interface_name, [internal_cidr], namespace=ri.ns_name) ip_address = internal_cidr.split('/')[0] self._send_gratuitous_arp_packet(ri, interface_name, ip_address)
def _process_routers(self, routers, all_routers=False): pool = eventlet.GreenPool() if (self.conf.external_network_bridge and not ip_lib.device_exists(self.conf.external_network_bridge)): LOG.error(_("The external network bridge '%s' does not exist"), self.conf.external_network_bridge) return target_ex_net_id = self._fetch_external_net_id() # if routers are all the routers we have (They are from router sync on # starting or when error occurs during running), we seek the # routers which should be removed. # If routers are from server side notification, we seek them # from subset of incoming routers and ones we have now. if all_routers: prev_router_ids = set(self.router_info) else: prev_router_ids = set(self.router_info) & set( [router['id'] for router in routers]) cur_router_ids = set() for r in routers: # If namespaces are disabled, only process the router associated # with the configured agent id. if (not self.conf.use_namespaces and r['id'] != self.conf.router_id): continue ex_net_id = (r['external_gateway_info'] or {}).get('network_id') if not ex_net_id and not self.conf.handle_internal_only_routers: continue if (target_ex_net_id and ex_net_id and ex_net_id != target_ex_net_id): # Double check that our single external_net_id has not changed # by forcing a check by RPC. if (ex_net_id != self._fetch_external_net_id(force=True)): continue cur_router_ids.add(r['id']) if r['id'] not in self.router_info: self._router_added(r['id'], r) ri = self.router_info[r['id']] ri.router = r pool.spawn_n(self.process_router, ri) # identify and remove routers that no longer exist for router_id in prev_router_ids - cur_router_ids: pool.spawn_n(self._router_removed, router_id) pool.waitall()
def plug(self, network_id, port_id, device_name, mac_address, bridge=None, namespace=None, prefix=None): """Plug in the interface.""" if not bridge: bridge = self.conf.ovs_integration_bridge if not ip_lib.device_exists(device_name, self.root_helper, namespace=namespace): self.check_bridge_exists(bridge) ip = ip_lib.IPWrapper(self.root_helper) tap_name = self._get_tap_name(device_name, prefix) if self.conf.ovs_use_veth: # Create ns_dev in a namespace if one is configured. root_dev, ns_dev = ip.add_veth(tap_name, device_name, namespace2=namespace) else: ns_dev = ip.device(device_name) internal = not self.conf.ovs_use_veth self._ovs_add_port(bridge, tap_name, port_id, mac_address, internal=internal) ns_dev.link.set_address(mac_address) if self.conf.network_device_mtu: ns_dev.link.set_mtu(self.conf.network_device_mtu) if self.conf.ovs_use_veth: root_dev.link.set_mtu(self.conf.network_device_mtu) # Add an interface created by ovs to the namespace. if not self.conf.ovs_use_veth and namespace: namespace_obj = ip.ensure_namespace(namespace) namespace_obj.add_device_to_namespace(ns_dev) ns_dev.link.set_up() if self.conf.ovs_use_veth: root_dev.link.set_up() else: LOG.info(_("Device %s already exists"), device_name)
def check_bridge_exists(self, bridge): if not ip_lib.device_exists(bridge): raise exceptions.BridgeDoesNotExist(bridge=bridge)