本文整理汇总了Python中charms.reactive.when方法的典型用法代码示例。如果您正苦于以下问题:Python reactive.when方法的具体用法?Python reactive.when怎么用?Python reactive.when使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类charms.reactive
的用法示例。
在下文中一共展示了reactive.when方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_config
# 需要导入模块: from charms import reactive [as 别名]
# 或者: from charms.reactive import when [as 别名]
def render_config(*args):
"""Render the configuration for charm when all the interfaces are
available.
"""
with charm.provide_charm_instance() as charm_class:
charm_class.render_with_interfaces(args)
charm_class.assess_status()
reactive.set_state('config.rendered')
# db_sync checks if sync has been done so rerunning is a noop
示例2: render_config
# 需要导入模块: from charms import reactive [as 别名]
# 或者: from charms.reactive import when [as 别名]
def render_config(*args):
"""Render the configuration for charm when all the interfaces are
available.
"""
with charm.provide_charm_instance() as charm_class:
charm_class.upgrade_if_available(args)
charm_class.enable_services()
charm_class.render_with_interfaces(args)
charm_class.enable_webserver_site()
charm_class.assess_status()
reactive.set_state('config.rendered')
# db_sync checks if sync has been done so rerunning is a noop
示例3: install_sandvine_pts_proxy
# 需要导入模块: from charms import reactive [as 别名]
# 或者: from charms.reactive import when [as 别名]
def install_sandvine_pts_proxy():
status_set('maintenance','Installing')
# Do your setup here.
#
# If your charm has other dependencies before it can install,
# add those as @when() clauses above., or as additional @when()
# decorated handlers below
#
# See the following for information about reactive charms:
#
# * https://jujucharms.com/docs/devel/developer-getting-started
# * https://github.com/juju-solutions/layer-basic#overview
#
set_state('sandvine-pts-proxy.installed')
status_set('active','ready')
示例4: render_config
# 需要导入模块: from charms import reactive [as 别名]
# 或者: from charms.reactive import when [as 别名]
def render_config(*args):
"""Render the configuration for charm when all the interfaces are
available.
"""
horrible_hack_to_workaround_missing_package_files()
with charm.provide_charm_instance() as charm_class:
charm_class.render_with_interfaces(args)
charm_class.db_sync()
charm_class.upgrade_if_available(args)
charm_class.assess_status()
reactive.set_state('config.rendered')
示例5: render_stuff
# 需要导入模块: from charms import reactive [as 别名]
# 或者: from charms.reactive import when [as 别名]
def render_stuff(*args):
"""Render the configuration for Barbican when all the interfaces are
available.
Note that the HSM interface is optional and thus is only used if it is
available.
"""
hookenv.log("about to call the render_configs with {}".format(args))
with charm.provide_charm_instance() as barbican_charm:
barbican_charm.render_with_interfaces(
charm.optional_interfaces(args, 'hsm.available'))
barbican_charm.assess_status()
示例6: setup_sync_target_alone
# 需要导入模块: from charms import reactive [as 别名]
# 或者: from charms.reactive import when [as 别名]
def setup_sync_target_alone():
'''If this is the only unit in the application then setup a sync target.
This will likely by empty as zones.initialised is only unset when a unit
frst comes up but the presence of the target allows subsequent units to
bootstrap if leadership flips to them as they come up'''
if hookenv.is_leader():
designate_bind.setup_sync()
reactive.set_state('zones.initialised')
示例7: server_connected
# 需要导入模块: from charms import reactive [as 别名]
# 或者: from charms.reactive import when [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', '')