Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def statistics_interface():
config = config_get()
enable_monitoring = config['enable_monitoring']
monitoring_port = config['monitoring_port']
monitoring_password = get_monitoring_password()
monitoring_username = config['monitoring_username']
for relid in get_relation_ids('statistics'):
if not enable_monitoring:
relation_set(relation_id=relid,
enabled=enable_monitoring)
else:
relation_set(relation_id=relid,
enabled=enable_monitoring,
port=monitoring_port,
password=monitoring_password,
user=monitoring_username)
def inform_peers_unit_state(state, relation_name='cluster'):
"""Inform peers of the state of this unit.
:param state: State of unit to publish
:type state: string
:param relation_name: Name of relation to publish state on
:type relation_name: string
"""
if state not in UNIT_STATES:
raise ValueError(
"Setting invalid state {} for unit".format(state))
this_unit = local_unit()
for r_id in relation_ids(relation_name):
juju_log('Telling peer behind relation {} that {} is {}'.format(
r_id, this_unit, state), 'DEBUG')
relation_set(relation_id=r_id,
relation_settings={
get_peer_key(this_unit): state})
vips = config('vip').split()
for vip in vips:
if vip and is_ipv6(vip):
hosts.append(vip)
kwargs = {'database': database,
'username': database_user,
'hostname': json.dumps(hosts)}
if relation_prefix:
for key in list(kwargs.keys()):
kwargs["%s_%s" % (relation_prefix, key)] = kwargs[key]
del kwargs[key]
for rid in relation_ids('shared-db'):
relation_set(relation_id=rid, **kwargs)
def compute_joined(rid=None, remote_restart=False):
rel_settings = get_compute_config(remote_restart=remote_restart)
rel_settings.update(keystone_compute_settings())
hookenv.relation_set(relation_id=rid, **rel_settings)
def keystone_joined(relid=None):
port = config('bind-port')
admin_url = '%s:%s' % (canonical_url(CONFIGS, ADMIN), port)
internal_url = ('%s:%s/v1/AUTH_$(tenant_id)s' %
(canonical_url(CONFIGS, INTERNAL), port))
public_url = ('%s:%s/v1/AUTH_$(tenant_id)s' %
(canonical_url(CONFIGS, PUBLIC), port))
region = config('region')
roles = config('operator-roles')
relation_set(service='swift', region=region, public_url=public_url,
internal_url=internal_url, admin_url=admin_url,
requested_roles=roles, relation_id=relid)
def peer_store(key, value, relation_name='cluster'):
"""Store the key/value pair on the named peer relation `relation_name`."""
cluster_rels = relation_ids(relation_name)
if len(cluster_rels) > 0:
cluster_rid = cluster_rels[0]
relation_set(relation_id=cluster_rid,
relation_settings={key: value})
else:
raise ValueError('Unable to detect '
'peer relation {}'.format(relation_name))
def _flush_data(self):
"""
If this relation's local unit data has been modified, publish it on the
relation. This should be automatically called.
"""
if self._data and self._data.modified:
hookenv.relation_set(self.relation_id, dict(self.to_publish.data))
def __call__(self):
ctxt = {}
if hookenv.relation_ids('cinder-volume-service'):
ctxt['volume_service'] = 'cinder'
# kick all compute nodes to know they should use cinder now.
for rid in hookenv.relation_ids('cloud-compute'):
hookenv.relation_set(relation_id=rid, volume_service='cinder')
return ctxt
os.mkdir(NRPE.nagios_logdir)
os.chown(NRPE.nagios_logdir, nagios_uid, nagios_gid)
nrpe_monitors = {}
monitors = {"monitors": {"remote": {"nrpe": nrpe_monitors}}}
for nrpecheck in self.checks:
nrpecheck.write(self.nagios_context, self.hostname,
self.nagios_servicegroups)
nrpe_monitors[nrpecheck.shortname] = {
"command": nrpecheck.command,
}
service('restart', 'nagios-nrpe-server')
for rid in relation_ids("local-monitors"):
relation_set(relation_id=rid, monitors=yaml.dump(monitors))
def keystone_joined(rel_id=None):
relation_set(relation_id=rel_id,
service="None",
region="None",
public_url="None",
admin_url="None",
internal_url="None",
requested_roles=config('default-role'))