def port_bind(endpoint_id, port, subnets, network=None, vm_port=None, segmentation_id=None): """Binds the Neutron port to the network interface on the host. :param endpoint_id: the ID of the endpoint as string :param port: the container Neutron port dictionary as returned by python-neutronclient :param subnets: an iterable of all the Neutron subnets which the endpoint is trying to join :param network: the Neutron network which the endpoint is trying to join :param vm_port: the Nova instance port dictionary, as returned by python-neutronclient. Container is running inside this instance (either ipvlan/macvlan or a subport) :param segmentation_id: ID of the segment for container traffic isolation) :returns: the tuple of the names of the veth pair and the tuple of stdout and stderr returned by processutils.execute invoked with the executable script for binding :raises: kuryr.common.exceptions.VethCreationFailure, processutils.ProcessExecutionError """ ip = utils.get_ipdb() port_id = port['id'] _, devname = utils.get_veth_pair_names(port_id) link_iface = nested.get_link_iface(vm_port) with ip.create(ifname=devname, kind=KIND, link=ip.interfaces[link_iface], address=port.get(utils.MAC_ADDRESS_KEY), vlan_id=segmentation_id) as container_iface: utils._configure_container_iface( container_iface, subnets, fixed_ips=port.get(utils.FIXED_IP_KEY)) return None, devname, ('', None)
def port_bind(endpoint_id, port, subnets, network=None, vm_port=None, segmentation_id=None, **kwargs): """Binds the Neutron port to the network interface on the host. :param endpoint_id: the ID of the endpoint as string :param port: the container Neutron port dictionary as returned by python-neutronclient :param subnets: an iterable of all the Neutron subnets which the endpoint is trying to join :param network: the Neutron network which the endpoint is trying to join :param vm_port: the Nova instance port dictionary, as returned by python-neutronclient. Container port under binding is running inside this instance (either ipvlan/macvlan or a subport) :param segmentation_id: ID of the segment for container traffic isolation) :param kwargs: Additional driver-specific arguments :returns: the tuple of the names of the veth pair and the tuple of stdout and stderr returned by processutils.execute invoked with the executable script for binding :raises: kuryr.common.exceptions.VethCreationFailure, processutils.ProcessExecutionError """ ip = utils.get_ipdb() port_id = port['id'] host_ifname, container_ifname = utils.get_veth_pair_names(port_id) mtu = utils.get_mtu_from_network(network) try: with ip.create(ifname=host_ifname, kind=KIND, reuse=True, peer=container_ifname) as host_veth: if not utils.is_up(host_veth): host_veth.up() with ip.interfaces[container_ifname] as container_veth: utils._configure_container_iface( container_veth, subnets, fixed_ips=port.get(utils.FIXED_IP_KEY), mtu=mtu, hwaddr=port[utils.MAC_ADDRESS_KEY].lower()) except pyroute2.CreateException: raise exceptions.VethCreationFailure( 'Virtual device creation failed.') except pyroute2.CommitException: raise exceptions.VethCreationFailure( 'Could not configure the container virtual device networking.') try: stdout, stderr = _configure_host_iface( host_ifname, endpoint_id, port_id, port['network_id'], port.get('project_id') or port['tenant_id'], port[utils.MAC_ADDRESS_KEY], kind=port.get(constants.VIF_TYPE_KEY), details=port.get(constants.VIF_DETAILS_KEY)) except Exception: with excutils.save_and_reraise_exception(): utils.remove_device(host_ifname) return host_ifname, container_ifname, (stdout, stderr)
def port_bind(endpoint_id, port, subnets, network=None, vm_port=None, segmentation_id=None): """Binds the Neutron port to the network interface on the host. :param endpoint_id: the ID of the endpoint as string :param port: the container Neutron port dictionary as returned by python-neutronclient :param subnets: an iterable of all the Neutron subnets which the endpoint is trying to join :param network: the Neutron network which the endpoint is trying to join :param vm_port: the Nova instance dictionary, as returned by python-neutronclient. Container port under binding is running inside this instance (either ipvlan/macvlan or a subport) :param segmentation_id: ID of the segment for container traffic isolation) :returns: the tuple of the names of the veth pair and the tuple of stdout and stderr returned by processutils.execute invoked with the executable script for binding :raises: kuryr.common.exceptions.VethCreationFailure, processutils.ProcessExecutionError """ ip = utils.get_ipdb() port_id = port['id'] host_ifname, container_ifname = utils.get_veth_pair_names(port_id) mtu = utils.get_mtu_from_network(network) try: with ip.create(ifname=host_ifname, kind=KIND, reuse=True, peer=container_ifname) as host_veth: if not utils.is_up(host_veth): host_veth.up() with ip.interfaces[container_ifname] as container_veth: utils._configure_container_iface( container_veth, subnets, fixed_ips=port.get(utils.FIXED_IP_KEY), mtu=mtu, hwaddr=port[utils.MAC_ADDRESS_KEY].lower()) except pyroute2.CreateException: raise exceptions.VethCreationFailure( 'Virtual device creation failed.') except pyroute2.CommitException: raise exceptions.VethCreationFailure( 'Could not configure the container virtual device networking.') try: stdout, stderr = _configure_host_iface( host_ifname, endpoint_id, port_id, port['network_id'], port.get('project_id') or port['tenant_id'], port[utils.MAC_ADDRESS_KEY], kind=port.get(constants.VIF_TYPE_KEY), details=port.get(constants.VIF_DETAILS_KEY)) except Exception: with excutils.save_and_reraise_exception(): utils.remove_device(host_ifname) return host_ifname, container_ifname, (stdout, stderr)
def get_link_iface(port): """Gets the name of the interface to link the container virtual devices""" link = cfg.CONF.binding.link_iface if not link: # Guess the name from the port hwaddr ip = utils.get_ipdb() for name, data in ip.interfaces.items(): if data['address'] == port[utils.MAC_ADDRESS_KEY]: link = data['ifname'] break return link
def _get_port_from_host_iface(self, ifname): """Returns the Neutron port associated to ifname or raises otherwise. Returns the Neutron port associated to ifname if such port exists, a exceptions.KuryrException if it does not, n_exceptions.NeutronClientException on errors. :returns: a Neutron port dictionary as returned by python-neutronclient or None :raises: exceptions.KuryrException neutronclient.common.exceptions.NeutronClientException """ ip = utils.get_ipdb() mac_address = ip.interfaces.get(ifname, {}).get('address', None) if mac_address: ports = app.neutron.list_ports(mac_address=mac_address) if ports['ports']: return ports['ports'][0] raise exceptions.KuryrException("Cannot find a Neutron port " "associated to interface name {0}".format(ifname))
def _get_port_from_host_iface(self, ifname): """Returns the Neutron port associated to ifname or raises otherwise. Returns the Neutron port associated to ifname if such port exists, a exceptions.KuryrException if it does not, n_exceptions.NeutronClientException on errors. :returns: a Neutron port dictionary as returned by python-neutronclient or None :raises: exceptions.KuryrException neutronclient.common.exceptions.NeutronClientException """ ip = utils.get_ipdb() mac_address = ip.interfaces.get(ifname, {}).get('address', None) if mac_address: ports = app.neutron.list_ports(mac_address=mac_address) if ports['ports']: return ports['ports'][0] raise exceptions.KuryrException( "Cannot find a Neutron port " "associated to interface name {0}".format(ifname))
def test_get_ipdb(self): ip = utils.get_ipdb() self.assertEqual(ip, utils.get_ipdb())
def port_bind(endpoint_id, port, subnets, network=None, nested_port=None): """Binds the Neutron port to the network interface on the host. :param endpoint_id: the ID of the endpoint as string :param port: the instance Neutron port dictionary as returned by python-neutronclient :param subnets: an iterable of all the Neutron subnets which the endpoint is trying to join :param network: the Neutron network which the endpoint is trying to join :param nested_port: the dictionary, as returned by python-neutronclient, of the port that that is used when running inside another instance (either ipvlan/macvlan or a subport) :returns: the tuple of the names of the veth pair and the tuple of stdout and stderr returned by processutils.execute invoked with the executable script for binding :raises: kuryr.common.exceptions.VethCreationFailure, processutils.ProcessExecutionError """ ip = utils.get_ipdb() port_id = port['id'] host_ifname, container_ifname = utils.get_veth_pair_names(port_id) if network is None: mtu = DEFAULT_NETWORK_MTU else: mtu = network.get('mtu', DEFAULT_NETWORK_MTU) try: with ip.create(ifname=host_ifname, kind=KIND, reuse=True, peer=container_ifname) as host_veth: if not utils.is_up(host_veth): host_veth.up() with ip.interfaces[container_ifname] as container_veth: utils._configure_container_iface( container_veth, subnets, fixed_ips=port.get(utils.FIXED_IP_KEY), mtu=mtu, hwaddr=port[utils.MAC_ADDRESS_KEY].lower()) except pyroute2.CreateException: raise exceptions.VethCreationFailure('Virtual device creation failed.') except pyroute2.CommitException: raise exceptions.VethCreationFailure( 'Could not configure the container virtual device networking.') try: stdout, stderr = _configure_host_iface( host_ifname, endpoint_id, port_id, port['network_id'], port['tenant_id'], port[utils.MAC_ADDRESS_KEY], kind=port.get(VIF_TYPE_KEY), details=port.get(VIF_DETAILS_KEY)) except Exception: with excutils.save_and_reraise_exception(): utils.remove_device(host_ifname) return host_ifname, container_ifname, (stdout, stderr)