예제 #1
0
    def get_ns_info(self):
        """Populate namespace information dict."""
        ns_info = {}
        for line in cli_helpers.get_ip_netns():
            ret = re.compile(r"^([a-z0-9]+)-([0-9a-z\-]+)\s+.+").match(line)
            if ret:
                if ret[1] in ns_info:
                    ns_info[ret[1]] += 1
                else:
                    ns_info[ret[1]] = 1

        if ns_info:
            NETWORK_INFO["namespaces"] = ns_info
예제 #2
0
    def host_interface_exists(self, iface, check_namespaces=True):
        _interfaces = self._get_interface_names(cli_helpers.get_ip_addr())
        if iface in _interfaces:
            return True

        if not check_namespaces:
            return False

        for ns in cli_helpers.get_ip_netns():
            interfaces = self._get_interface_names(
                                         cli_helpers.get_ip_addr(namespace=ns))
            if iface in interfaces:
                return True

        return False
예제 #3
0
    def get_host_interfaces(self, include_namespaces=False):
        """Returns a list of all interfaces on the host including ones found in
        namespaces created with ip netns.
        """
        _interfaces = []
        _interfaces += self._get_interface_names(cli_helpers.get_ip_addr())
        if not include_namespaces:
            return _interfaces

        for ns in cli_helpers.get_ip_netns():
            ns_name = ns.partition(" ")[0]
            _interfaces += self._get_interface_names(
                                    cli_helpers.get_ip_addr(namespace=ns_name))

        return _interfaces