示例#1
0
 def unplug(self, device_name, bridge=None, namespace=None, prefix=None):
     """Unplug the interface."""
     device = ip_lib.IPDevice(device_name, self.root_helper, namespace)
     try:
         device.link.delete()
         LOG.debug(_("Unplugged interface '%s'"), device_name)
     except RuntimeError:
         LOG.error(_("Failed unplugging interface '%s'"), device_name)
示例#2
0
 def unplug(self, device_name, bridge=None, namespace=None, prefix=None):
     """Unplug the interface."""
     tap_name = self._get_tap_name(device_name, prefix)
     try:
         cmd = ['ivs-ctl', 'del-port', tap_name]
         utils.execute(cmd, self.root_helper)
         device = ip_lib.IPDevice(device_name, self.root_helper, namespace)
         device.link.delete()
         LOG.debug(_("Unplugged interface '%s'"), device_name)
     except RuntimeError:
         LOG.error(_("Failed unplugging interface '%s'"), device_name)
示例#3
0
    def unplug(self, device_name, bridge=None, namespace=None, prefix=None):
        # the port will be deleted by the dhcp agent that will call the plugin
        device = ip_lib.IPDevice(device_name, self.root_helper, namespace)
        try:
            device.link.delete()
        except RuntimeError:
            LOG.error(_("Failed unplugging interface '%s'"), device_name)
        LOG.debug(_("Unplugged interface '%s'"), device_name)

        ip_lib.IPWrapper(self.root_helper,
                         namespace).garbage_collect_namespace()
示例#4
0
    def init_l3(self,
                device_name,
                ip_cidrs,
                namespace=None,
                preserve_ips=None,
                gateway=None,
                extra_subnets=None):
        """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
        """
        if not preserve_ips:
            preserve_ips = []
        if not extra_subnets:
            extra_subnets = []
        device = ip_lib.IPDevice(device_name,
                                 self.root_helper,
                                 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)
            # 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:
                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():
            if ip_cidr not in preserve_ips:
                device.addr.delete(ip_version, ip_cidr)

        if gateway:
            device.route.add_gateway(gateway)

        new_onlink_routes = set(s['cidr'] for s in extra_subnets)
        existing_onlink_routes = set(device.route.list_onlink_routes())
        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)
示例#5
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, self.root_helper)

        try:
            ovs.delete_port(tap_name)
            if self.conf.ovs_use_veth:
                device = ip_lib.IPDevice(device_name, self.root_helper,
                                         namespace)
                device.link.delete()
                LOG.debug(_("Unplugged interface '%s'"), device_name)
        except RuntimeError:
            LOG.error(_("Failed unplugging interface '%s'"), device_name)
示例#6
0
 def _get_device_plugin_tag(self, device_name, namespace=None):
     device = ip_lib.IPDevice(device_name, self.conf.root_helper, namespace)
     return device.link.alias
示例#7
0
 def _set_device_plugin_tag(self, network_id, device_name, namespace=None):
     plugin_tag = self._get_flavor_by_network_id(network_id)
     device = ip_lib.IPDevice(device_name, self.conf.root_helper, namespace)
     device.link.set_alias(plugin_tag)