本文整理匯總了Python中charms.reactive.hook方法的典型用法代碼示例。如果您正苦於以下問題:Python reactive.hook方法的具體用法?Python reactive.hook怎麽用?Python reactive.hook使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類charms.reactive
的用法示例。
在下文中一共展示了reactive.hook方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: default_upgrade_charm
# 需要導入模塊: from charms import reactive [as 別名]
# 或者: from charms.reactive import hook [as 別名]
def default_upgrade_charm():
"""Default handler for the 'upgrade-charm' hook.
This calls the charm.singleton.upgrade_charm() function as a default.
"""
reactive.set_state('run-default-upgrade-charm')
示例2: changed
# 需要導入模塊: from charms import reactive [as 別名]
# 或者: from charms.reactive import hook [as 別名]
def changed(self):
"""This hook is used to indicate that something has changed on the
interface and that interested parties should recheck the properties
exposed to see if they need to do anything.
The handler should clear the state after it has been consumed so that
the next change gets registered too.
"""
self.update_status()
示例3: check_dns_slaves
# 需要導入模塊: from charms import reactive [as 別名]
# 或者: from charms.reactive import hook [as 別名]
def check_dns_slaves():
"""verify if the config('dns-slaves') is valid and set or remove the state
accordingly. Note, that hooks run BEFORE the reactive handlers so this
should happen first during a hook.
"""
if hookenv.config('dns-slaves'):
with provide_charm_instance() as instance:
if not instance.options.invalid_pool_config():
reactive.set_state('dns-slaves-config-valid')
return
reactive.remove_state('dns-slaves-config-valid')
示例4: update_peers
# 需要導入模塊: from charms import reactive [as 別名]
# 或者: from charms.reactive import hook [as 別名]
def update_peers(cluster):
"""Inform designate peers about this unit"""
with provide_charm_instance() as instance:
# This function ONLY updates the peers if the data has changed. Thus
# it's okay to call it on every hook invocation.
instance.update_peers(cluster)
示例5: run_assess_status_on_every_hook
# 需要導入模塊: from charms import reactive [as 別名]
# 或者: from charms.reactive import hook [as 別名]
def run_assess_status_on_every_hook():
"""The call to charm instance.assess_status() sets up the assess status
functionality to be called atexit() of the charm. i.e. as the last thing
it does. Thus, this handle gets called for EVERY hook invocation, which
means that no other handlers need to call the assess_status function.
"""
with provide_charm_instance() as instance:
instance.assess_status()