本文整理汇总了Python中charmhelpers.contrib.openstack.utils.get_host_ip方法的典型用法代码示例。如果您正苦于以下问题:Python utils.get_host_ip方法的具体用法?Python utils.get_host_ip怎么用?Python utils.get_host_ip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类charmhelpers.contrib.openstack.utils
的用法示例。
在下文中一共展示了utils.get_host_ip方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _pg_dir_context
# 需要导入模块: from charmhelpers.contrib.openstack import utils [as 别名]
# 或者: from charmhelpers.contrib.openstack.utils import get_host_ip [as 别名]
def _pg_dir_context():
'''
Inspects relation with PLUMgrid director.
'''
ctxt = {
'opsvm_ip': '127.0.0.1',
'director_ips': [],
}
for rid in relation_ids('plumgrid'):
for unit in related_units(rid):
rdata = relation_get(rid=rid, unit=unit)
ctxt['director_ips'
].append(str(get_host_ip(rdata['private-address'])))
if "opsvm_ip" in rdata:
ctxt['opsvm_ip'] = \
rdata['opsvm_ip']
return ctxt
示例2: __call__
# 需要导入模块: from charmhelpers.contrib.openstack import utils [as 别名]
# 或者: from charmhelpers.contrib.openstack.utils import get_host_ip [as 别名]
def __call__(self):
allowed_hosts = []
for relid in relation_ids('swift-storage'):
for unit in related_units(relid):
host = relation_get('private-address', unit, relid)
if config('prefer-ipv6'):
host_ip = get_ipv6_addr(exc_list=[config('vip')])[0]
else:
host_ip = get_host_ip(host)
allowed_hosts.append(host_ip)
ctxt = {
'www_dir': WWW_DIR,
'allowed_hosts': allowed_hosts
}
return ctxt
示例3: update_rsync_acls
# 需要导入模块: from charmhelpers.contrib.openstack import utils [as 别名]
# 或者: from charmhelpers.contrib.openstack.utils import get_host_ip [as 别名]
def update_rsync_acls():
"""Get Host IP of each storage unit and broadcast acl to all units."""
hosts = []
if not is_elected_leader(SWIFT_HA_RES):
log("Skipping rsync acl update since not leader", level=DEBUG)
return
# Get all unit addresses
for rid in relation_ids('swift-storage'):
for unit in related_units(rid):
hosts.append(get_host_ip(rid=rid, unit=unit))
rsync_hosts = ' '.join(hosts)
log("Broadcasting acl '{}' to all storage units".format(rsync_hosts),
level=DEBUG)
# We add a timestamp so that the storage units know which is the newest
settings = {'rsync_allowed_hosts': rsync_hosts,
'timestamp': time.time()}
for rid in relation_ids('swift-storage'):
relation_set(relation_id=rid, **settings)
示例4: get_host_ip
# 需要导入模块: from charmhelpers.contrib.openstack import utils [as 别名]
# 或者: from charmhelpers.contrib.openstack.utils import get_host_ip [as 别名]
def get_host_ip(rid=None, unit=None):
addr = relation_get('private-address', rid=rid, unit=unit)
if config('prefer-ipv6'):
host_ip = format_ipv6_addr(addr)
if host_ip:
return host_ip
else:
msg = ("Did not get IPv6 address from storage relation "
"(got={})".format(addr))
log(msg, level=WARNING)
return openstack.get_host_ip(addr)
示例5: get_local_ip
# 需要导入模块: from charmhelpers.contrib.openstack import utils [as 别名]
# 或者: from charmhelpers.contrib.openstack.utils import get_host_ip [as 别名]
def get_local_ip() -> Result:
"""
Returns the local IPAddr address associated with this server
# Failures
Returns a GlusterError representing any failure that may have happened
while trying to
query this information.
"""
ip_addr = get_host_ip(unit_get('private-address'))
try:
parsed = ip_address(address=ip_addr)
return Ok(parsed) # Resolves a str hostname into a ip address.
except ValueError:
return Err("failed to parse ip address: {}".format(ip_addr))
示例6: resolve_to_ip
# 需要导入模块: from charmhelpers.contrib.openstack import utils [as 别名]
# 或者: from charmhelpers.contrib.openstack.utils import get_host_ip [as 别名]
def resolve_to_ip(address: str) -> Result:
"""
Resolves an dns address to an ip address. Relies on dig
:param address: String. Hostname to resolve to an ip address
:return: result
"""
ip_addr = get_host_ip(hostname=address)
try:
parsed = ip_address(address=ip_addr)
return Ok(parsed)
except ValueError:
return Err("failed to parse ip address: {}".format(ip_addr))
示例7: local_address
# 需要导入模块: from charmhelpers.contrib.openstack import utils [as 别名]
# 或者: from charmhelpers.contrib.openstack.utils import get_host_ip [as 别名]
def local_address(self):
"""Return remotely accessible address of charm (not localhost)
@return True if user has requested ipv6 support otherwise False
"""
if self.ipv6_mode:
addr = ch_ip.get_ipv6_addr(exc_list=[self.vip])[0]
else:
addr = ch_utils.get_host_ip(
hookenv.unit_get('private-address'))
return addr
示例8: get_local_addresses
# 需要导入模块: from charmhelpers.contrib.openstack import utils [as 别名]
# 或者: from charmhelpers.contrib.openstack.utils import get_host_ip [as 别名]
def get_local_addresses(self):
"""Return list of local addresses on each configured network
For each network return an address the local unit has on that network
if one exists.
@returns [private_addr, admin_addr, public_addr, ...]
"""
addresses = [
os_utils.get_host_ip(hookenv.unit_get('private-address'))]
for addr_type in os_ip.ADDRESS_MAP.keys():
laddr = os_ip.resolve_address(endpoint_type=addr_type)
if laddr:
addresses.append(laddr)
return sorted(list(set(addresses)))
示例9: _pg_edge_ips
# 需要导入模块: from charmhelpers.contrib.openstack import utils [as 别名]
# 或者: from charmhelpers.contrib.openstack.utils import get_host_ip [as 别名]
def _pg_edge_ips():
'''
Inspects edge-peer relation and returns the
ips of the edge nodes
'''
return [get_host_ip(rdata['private-address'])
for rid in relation_ids("plumgrid")
for rdata in
(relation_get(rid=rid, unit=unit) for unit in related_units(rid))
if 'edge-peer' in rdata]
示例10: _pg_gateway_ips
# 需要导入模块: from charmhelpers.contrib.openstack import utils [as 别名]
# 或者: from charmhelpers.contrib.openstack.utils import get_host_ip [as 别名]
def _pg_gateway_ips():
'''
Inspects gateway-peer relation and returns the
ips of the gateway nodes
'''
return [get_host_ip(rdata['private-address'])
for rid in relation_ids("plumgrid")
for rdata in
(relation_get(rid=rid, unit=unit) for unit in related_units(rid))
if 'gateway-peer' in rdata]
示例11: _pg_dir_ips
# 需要导入模块: from charmhelpers.contrib.openstack import utils [as 别名]
# 或者: from charmhelpers.contrib.openstack.utils import get_host_ip [as 别名]
def _pg_dir_ips():
'''
Inspects plumgrid-director peer relation and returns the
ips of the peer directors
'''
return [get_host_ip(rdata['private-address'])
for rid in relation_ids("director")
for rdata in
(relation_get(rid=rid, unit=unit) for unit in related_units(rid))
if rdata]
示例12: pg_ctxt
# 需要导入模块: from charmhelpers.contrib.openstack import utils [as 别名]
# 或者: from charmhelpers.contrib.openstack.utils import get_host_ip [as 别名]
def pg_ctxt(self):
'''
Generated Config for all PLUMgrid templates inside the templates
folder.
'''
pg_ctxt = super(PGDirContext, self).pg_ctxt()
if not pg_ctxt:
return {}
conf = config()
pg_dir_ips = _pg_dir_ips()
pg_dir_ips.append(str(get_address_in_network(network=None,
fallback=get_host_ip(unit_get('private-address')))))
pg_dir_ips = sorted(pg_dir_ips)
pg_ctxt['director_ips'] = pg_dir_ips
dir_count = len(pg_dir_ips)
pg_ctxt['director_ips_string'] = (str(pg_dir_ips[0]) + ',' +
str(pg_dir_ips[1]) + ',' +
str(pg_dir_ips[2])
if dir_count == 3 else
str(pg_dir_ips[0]))
PG_VIP = conf['plumgrid-virtual-ip']
if is_ip(PG_VIP):
pg_ctxt['virtual_ip'] = PG_VIP
else:
raise ValueError('Invalid PLUMgrid Virtual IP Provided')
unit_hostname = gethostname()
pg_ctxt['pg_hostname'] = unit_hostname
pg_ctxt['pg_fqdn'] = getfqdn()
from pg_dir_utils import get_mgmt_interface, get_fabric_interface
pg_ctxt['interface'] = get_mgmt_interface()
pg_ctxt['fabric_interface'] = get_fabric_interface()
pg_ctxt['label'] = unit_hostname
pg_ctxt['fabric_mode'] = 'host'
virtual_ip_array = re.split('\.', conf['plumgrid-virtual-ip'])
pg_ctxt['virtual_router_id'] = virtual_ip_array[3]
pg_ctxt['opsvm_ip'] = conf['opsvm-ip']
return pg_ctxt
示例13: storage_changed
# 需要导入模块: from charmhelpers.contrib.openstack import utils [as 别名]
# 或者: from charmhelpers.contrib.openstack.utils import get_host_ip [as 别名]
def storage_changed():
"""Storage relation.
Only the leader unit can update and distribute rings so if we are not the
leader we ignore this event and wait for a resync request from the leader.
"""
if not is_elected_leader(SWIFT_HA_RES):
log("Not the leader - deferring storage relation change to leader "
"unit.", level=DEBUG)
return
log("Storage relation changed -processing", level=DEBUG)
host_ip = get_host_ip()
if not host_ip:
log("No host ip found in storage relation - deferring storage "
"relation", level=WARNING)
return
update_rsync_acls()
zone = get_zone(config('zone-assignment'))
node_settings = {
'ip': host_ip,
'zone': zone,
'account_port': relation_get('account_port'),
'object_port': relation_get('object_port'),
'container_port': relation_get('container_port'),
}
if None in node_settings.values():
missing = [k for k, v in node_settings.items() if v is None]
log("Relation not ready - some required values not provided by "
"relation (missing={})".format(', '.join(missing)), level=INFO)
return None
for k in ['zone', 'account_port', 'object_port', 'container_port']:
node_settings[k] = int(node_settings[k])
CONFIGS.write_all()
# Allow for multiple devs per unit, passed along as a : separated list
# Update and balance rings.
nodes = []
devs = relation_get('device')
if devs:
for dev in devs.split(':'):
node = {k: v for k, v in node_settings.items()}
node['device'] = dev
nodes.append(node)
update_rings(nodes)
if not openstack.is_unit_paused_set():
# Restart proxy here in case no config changes made (so
# restart_on_change() ineffective).
service_restart('swift-proxy')