Esempio n. 1
0
 def unplug(self, device_name, bridge=None, namespace=None, prefix=None):
     """Unplug the interface."""
     device = ip_lib.IPDevice(device_name, namespace=namespace)
     try:
         device.link.delete()
         LOG.debug("Unplugged interface '%s'", device_name)
     except RuntimeError:
         LOG.error(("Failed unplugging interface '%s'"), device_name)
Esempio n. 2
0
 def get_local_port_mac(self):
     """Retrieve the mac of the bridge's local port."""
     address = ip_lib.IPDevice(self.br_name).link.address
     if address:
         return address
     else:
         msg = _('Unable to determine mac address for %s') % self.br_name
         raise Exception(msg)
Esempio n. 3
0
    def init_l3(self,
                device_name,
                ip_cidrs,
                namespace=None,
                preserve_ips=[],
                gateway_ips=None,
                extra_subnets=[],
                enable_ra_on_gw=False):
        """Set the L3 settings for the interface using data from the port.

        ip_cidrs: list of 'X.X.X.X/YY' strings
        preserve_ips: list of ip cidrs that should not be removed from device
        gateway_ips: For gateway ports, list of external gateway ip addresses
        enable_ra_on_gw: Boolean to indicate configuring acceptance of IPv6 RA
        """
        device = ip_lib.IPDevice(device_name, namespace=namespace)

        previous = set()
        for address in device.addr.list(scope='global', filters=['permanent']):
            previous.add(address['cidr'])

        # add new addresses
        for ip_cidr in ip_cidrs:

            net = netaddr.IPNetwork(ip_cidr)
            # Convert to compact IPv6 address because the return values of
            # "ip addr list" are compact.
            if net.version == 6:
                ip_cidr = str(net)
            if ip_cidr in previous:
                previous.remove(ip_cidr)
                continue

            device.addr.add(ip_cidr)

        # clean up any old addresses
        for ip_cidr in previous:
            if ip_cidr not in preserve_ips:
                device.addr.delete(ip_cidr)
                self.delete_conntrack_state(namespace=namespace, ip=ip_cidr)

        for gateway_ip in gateway_ips or []:
            device.route.add_gateway(gateway_ip)

        if enable_ra_on_gw:
            self.configure_ipv6_ra(namespace, device_name)

        new_onlink_routes = set(s['cidr'] for s in extra_subnets)
        existing_onlink_routes = set(
            device.route.list_onlink_routes(n_const.IP_VERSION_4) +
            device.route.list_onlink_routes(n_const.IP_VERSION_6))
        for route in new_onlink_routes - existing_onlink_routes:
            device.route.add_onlink_route(route)
        for route in existing_onlink_routes - new_onlink_routes:
            device.route.delete_onlink_route(route)
Esempio n. 4
0
    def unplug(self, device_name, bridge=None, namespace=None, prefix=None):
        """Unplug the interface."""
        if not bridge:
            bridge = self.conf.ovs_integration_bridge

        tap_name = self._get_tap_name(device_name, prefix)
        self.check_bridge_exists(bridge)
        ovs = ovs_lib.OVSBridge(bridge)

        try:
            ovs.delete_port(tap_name)
            if self.conf.ovs_use_veth:
                device = ip_lib.IPDevice(device_name, namespace=namespace)
                device.link.delete()
                LOG.debug("Unplugged interface '%s'", device_name)
        except RuntimeError:
            LOG.error(("Failed unplugging interface '%s'"), device_name)