当前位置: 首页>>代码示例>>Python>>正文


Python util.get_host_ips函数代码示例

本文整理汇总了Python中pycalico.util.get_host_ips函数的典型用法代码示例。如果您正苦于以下问题:Python get_host_ips函数的具体用法?Python get_host_ips怎么用?Python get_host_ips使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_host_ips函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_host_ips_exclude

  def test_get_host_ips_exclude(self, m_check_output):
    # Exclude "docker0"
    m_check_output.return_value = MOCK_IP_ADDR
    addrs = get_host_ips(version=4, exclude=["docker0"])
    m_check_output.assert_called_once_with(["ip", "-4", "addr"])
    m_check_output.reset_mock()
    self.assertEquals(addrs, ['172.24.114.18'])

    addrs = get_host_ips(version=6, exclude=["docker0"])
    m_check_output.assert_called_once_with(["ip", "-6", "addr"])
    m_check_output.reset_mock()
    self.assertEquals(addrs, ['2620:104:4008:69:8d7c:499f:2f04:9e55',
                  '2620:104:4008:69:a00:27ff:fe73:c8d0',
                  'fe80::a00:27ff:fe73:c8d0'])

    # Exclude empty list
    addrs = get_host_ips(version=4, exclude=[""])
    m_check_output.assert_called_once_with(["ip", "-4", "addr"])
    m_check_output.reset_mock()
    self.assertEquals(addrs, ['172.24.114.18', '172.17.42.1'])

    addrs = get_host_ips(version=6, exclude=[""])
    m_check_output.assert_called_once_with(["ip", "-6", "addr"])
    m_check_output.reset_mock()
    self.assertEquals(addrs, ['2620:104:4008:69:8d7c:499f:2f04:9e55',
                  '2620:104:4008:69:a00:27ff:fe73:c8d0',
                  'fe80::a00:27ff:fe73:c8d0',
                  'fe80::188f:d6ff:fe1f:1482'])
开发者ID:robbrockbank,项目名称:libcalico,代码行数:28,代码来源:test_util.py

示例2: test_get_host_ips_loopback_only

  def test_get_host_ips_loopback_only(self, m_check_output):
    # Test Loopback
    m_check_output.return_value = MOCK_IP_ADDR_LOOPBACK
    addrs = get_host_ips(version=4)
    m_check_output.assert_called_once_with(["ip", "-4", "addr"])
    m_check_output.reset_mock()
    self.assertEquals(addrs, [])

    addrs = get_host_ips(version=6)
    m_check_output.assert_called_once_with(["ip", "-6", "addr"])
    m_check_output.reset_mock()
    self.assertEquals(addrs, [])
开发者ID:robbrockbank,项目名称:libcalico,代码行数:12,代码来源:test_util.py

示例3: test_get_host_ips_loopback_only

    def test_get_host_ips_loopback_only(self, m_check_output):
        '''Test get_host_ips with loopback'''
        # Test IPv4
        m_check_output.return_value = MOCK_IP_ADDR_LOOPBACK
        addrs = util.get_host_ips(version=4)
        m_check_output.assert_called_once_with(["ip", "-4", "addr"])
        m_check_output.reset_mock()
        self.assertEqual(addrs, [])

        # Test IPv6
        addrs = util.get_host_ips(version=6)
        m_check_output.assert_called_once_with(["ip", "-6", "addr"])
        m_check_output.reset_mock()
        self.assertEqual(addrs, [])
开发者ID:mkumatag,项目名称:libcalico,代码行数:14,代码来源:test_util.py

示例4: warn_if_unknown_ip

def warn_if_unknown_ip(ip, ip6):
    """
    Prints a warning message if the IP addresses are not assigned to interfaces
    on the current host.

    :param ip: IPv4 address which should be present on the host.
    :param ip6: IPv6 address which should be present on the host.
    :return: None
    """
    if ip and IPAddress(ip) not in get_host_ips(version=4, exclude=["docker0"]):
        print "WARNING: Could not confirm that the provided IPv4 address is" " assigned to this host."

    if ip6 and IPAddress(ip6) not in get_host_ips(version=6, exclude=["docker0"]):
        print "WARNING: Could not confirm that the provided IPv6 address is" " assigned to this host."
开发者ID:caseydavenport,项目名称:calico-containers,代码行数:14,代码来源:startup.py

示例5: _get_node_ip

    def _get_node_ip(self):
        """ 
        Determine the IP for the host node.
        """
        # Compile list of addresses on network, return the first entry.
        # Try IPv4 and IPv6.
        addrs = get_host_ips(version=4) or get_host_ips(version=6)

        try:
            addr = addrs[0]
            print('Using IP Address %s' % (addr))
            return addr
        except IndexError:
            # If both get_host_ips return empty lists, print message and exit.
            print('No Valid IP Address Found for Host - cannot configure networking for pod %s' % (self.pod_name))
            sys.exit(1)
开发者ID:kriss9,项目名称:calico-docker,代码行数:16,代码来源:calico_kubernetes.py

示例6: test_get_host_ips_exclude_docker_prefix

    def test_get_host_ips_exclude_docker_prefix(self, m_check_output):
        '''Test get_host_ips exclude "docker0.*'''
        # Test IPv4
        m_check_output.return_value = MOCK_IP_ADDR_DOCKER_NONE
        addrs = get_host_ips(version=4, exclude=["docker0.*"])
        m_check_output.assert_called_once_with(["ip", "-4", "addr"])
        m_check_output.reset_mock()
        self.assertEquals(addrs, ['172.24.114.18'])

        # Test IPv6
        addrs = get_host_ips(version=6, exclude=["docker0.*"])
        m_check_output.assert_called_once_with(["ip", "-6", "addr"])
        m_check_output.reset_mock()
        self.assertEquals(addrs, ['2620:104:4008:69:8d7c:499f:2f04:9e55',
                                  '2620:104:4008:69:a00:27ff:fe73:c8d0',
                                  'fe80::a00:27ff:fe73:c8d0'])
开发者ID:TrimBiggs,项目名称:libcalico,代码行数:16,代码来源:test_util.py

示例7: test_get_host_ips_standard

  def test_get_host_ips_standard(self, m_check_output):
    # Test IPv4
    m_check_output.return_value = MOCK_IP_ADDR
    addrs = get_host_ips(version=4)
    m_check_output.assert_called_once_with(["ip", "-4", "addr"])
    m_check_output.reset_mock()
    self.assertEquals(addrs, ['172.24.114.18', '172.17.42.1'])

    # Test IPv6
    addrs = get_host_ips(version=6)
    m_check_output.assert_called_once_with(["ip", "-6", "addr"])
    m_check_output.reset_mock()
    self.assertEquals(addrs, ['2620:104:4008:69:8d7c:499f:2f04:9e55',
                  '2620:104:4008:69:a00:27ff:fe73:c8d0',
                  'fe80::a00:27ff:fe73:c8d0',
                  'fe80::188f:d6ff:fe1f:1482'])
开发者ID:robbrockbank,项目名称:libcalico,代码行数:16,代码来源:test_util.py

示例8: get_ip

def get_ip(v6=False):
    """
    Return a string of the IP of the hosts interface.
    Try to get the local IP from the environment variables.  This allows
    testers to specify the IP address in cases where there is more than one
    configured IP address for the test system.
    """
    env = LOCAL_IPv6_ENV if v6 else LOCAL_IP_ENV
    ip = os.environ.get(env)
    if not ip:
        try:
            # No env variable set; try to auto detect.
            socket_type = socket.AF_INET6 if v6 else socket.AF_INET
            s = socket.socket(socket_type, socket.SOCK_DGRAM)
            remote_ip = "2001:4860:4860::8888" if v6 else "8.8.8.8"
            s.connect((remote_ip, 0))
            ip = s.getsockname()[0]
            s.close()
        except BaseException:
            # Failed to connect, just try to get the address from the interfaces
            version = 6 if v6 else 4
            ips = get_host_ips(version)
            if ips:
                ip = ips[0]

    return ip
开发者ID:xuzhaokui,项目名称:calico-docker,代码行数:26,代码来源:utils.py

示例9: test_get_host_ips_exclude_docker

    def test_get_host_ips_exclude_docker(self, m_check_output):
        '''Test get_host_ips exclude "docker0"'''
        # Test IPv4
        m_check_output.return_value = MOCK_IP_ADDR
        addrs = get_host_ips(version=4, exclude=["docker0"])
        m_check_output.assert_called_once_with(["ip", "-4", "addr"])
        m_check_output.reset_mock()
        self.assertEquals(addrs, ["172.24.114.18"])

        # Test IPv6
        addrs = get_host_ips(version=6, exclude=["docker0"])
        m_check_output.assert_called_once_with(["ip", "-6", "addr"])
        m_check_output.reset_mock()
        self.assertEquals(
            addrs,
            ["2620:104:4008:69:8d7c:499f:2f04:9e55", "2620:104:4008:69:a00:27ff:fe73:c8d0", "fe80::a00:27ff:fe73:c8d0"],
        )
开发者ID:fasaxc,项目名称:libcalico,代码行数:17,代码来源:test_util.py

示例10: _get_node_ip

    def _get_node_ip(self):
        """
        Determine the IP for the host node.
        """
        # Compile list of addresses on network, return the first entry.
        # Try IPv4 and IPv6.
        addrs = get_host_ips(version=4) or get_host_ips(version=6)

        try:
            addr = addrs[0]
            logger.debug("Node's IP address: %s", addr)
            return addr
        except IndexError:
            # If both get_host_ips return empty lists, print message and exit.
            logger.exception('No Valid IP Address Found for Host - cannot '
                             'configure networking for pod %s. '
                             'Exiting', self.pod_name)
            sys.exit(1)
开发者ID:tomdee,项目名称:calico-kubernetes,代码行数:18,代码来源:calico_kubernetes.py

示例11: test_get_host_ips_exclude_empty

    def test_get_host_ips_exclude_empty(self, m_check_output):
        '''Test get_host_ips exclude empty list'''
        # Test IPv4
        m_check_output.return_value = MOCK_IP_ADDR
        addrs = get_host_ips(version=4, exclude=["^$"])
        m_check_output.assert_called_once_with(["ip", "-4", "addr"])
        m_check_output.reset_mock()
        self.assertEquals(addrs, [IPAddress('172.24.114.18'),
                                  IPAddress('172.17.42.1')])

        # Test IPv6
        addrs = get_host_ips(version=6, exclude=["^$"])
        m_check_output.assert_called_once_with(["ip", "-6", "addr"])
        m_check_output.reset_mock()
        self.assertEquals(addrs,
                          [IPAddress('2620:104:4008:69:8d7c:499f:2f04:9e55'),
                           IPAddress('2620:104:4008:69:a00:27ff:fe73:c8d0'),
                           IPAddress('fe80::a00:27ff:fe73:c8d0'),
                           IPAddress('fe80::188f:d6ff:fe1f:1482')])
开发者ID:HuKeping,项目名称:libcalico,代码行数:19,代码来源:test_util.py

示例12: test_get_host_ips_standard

    def test_get_host_ips_standard(self, m_check_output):
        '''Test general case for get_host_ips'''
        # Test IPv4
        m_check_output.return_value = MOCK_IP_ADDR
        addrs = util.get_host_ips(version=4)
        m_check_output.assert_called_once_with(["ip", "-4", "addr"])
        m_check_output.reset_mock()
        self.assertEqual(addrs, [IPAddress('172.24.114.18'),
                                 IPAddress('172.17.42.1')])

        # Test IPv6
        addrs = util.get_host_ips(version=6)
        m_check_output.assert_called_once_with(["ip", "-6", "addr"])
        m_check_output.reset_mock()
        self.assertEqual(addrs,
                         [IPAddress('2620:104:4008:69:8d7c:499f:2f04:9e55'),
                          IPAddress('2620:104:4008:69:a00:27ff:fe73:c8d0'),
                          IPAddress('fe80::a00:27ff:fe73:c8d0'),
                          IPAddress('fe80::188f:d6ff:fe1f:1482')])
开发者ID:mkumatag,项目名称:libcalico,代码行数:19,代码来源:test_util.py

示例13: test_get_host_ips_standard

    def test_get_host_ips_standard(self, m_check_output):
        """Test general case for get_host_ips"""
        # Test IPv4
        m_check_output.return_value = MOCK_IP_ADDR
        addrs = get_host_ips(version=4)
        m_check_output.assert_called_once_with(["ip", "-4", "addr"])
        m_check_output.reset_mock()
        self.assertEquals(addrs, ["172.24.114.18", "172.17.42.1"])

        # Test IPv6
        addrs = get_host_ips(version=6)
        m_check_output.assert_called_once_with(["ip", "-6", "addr"])
        m_check_output.reset_mock()
        self.assertEquals(
            addrs,
            [
                "2620:104:4008:69:8d7c:499f:2f04:9e55",
                "2620:104:4008:69:a00:27ff:fe73:c8d0",
                "fe80::a00:27ff:fe73:c8d0",
                "fe80::188f:d6ff:fe1f:1482",
            ],
        )
开发者ID:fasaxc,项目名称:libcalico,代码行数:22,代码来源:test_util.py

示例14: create_profile_with_default_mesos_rules

def create_profile_with_default_mesos_rules(profile):
    _log.info("Autocreating profile %s", profile)
    datastore.create_profile(profile)
    prof = datastore.get_profile(profile)
    # Set up the profile rules to allow incoming connections from the host
    # since the slave process will be running there.
    # Also allow connections from others in the profile.
    # Deny other connections (default, so not explicitly needed).
    # TODO: confirm that we're not getting more interfaces than we bargained for
    ipv4 = get_host_ips(4, exclude=["docker0"]).pop()
    host_net = ipv4 + "/32"
    _log.info("adding accept rule for %s" % host_net)
    allow_slave = Rule(action="allow", src_net=host_net)
    allow_self = Rule(action="allow", src_tag=profile)
    allow_all = Rule(action="allow")
    prof.rules = Rules(id=profile,
                       inbound_rules=[allow_slave, allow_self],
                       outbound_rules=[allow_all])
    datastore.profile_update_rules(prof)
开发者ID:spikecurtis,项目名称:calico-mesos,代码行数:19,代码来源:calico_mesos.py

示例15: test_isolate

    def test_isolate(self):
        # Test isolate
        hostname = socket.gethostname()

        indata = {
            "command": "isolate",
            "args": {
                "hostname": hostname,
                "container-id": self.container_id,
                "ipv4_addrs": ["192.168.23.4"],
                "ipv6_addrs": [],
                "netgroups": ["prod", "frontend"],
                "labels": {
                    "rack": "3A",
                    "pop": "houston"
                },
                "pid": 3789
            }
        }

        # Prepare network environment
        calicoctl("pool", "add", "192.168.0.0/16")

        # Set up bgp host configuration
        calicoctl("node")

        output = self.binary_exec(indata)
        self.assertEqual(self.stderr, '')
        self.assertEqual(output, error_msg())

        # Check if the endpoint was correctly written to etcd
        host = "127.0.0.1"
        port = 4001
        etcd_client = etcd.Client(host=host, port=port)
        leaves = etcd_client.read('/calico/v1/host/%s/workload/%s/%s/endpoint' % \
                                  (hostname, "mesos", self.container_id), recursive=True).leaves
        values = [leaf for leaf in leaves]
        self.assertEqual(len(values), 1, "Only 1 endpoint should exist: %d were found" % len(values))
        endpoint = values.pop()
        endpoint_dict = json.loads(endpoint.value)
        self.assertEqual(endpoint_dict["ipv4_gateway"], get_host_ips(exclude="docker0").pop())
        self.assertEqual(endpoint_dict["ipv4_nets"], ["192.168.23.4"])
        self.assertEqual(endpoint_dict["profile_ids"], ["prod", "frontend"])
开发者ID:insequent,项目名称:calico-mesos,代码行数:43,代码来源:test_mesos.py


注:本文中的pycalico.util.get_host_ips函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。