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


Python ip.get_relation_ip方法代码示例

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


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

示例1: add_network_split_addresses

# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import get_relation_ip [as 别名]
def add_network_split_addresses(self):
        """Populate cluster_hosts with addresses of this unit and its
           peers on each address type

           @return None
        """
        for addr_type in ADDRESS_TYPES:
            cfg_opt = os_ip.ADDRESS_MAP[addr_type]['config']
            laddr = ch_ip.get_relation_ip(
                os_ip.ADDRESS_MAP[addr_type]['binding'],
                self.config.get(cfg_opt))
            if laddr:
                self.cluster_hosts[laddr] = \
                    self.local_network_split_addresses()[laddr]
                key = '{}-address'.format(
                    os_ip.ADDRESS_MAP[addr_type]['binding'])
                for _unit, _laddr in self.relation.ip_map(address_key=key):
                    if _laddr:
                        self.cluster_hosts[laddr]['backends'][_unit] = _laddr 
开发者ID:openstack,项目名称:charms.openstack,代码行数:21,代码来源:adapters.py

示例2: internal_addresses

# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import get_relation_ip [as 别名]
def internal_addresses(self):
        """Return list of internal addresses of this unit and peers

           Return list of internal addresses of this unit and peers. If no
           internal address cidr has been set return private addresses.

           @return list [ip1, ip2, ...]
        """
        cfg_opt = os_ip.ADDRESS_MAP[os_ip.INTERNAL]['config']
        int_net = self.config.get(cfg_opt)
        laddr = ch_ip.get_relation_ip(
            os_ip.ADDRESS_MAP[os_ip.INTERNAL]['binding'],
            int_net)
        try:
            hosts = sorted(
                list(self.cluster_hosts[laddr]['backends'].values()))
        except KeyError:
            hosts = [laddr]
        return hosts 
开发者ID:openstack,项目名称:charms.openstack,代码行数:21,代码来源:adapters.py

示例3: update_peers

# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import get_relation_ip [as 别名]
def update_peers(self, cluster):
        """Update peers in the cluster about the addresses that this unit
        holds.

        NOTE(AJK): This uses the helper is_data_changed() to track whether this
        has already been done, and doesn't re-advertise the changes if nothing
        has changed.

        @param cluster: the interface object for the cluster relation
        """
        laddrs = []
        for addr_type in sorted(os_ip.ADDRESS_MAP.keys()):
            cidr = self.config.get(os_ip.ADDRESS_MAP[addr_type]['config'])
            laddr = ch_ip.get_relation_ip(
                os_ip.ADDRESS_MAP[addr_type]['binding'],
                cidr)
            laddrs.append((addr_type, laddr))
        with is_data_changed('update_peers.laddrs', laddrs) as changed:
            if changed:
                for (addr_type, laddr) in laddrs:
                    cluster.set_address(
                        os_ip.ADDRESS_MAP[addr_type]['binding'],
                        laddr) 
开发者ID:openstack,项目名称:charms.openstack,代码行数:25,代码来源:classes.py

示例4: get_database_setup

# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import get_relation_ip [as 别名]
def get_database_setup(self):
        return [{
            'database': 'gnocchi',
            'username': 'gnocchi',
            'hostname': ch_ip.get_relation_ip(DB_INTERFACE)}, ] 
开发者ID:openstack,项目名称:charm-gnocchi,代码行数:7,代码来源:gnocchi.py

示例5: local_network_split_addresses

# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import get_relation_ip [as 别名]
def local_network_split_addresses(self):
        """Map of local units addresses for each address type

           NOTE: This excludes private-address
           @return dict of backends and networks for local unit e.g.
               {'this_unit_admin_addr': {
                    'backends': {
                        'this_unit-1': 'this_unit_admin_addr'},
                    'network': 'this_unit_admin_addr/admin_netmask'},
                'this_unit_internal_addr': {
                    'backends': {
                        'this_unit-1': 'this_unit_internal_addr'},
                    'network': 'this_unit_internal_addr/internal_netmask'},
                'this_unit_public_addr': {
                    'backends': {
                        'this_unit-1': 'this_unit_public_addr'},
                    'network': 'this_unit_public_addr/public_netmask'}}
        """
        config = hookenv.config()
        _cluster_hosts = {}
        for addr_type in ADDRESS_TYPES:
            cfg_opt = os_ip.ADDRESS_MAP[addr_type]['config']
            laddr = ch_ip.get_relation_ip(
                os_ip.ADDRESS_MAP[addr_type]['binding'],
                config.get(cfg_opt))
            if laddr:
                netmask = ch_ip.get_netmask_for_address(laddr)
                _cluster_hosts[laddr] = {
                    'network': "{}/{}".format(laddr, netmask),
                    'backends': collections.OrderedDict(
                        [(self.local_unit_name, laddr)])}
        return _cluster_hosts 
开发者ID:openstack,项目名称:charms.openstack,代码行数:34,代码来源:adapters.py

示例6: rndc_master_ips

# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import get_relation_ip [as 别名]
def rndc_master_ips(self):
        rndc_master_ips = []
        rndc_master_ip = ch_ip.get_relation_ip('dns-backend')
        rndc_master_ips.append(rndc_master_ip)
        cluster_relid = hookenv.relation_ids('cluster')[0]
        if hookenv.related_units(relid=cluster_relid):
            for unit in hookenv.related_units(relid=cluster_relid):
                rndc_master_ip = hookenv.relation_get('rndc-address',
                                                      rid=cluster_relid,
                                                      unit=unit)
                if rndc_master_ip is not None:
                    rndc_master_ips.append(rndc_master_ip)
        return rndc_master_ips 
开发者ID:openstack,项目名称:charm-designate,代码行数:15,代码来源:designate.py

示例7: expose_rndc_address

# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import get_relation_ip [as 别名]
def expose_rndc_address(cluster):
    rndc_address = ip.get_relation_ip('dns-backend')
    cluster.set_address('rndc', rndc_address) 
开发者ID:openstack,项目名称:charm-designate,代码行数:5,代码来源:designate_handlers.py

示例8: control_listen_ip

# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import get_relation_ip [as 别名]
def control_listen_ip(self):
        """IP local rndc service listens on

        :returns: str: IP local rndc listens on
        """
        return ch_ip.get_relation_ip('dns-backend') 
开发者ID:openstack,项目名称:charm-designate-bind,代码行数:8,代码来源:designate_bind.py

示例9: test_get_relation_ip

# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import get_relation_ip [as 别名]
def test_get_relation_ip(self, assert_charm_supports_ipv6, get_ipv6_addr,
                             unit_get, get_address_in_network,
                             network_get_primary_address, config):
        ACCESS_IP = '10.50.1.1'
        ACCESS_NETWORK = '10.50.1.0/24'
        AMQP_IP = '10.200.1.1'
        IPV6_IP = '2001:DB8::1'
        DEFAULT_IP = '172.16.1.1'
        assert_charm_supports_ipv6.return_value = True
        get_ipv6_addr.return_value = [IPV6_IP]
        unit_get.return_value = DEFAULT_IP
        get_address_in_network.return_value = DEFAULT_IP
        network_get_primary_address.return_value = AMQP_IP

        # Network-get calls
        _config = {'prefer-ipv6': False}
        config.side_effect = lambda key: _config.get(key)

        network_get_primary_address.side_effect = NotImplementedError
        self.assertEqual(DEFAULT_IP, net_ip.get_relation_ip('amqp'))

        network_get_primary_address.side_effect = None
        self.assertEqual(AMQP_IP, net_ip.get_relation_ip('amqp'))

        self.assertFalse(get_address_in_network.called)

        # Specific CIDR network
        get_address_in_network.return_value = ACCESS_IP
        network_get_primary_address.return_value = DEFAULT_IP
        self.assertEqual(
            ACCESS_IP,
            net_ip.get_relation_ip('shared-db',
                                   cidr_network=ACCESS_NETWORK))
        get_address_in_network.assert_called_with(ACCESS_NETWORK, DEFAULT_IP)

        self.assertFalse(assert_charm_supports_ipv6.called)

        # IPv6
        _config = {'prefer-ipv6': True}
        config.side_effect = lambda key: _config.get(key)
        self.assertEqual(IPV6_IP, net_ip.get_relation_ip('amqp'))
        assert_charm_supports_ipv6.assert_called_with() 
开发者ID:juju,项目名称:charm-helpers,代码行数:44,代码来源:test_ip.py


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