本文整理匯總了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')