本文整理汇总了Python中charmhelpers.contrib.network.ip.get_host_ip方法的典型用法代码示例。如果您正苦于以下问题:Python ip.get_host_ip方法的具体用法?Python ip.get_host_ip怎么用?Python ip.get_host_ip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类charmhelpers.contrib.network.ip
的用法示例。
在下文中一共展示了ip.get_host_ip方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: normalize_address
# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import get_host_ip [as 别名]
def normalize_address(self, hostname):
"""Ensure that address returned is an IP address (i.e. not fqdn)"""
if config_get('prefer-ipv6'):
# TODO: add support for ipv6 dns
return hostname
if hostname != unit_get('private-address'):
return get_host_ip(hostname, fallback=hostname)
# Otherwise assume localhost
return '127.0.0.1'
示例2: test_get_host_ip_with_hostname
# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import get_host_ip [as 别名]
def test_get_host_ip_with_hostname(self, apt_install):
fake_dns = FakeDNS('10.0.0.1')
with patch(builtin_import, side_effect=[fake_dns]):
ip = net_ip.get_host_ip('www.ubuntu.com')
self.assertEquals(ip, '10.0.0.1')
示例3: test_get_host_ip_with_hostname_no_dns
# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import get_host_ip [as 别名]
def test_get_host_ip_with_hostname_no_dns(self, apt_install, socket,
ns_query):
ns_query.return_value = []
fake_dns = FakeDNS(None)
socket.return_value = '10.0.0.1'
with patch(builtin_import, side_effect=[fake_dns]):
ip = net_ip.get_host_ip('www.ubuntu.com')
self.assertEquals(ip, '10.0.0.1')
示例4: test_get_host_ip_with_hostname_fallback
# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import get_host_ip [as 别名]
def test_get_host_ip_with_hostname_fallback(self, apt_install, socket,
ns_query, *args):
ns_query.return_value = []
fake_dns = FakeDNS(None)
def r():
raise Exception()
socket.side_effect = r
with patch(builtin_import, side_effect=[fake_dns]):
ip = net_ip.get_host_ip('www.ubuntu.com', fallback='127.0.0.1')
self.assertEquals(ip, '127.0.0.1')
示例5: test_get_host_ip_with_ip
# 需要导入模块: from charmhelpers.contrib.network import ip [as 别名]
# 或者: from charmhelpers.contrib.network.ip import get_host_ip [as 别名]
def test_get_host_ip_with_ip(self, apt_install):
fake_dns = FakeDNS('5.5.5.5')
with patch(builtin_import, side_effect=[fake_dns]):
ip = net_ip.get_host_ip('4.2.2.1')
self.assertEquals(ip, '4.2.2.1')