本文整理汇总了Python中charmhelpers.core.hookenv.unit_get方法的典型用法代码示例。如果您正苦于以下问题:Python hookenv.unit_get方法的具体用法?Python hookenv.unit_get怎么用?Python hookenv.unit_get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类charmhelpers.core.hookenv
的用法示例。
在下文中一共展示了hookenv.unit_get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_prometheus_config_def
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import unit_get [as 别名]
def write_prometheus_config_def():
config = hookenv.config()
port = config.get('port', '9090')
check_ports(port)
if config.get('external_url', False):
vars = {
'private_address': hookenv.unit_get('private-address'),
'public_address': hookenv.unit_get('public-address'),
# prometheus default:
'port': port,
}
runtime_args('-web.external-url',
config['external_url'].format(**vars))
args = runtime_args()
hookenv.log('runtime_args: {}'.format(args))
if args:
render(source=PROMETHEUS_DEF_TMPL,
target=PROMETHEUS_DEF,
context={'args': args},
)
set_state('prometheus.do-restart')
remove_state('prometheus.do-reconfig-def')
示例2: provide_data
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import unit_get [as 别名]
def provide_data(self):
return {
'host': hookenv.unit_get('private-address'),
'port': 80,
}
示例3: sniff_iface
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import unit_get [as 别名]
def sniff_iface(f):
"""Ensure decorated function is called with a value for iface.
If no iface provided, inject net iface inferred from unit private address.
"""
def iface_sniffer(*args, **kwargs):
if not kwargs.get('iface', None):
kwargs['iface'] = get_iface_from_addr(unit_get('private-address'))
return f(*args, **kwargs)
return iface_sniffer
示例4: get_local_ip
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import unit_get [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))
示例5: get_database_setup
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import unit_get [as 别名]
def get_database_setup(self):
"""Provide the default database credentials as a list of 3-tuples
returns a structure of:
[
{'database': <database>,
'username': <username>,
'hostname': <hostname of this unit>
'prefix': <the optional prefix for the database>, },
]
:returns [{'database': ...}, ...]: credentials for multiple databases
"""
host = None
try:
host = hookenv.network_get_primary_address('shared-db')
except NotImplementedError:
host = hookenv.unit_get('private-address')
return [
dict(
database=self.config['database'],
username=self.config['database-user'],
hostname=host, )
]
# Determine the charm class by the supported release
示例6: write_prometheus_config_yml
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import unit_get [as 别名]
def write_prometheus_config_yml():
config = hookenv.config()
target_jobs = unitdata.kv().get('target_jobs', [])
scrape_jobs = unitdata.kv().get('scrape_jobs', [])
# transform eg. 'h1:p1 , h2:p2' (string), to ['h1:p1', 'h2:p2'] (list)
static_targets = None
if config.get('static-targets'):
static_targets = [x.strip()
for x in config.get('static-targets', '').split(',')]
default_monitor_name = '{}-monitor'.format(hookenv.service_name())
options = {
'scrape_interval': config['scrape-interval'],
'evaluation_interval': config['evaluation-interval'],
'static_targets': static_targets,
'private_address': hookenv.unit_get('private-address'),
'monitor_name': config.get('monitor_name', default_monitor_name),
'jobs': target_jobs,
'scrape_jobs': scrape_jobs,
}
# custom-rules content must be passed verbatim with e.g.
# juju set prometheus custom-rules @my.rules
if config.get('custom-rules'):
custom_rules = config['custom-rules']
with open(CUSTOM_RULES_PATH, 'w') as fh:
fh.write(custom_rules)
options['custom_rules_file'] = CUSTOM_RULES_PATH
render(source=PROMETHEUS_YML_TMPL,
target=PROMETHEUS_YML,
context=options
)
validate_config()
set_state('prometheus.do-restart')
remove_state('prometheus.do-reconfig-yml')