本文整理汇总了Python中charmhelpers.core.hookenv.leader_set方法的典型用法代码示例。如果您正苦于以下问题:Python hookenv.leader_set方法的具体用法?Python hookenv.leader_set怎么用?Python hookenv.leader_set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类charmhelpers.core.hookenv
的用法示例。
在下文中一共展示了hookenv.leader_set方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_rndckey
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import leader_set [as 别名]
def init_rndckey(self):
"""Create a RNDC key if needed
Return the rndc key from the leader DB or if one is not present
generate a new one.
:returns: str: rndc key
"""
secret = DesignateBindCharm.get_rndc_secret()
hookenv.log('Retrieving secret', level=hookenv.DEBUG)
if not secret:
hookenv.log('Secret not found in leader db', level=hookenv.DEBUG)
if hookenv.is_leader():
hookenv.log('Creating new secret as leader',
level=hookenv.DEBUG)
secret = self.generate_rndc_key()
hookenv.leader_set({LEADERDB_SECRET_KEY: secret})
return secret
示例2: _save_state
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import leader_set [as 别名]
def _save_state(self):
self.msg('Publishing state'.format(self._name()))
if hookenv.is_leader():
# sort_keys to ensure stability.
raw = json.dumps(self.grants, sort_keys=True)
hookenv.leader_set({self.key: raw})
local_unit = hookenv.local_unit()
if self.relid is None:
# No peers relation yet. Fallback to local state.
self.msg('No peer relation. Saving local state')
self._save_local_state(self.requests[local_unit])
else:
# sort_keys to ensure stability.
raw = json.dumps(self.requests[local_unit], sort_keys=True)
hookenv.relation_set(self.relid, relation_settings={self.key: raw})
示例3: db_sync
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import leader_set [as 别名]
def db_sync(self):
"""Perform a database sync using the command defined in the
self.sync_cmd attribute. The services defined in self.services are
restarted after the database sync.
"""
if not self.db_sync_done() and hookenv.is_leader():
subprocess.check_call(self.sync_cmd)
hookenv.leader_set({'db-sync-done': True})
# Restart services immediately after db sync as
# render_domain_config needs a working system
self.restart_all()
示例4: db_sync
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import leader_set [as 别名]
def db_sync(self):
"""Perform a database sync using the command defined in the
self.sync_cmd attribute. The services defined in self.services are
restarted after the database sync.
"""
if not self.db_sync_done() and hookenv.is_leader():
subprocess.check_call(['mistral-db-manage', '--config-file', '/etc/mistral/mistral.conf', 'upgrade', 'head'])
subprocess.check_call(['mistral-db-manage', '--config-file', '/etc/mistral/mistral.conf', 'stamp', 'head'])
subprocess.check_call(['mistral-db-manage', '--config-file', '/etc/mistral/mistral.conf', 'populate'])
hookenv.leader_set({'db-sync-done': True})
# Restart services immediately after db sync as
# render_domain_config needs a working system
self.restart_all()
示例5: check_zone_ids
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import leader_set [as 别名]
def check_zone_ids(cls, nova_domain_name, neutron_domain_name):
zone_org_ids = {
'nova-domain-id': cls.get_domain_id(nova_domain_name),
'neutron-domain-id': cls.get_domain_id(neutron_domain_name),
}
yield
zone_ids = {
'nova-domain-id': cls.get_domain_id(nova_domain_name),
'neutron-domain-id': cls.get_domain_id(neutron_domain_name),
}
if zone_org_ids != zone_ids:
# Update leader-db to trigger peers to rerender configs
# as sink files will need updating with new domain ids
# Use host ID and current time UUID to help with debugging
hookenv.leader_set({'domain-init-done': uuid.uuid1()})
示例6: create_initial_servers_and_domains
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import leader_set [as 别名]
def create_initial_servers_and_domains(cls):
"""Create the nameserver entry and domains based on the charm user
supplied config
NOTE(AJK): This only wants to be done ONCE and by the leader, so we use
leader settings to store that we've done it, after it's successfully
completed.
@returns None
"""
KEY = 'create_initial_servers_and_domains'
if hookenv.is_leader() and not hookenv.leader_get(KEY):
nova_domain_name = hookenv.config('nova-domain')
neutron_domain_name = hookenv.config('neutron-domain')
with cls.check_zone_ids(nova_domain_name, neutron_domain_name):
if hookenv.config('nameservers'):
for ns in hookenv.config('nameservers').split():
cls.create_server(ns)
else:
hookenv.log('No nameserver specified, skipping creation of'
'nova and neutron domains',
level=hookenv.WARNING)
return
if nova_domain_name:
cls.create_domain(
nova_domain_name,
hookenv.config('nova-domain-email'))
if neutron_domain_name:
cls.create_domain(
neutron_domain_name,
hookenv.config('neutron-domain-email'))
# if this fails, we weren't the leader any more; another unit may
# attempt to do this too.
hookenv.leader_set({KEY: 'done'})
示例7: set_sync_info
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import leader_set [as 别名]
def set_sync_info(self, sync_time, sync_file):
"""Update leader DB with sync information
:param sync_time: str Time sync was created in epoch seconds
:param sync_file: str Local file containing zone information
:returns: None
"""
sync_info = {
LEADERDB_SYNC_SRC_KEY: 'http://{}:80/zone-syncs/{}'.format(
hookenv.unit_private_ip(), sync_file),
LEADERDB_SYNC_TIME_KEY: sync_time,
}
hookenv.leader_set(sync_info)
示例8: __setitem__
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import leader_set [as 别名]
def __setitem__(self, key, value):
if not hookenv.is_leader():
raise TypeError('Not the leader. Cannot change leader settings.')
if value is not None and not isinstance(value, six.string_types):
# We don't do implicit casting. This would cause simple
# types like integers to be read back as strings in subsequent
# hooks, and mutable types would require a lot of wrapping
# to ensure leader-set gets called when they are mutated.
raise ValueError('Only string values allowed')
hookenv.leader_set({key: value})
示例9: server_connected
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import leader_set [as 别名]
def server_connected(peer) -> None:
"""
The peer.available state is set when there are one or more peer units
that have joined.
:return:
"""
update_status()
bricks = check_for_new_devices()
if bricks.is_ok():
log('Reporting my bricks {} to the leader'.format(bricks.value))
peer.set_bricks(bricks=bricks.value)
if not is_leader():
log('Reporting my public address {} to the leader'.format(
unit_public_ip()))
peer.set_address(address_type='public', address=unit_public_ip())
return
# I am the leader
log('Leader probing peers')
probed_units = []
try:
p = hookenv.leader_get('probed-units')
if p:
probed_units = json.loads(p)
except json.decoder.JSONDecodeError as e:
log("json decoder failed for {}: {}".format(e.doc, e.msg))
log("probed_units: {}".format(probed_units))
peer_info = peer.get_peer_info()
for unit in peer_info:
if unit in probed_units:
continue
address = peer_info[unit]['address']
log('probing host {} at {}'.format(unit, address))
status_set('maintenance', 'Probing peer {}'.format(unit))
try:
peer_probe(address)
probed_units.append(unit)
except (GlusterCmdException, GlusterCmdOutputParseError):
log('Error probing host {}: {}'.format(unit, address), ERROR)
continue
log('successfully probed {}: {}'.format(unit, address), DEBUG)
settings = {'probed-units': json.dumps(probed_units)}
hookenv.leader_set(settings)
status_set('maintenance', '')