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