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


Python ipaddr.IPAddress方法代码示例

本文整理汇总了Python中ipaddr.IPAddress方法的典型用法代码示例。如果您正苦于以下问题:Python ipaddr.IPAddress方法的具体用法?Python ipaddr.IPAddress怎么用?Python ipaddr.IPAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ipaddr的用法示例。


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

示例1: test_get_node_cpu_times

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPAddress [as 别名]
def test_get_node_cpu_times(self):
        """
        Success results in output of dictionary containing process names.
        """
        d = get_node_cpu_times(
            Clock(),
            _LocalRunner(),
            Node(uuid=uuid4(), public_address=IPAddress('10.0.0.1')),
            _pid_1_name,
            [_pid_1_name],
        )

        def check(result):
            self.assertEqual(
                set(result.keys()), {_pid_1_name, WALLCLOCK_LABEL}
            )

        d.addCallback(check)

        return d 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:22,代码来源:test_cputime.py

示例2: test_scenario_throws_exception_when_already_started

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPAddress [as 别名]
def test_scenario_throws_exception_when_already_started(self, _logger):
        """
        start method in the ``RequestLoadScenario`` throws a
        ``RequestScenarioAlreadyStarted`` if the scenario is already started.
        """
        c = Clock()

        node1 = Node(uuid=uuid4(), public_address=IPAddress('10.0.0.1'))
        node2 = Node(uuid=uuid4(), public_address=IPAddress('10.0.0.2'))
        cluster = BenchmarkCluster(
            node1.public_address,
            lambda reactor: FakeFlockerClient([node1, node2]),
            {node1.public_address, node2.public_address},
            default_volume_size=DEFAULT_VOLUME_SIZE
        )

        sample_size = 5
        s = read_request_load_scenario(c, cluster, sample_size=sample_size)

        s.start()

        self.assertRaises(RequestScenarioAlreadyStarted, s.start) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:24,代码来源:test_read_request_load.py

示例3: test_empty_cluster

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPAddress [as 别名]
def test_empty_cluster(self):
        """
        CreateDataset fails if no nodes in cluster.
        """
        control_service = FakeFlockerClient()

        cluster = BenchmarkCluster(
            IPAddress('10.0.0.1'),
            lambda reactor: control_service,
            {},
            None,
        )

        d = CreateDataset(Clock(), cluster).get_probe()

        self.failureResultOf(d, EmptyClusterError) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:18,代码来源:test_create_dataset.py

示例4: list_nodes

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPAddress [as 别名]
def list_nodes(self):
        request = self._request(
            b"GET", b"/state/nodes", None, {OK}
        )

        def to_nodes(result):
            """
            Turn the list of dicts into ``Node`` instances.
            """
            nodes = []
            for node_dict in result:
                node = Node(
                    uuid=UUID(hex=node_dict['uuid'], version=4),
                    public_address=IPAddress(node_dict['host']),
                )
                nodes.append(node)
            return nodes
        request.addCallback(to_nodes)

        return request 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:22,代码来源:_client.py

示例5: get_all_ips

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPAddress [as 别名]
def get_all_ips():
    """
    Find all IPs for this machine.

    :return: ``set`` of IP addresses (``IPAddress``).
    """
    ips = set()
    interfaces = netifaces.interfaces()
    for interface in interfaces:
        addresses = netifaces.ifaddresses(interface)
        for address_family in (netifaces.AF_INET, netifaces.AF_INET6):
            family_addresses = addresses.get(address_family)
            if not family_addresses:
                continue
            for address in family_addresses:
                ips.add(ipaddress_from_string(address['addr']))
    return ips 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:19,代码来源:_net.py

示例6: SetIP6Comment

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPAddress [as 别名]
def SetIP6Comment(self, comment, ip):
        """ Set comment for IPv6 address """

        # Create address object using ipaddr
        addr6 = ipaddr.IPAddress(ip)
        # Create IPv6 format for Mysql
        db_ip6_format = "".join(str(x) for x in addr6.exploded.split(':')).upper()

        sql = "SELECT comment FROM IPv6Address WHERE HEX(ip) = '%s'" % (db_ip6_format)
        result = self.db_query_one(sql)

        if result is not None:
            sql = "UPDATE IPv6Address SET comment = '%s' WHERE HEX(ip) = '%s'" % (comment, db_ip6_format)
        else:
            sql = "INSERT INTO IPv6Address (ip, comment) VALUES (UNHEX('%s'), '%s')" % (db_ip6_format, comment)

        self.db_insert(sql) 
开发者ID:rvojcik,项目名称:rtapi,代码行数:19,代码来源:__init__.py

示例7: __init__

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPAddress [as 别名]
def __init__(self, vid, conf=None):
        if conf is None:
            conf = {}
        self.vid = vid
        self.tagged = []
        self.untagged = []
        self.name = conf.setdefault('name', str(vid))
        self.description = conf.setdefault('description', self.name)
        self.controller_ips = conf.setdefault('controller_ips', [])
        if self.controller_ips:
            self.controller_ips = [
                ipaddr.IPNetwork(ip) for ip in self.controller_ips]
        self.unicast_flood = conf.setdefault('unicast_flood', True)
        self.routes = conf.setdefault('routes', {})
        self.ipv4_routes = {}
        self.ipv6_routes = {}
        if self.routes:
            self.routes = [route['route'] for route in self.routes]
            for route in self.routes:
                ip_gw = ipaddr.IPAddress(route['ip_gw'])
                ip_dst = ipaddr.IPNetwork(route['ip_dst'])
                assert(ip_gw.version == ip_dst.version)
                if ip_gw.version == 4:
                    self.ipv4_routes[ip_dst] = ip_gw
                else:
                    self.ipv6_routes[ip_dst] = ip_gw
        self.arp_cache = {}
        self.nd_cache = {}
        self.max_hosts = conf.setdefault('max_hosts', None)
        self.host_cache = {} 
开发者ID:sdn-ixp,项目名称:iSDX,代码行数:32,代码来源:vlan.py

示例8: __init__

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPAddress [as 别名]
def __init__(self, server_address, handler, *args, **kwargs):
        self.session = kwargs.pop("session")
        (address, _) = server_address
        version = ipaddr.IPAddress(address).version
        if version == 4:
            self.address_family = socket.AF_INET
        elif version == 6:
            self.address_family = socket.AF_INET6

        http.server.HTTPServer.__init__(
            self, server_address, handler, *args, **kwargs) 
开发者ID:google,项目名称:rekall,代码行数:13,代码来源:http_server.py

示例9: from_cluster_yaml

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPAddress [as 别名]
def from_cluster_yaml(cls, path):
        """
        Create a cluster from Quick Start Installer files.

        :param FilePath path: directory containing Quick Start Installer
            ``cluster.yml`` and certificate files.
        :return: A ``BenchmarkCluster`` instance.
        """
        with path.child('cluster.yml').open() as f:
            cluster = yaml.safe_load(f)
        validate_cluster_configuration(cluster)
        control_node_address = cluster['control_node']
        public_addresses = {
            IPAddress(node['private']): IPAddress(node['public'])
            for node in cluster['agent_nodes']
        }
        control_service = partial(
            FlockerClient,
            host=control_node_address,
            port=4523,
            ca_cluster_path=path.child('cluster.crt'),
            cert_path=path.child('user.crt'),
            key_path=path.child('user.key')
        )
        return cls(
            IPAddress(control_node_address), control_service, public_addresses,
            None,
        ) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:30,代码来源:cluster.py

示例10: public_address

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPAddress [as 别名]
def public_address(self, hostname):
        """
        Convert a node's internal hostname to a public address.  If the
        hostname does not exist in ``_public_addresses``, just return the
        hostname, and hope it is public.

        :param IPAddress hostname: Hostname for Flocker node.
        :return IPAddress: Public IP address for node.
        """
        return self._public_addresses.get(hostname, hostname) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:12,代码来源:cluster.py

示例11: test_get_node_init_process_name

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPAddress [as 别名]
def test_get_node_init_process_name(self):
        """
        Success results in output of string containing name of process 1.
        """
        d = get_node_init_process_name(
            _LocalRunner(),
            Node(uuid=uuid4(), public_address=IPAddress('10.0.0.1')),
        )

        def check(result):
            self.assertEqual(result, _pid_1_name)
        d.addCallback(check)

        return d 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:16,代码来源:test_cputime.py

示例12: test_cpu_time

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPAddress [as 别名]
def test_cpu_time(self):
        """
        Fake Flocker cluster gives expected results.
        """
        clock = Clock()
        node1 = Node(uuid=uuid4(), public_address=IPAddress('10.0.0.1'))
        node2 = Node(uuid=uuid4(), public_address=IPAddress('10.0.0.2'))
        metric = CPUTime(
            clock,
            BenchmarkCluster(
                IPAddress('10.0.0.1'),
                lambda reactor: FakeFlockerClient([node1, node2]),
                {},
                None,
            ),
            _LocalRunner(),
            processes=[_pid_1_name]
        )
        d = metric.measure(lambda: clock.advance(5))

        # Although it is unlikely, it's possible that we could get a CPU
        # time != 0, so filter values out.
        def remove_process_times(node_cpu_times):
            for process_times in node_cpu_times.values():
                if process_times:
                    for process in process_times:
                        if process != WALLCLOCK_LABEL:
                            process_times[process] = 0
            return node_cpu_times
        d.addCallback(remove_process_times)

        def check(result):
            self.assertEqual(
                result,
                {
                    '10.0.0.1': {_pid_1_name: 0, WALLCLOCK_LABEL: 5},
                    '10.0.0.2': {_pid_1_name: 0, WALLCLOCK_LABEL: 5}
                }
            )
        d.addCallback(check)
        return d 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:43,代码来源:test_cputime.py

示例13: make_cluster

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPAddress [as 别名]
def make_cluster(self, make_flocker_client):
        """
        Create a cluster that can be used by the scenario tests.
        """
        node1 = Node(uuid=uuid4(), public_address=IPAddress('10.0.0.1'))
        node2 = Node(uuid=uuid4(), public_address=IPAddress('10.0.0.2'))
        return BenchmarkCluster(
            node1.public_address,
            lambda reactor: make_flocker_client(
                FakeFlockerClient([node1, node2]), reactor
            ),
            {node1.public_address, node2.public_address},
            default_volume_size=DEFAULT_VOLUME_SIZE,
        ) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:16,代码来源:test_read_request_load.py

示例14: test_read_request_load_succeeds

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPAddress [as 别名]
def test_read_request_load_succeeds(self, _logger):
        """
        ``read_request_load_scenario`` starts and stops without collapsing.
        """
        c = Clock()

        node1 = Node(uuid=uuid4(), public_address=IPAddress('10.0.0.1'))
        node2 = Node(uuid=uuid4(), public_address=IPAddress('10.0.0.2'))
        cluster = BenchmarkCluster(
            node1.public_address,
            lambda reactor: FakeFlockerClient([node1, node2]),
            {node1.public_address, node2.public_address},
            default_volume_size=DEFAULT_VOLUME_SIZE
        )

        sample_size = 5
        s = read_request_load_scenario(c, cluster, sample_size=sample_size)

        d = s.start()

        # Request rate samples are recorded every second and we need to
        # collect enough samples to establish the rate which is defined
        # by `sample_size`. Therefore, advance the clock by
        # `sample_size` seconds to obtain enough samples.
        c.pump(repeat(1, sample_size))
        s.maintained().addBoth(lambda x: self.fail())
        d.addCallback(lambda ignored: s.stop())

        def verify_scenario_returns_metrics(result):
            self.assertIsInstance(result, dict)

        d.addCallback(verify_scenario_returns_metrics)

        c.pump(repeat(1, sample_size))
        self.successResultOf(d) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:37,代码来源:test_read_request_load.py

示例15: test_read_request_load_start_stop_start_succeeds

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPAddress [as 别名]
def test_read_request_load_start_stop_start_succeeds(self, _logger):
        """
        ``read_request_load_scenario`` starts, stops and starts
        without collapsing.
        """
        c = Clock()

        node1 = Node(uuid=uuid4(), public_address=IPAddress('10.0.0.1'))
        node2 = Node(uuid=uuid4(), public_address=IPAddress('10.0.0.2'))
        cluster = BenchmarkCluster(
            node1.public_address,
            lambda reactor: FakeFlockerClient([node1, node2]),
            {node1.public_address, node2.public_address},
            default_volume_size=DEFAULT_VOLUME_SIZE
        )

        sample_size = 5
        s = read_request_load_scenario(c, cluster, sample_size=sample_size)
        # Start and stop
        s.start()
        c.pump(repeat(1, sample_size))
        s.stop()

        # Start again and verify the scenario succeeds
        d = s.start()
        c.pump(repeat(1, sample_size))
        s.maintained().addBoth(lambda x: self.fail())
        d.addCallback(lambda ignored: s.stop())
        c.pump(repeat(1, sample_size))
        self.successResultOf(d) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:32,代码来源:test_read_request_load.py


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