本文整理匯總了Python中charmhelpers.core.decorators.retry_on_exception方法的典型用法代碼示例。如果您正苦於以下問題:Python decorators.retry_on_exception方法的具體用法?Python decorators.retry_on_exception怎麽用?Python decorators.retry_on_exception使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類charmhelpers.core.decorators
的用法示例。
在下文中一共展示了decorators.retry_on_exception方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: add_node
# 需要導入模塊: from charmhelpers.core import decorators [as 別名]
# 或者: from charmhelpers.core.decorators import retry_on_exception [as 別名]
def add_node(self, host, executors, labels=()):
"""Add a slave node with the given host name."""
self.wait()
client = self._make_client()
@retry_on_exception(3, 3, exc_type=RETRIABLE)
def _add_node():
if client.node_exists(host):
hookenv.log("Node exists - not adding")
return
hookenv.log("Adding node '%s' to Jenkins master" % host)
# See the "Launch slave agent headlessly" section of the Jenkins
# wiki page about distributed builds:
#
# https://wiki.jenkins-ci.org/display/JENKINS/Distributed+builds
launcher = jenkins.LAUNCHER_JNLP
client.create_node(
host, int(executors), host, labels=labels, launcher=launcher)
if not client.node_exists(host):
hookenv.log(
"Failed to create node '%s'" % host, level=ERROR)
return _add_node()
示例2: charm_check_func
# 需要導入模塊: from charmhelpers.core import decorators [as 別名]
# 或者: from charmhelpers.core.decorators import retry_on_exception [as 別名]
def charm_check_func():
"""Custom function to assess the status of the current unit
@returns (status, message) - tuple of strings if an issue
"""
@retry_on_exception(num_retries=10,
base_delay=2,
exc_type=DesyncedException)
def _cluster_in_sync():
'''Helper func to wait for a while for resync to occur
@raise DesynedException: raised if local unit is not in sync
with its peers
'''
if not cluster_in_sync():
raise DesyncedException()
min_size = config('min-cluster-size')
# Ensure that number of peers > cluster size configuration
if not is_sufficient_peers():
return ('blocked', 'Insufficient peers to bootstrap cluster')
if min_size and int(min_size) > 1:
# Once running, ensure that cluster is in sync
# and has the required peers
if not is_bootstrapped():
return ('waiting', 'Unit waiting for cluster bootstrap')
elif is_bootstrapped():
try:
_cluster_in_sync()
return ('active', 'Unit is ready and clustered')
except DesyncedException:
return ('blocked', 'Unit is not in sync')
else:
return ('active', 'Unit is ready')
示例3: ensure_api_responding
# 需要導入模塊: from charmhelpers.core import decorators [as 別名]
# 或者: from charmhelpers.core.decorators import retry_on_exception [as 別名]
def ensure_api_responding(cls):
"""Check that the api service is responding.
The retry_on_exception decorator will cause this method to be called
until it succeeds or retry limit is exceeded"""
hookenv.log('Checking API service is responding',
level=hookenv.WARNING)
check_cmd = ['reactive/designate_utils.py', 'server-list']
subprocess.check_call(check_cmd)
示例4: get_keystone_manager
# 需要導入模塊: from charmhelpers.core import decorators [as 別名]
# 或者: from charmhelpers.core.decorators import retry_on_exception [as 別名]
def get_keystone_manager(endpoint, token, api_version=None):
"""Return a keystonemanager for the correct API version
If api_version has not been set then create a manager based on the endpoint
Use this manager to query the catalogue and determine which api version
should actually be being used. Return the correct client based on that.
Function is wrapped in a retry_on_exception to catch the case where the
keystone service is still initialising and not responding to requests yet.
XXX I think the keystone client should be able to do version
detection automatically so the code below could be greatly
simplified
@param endpoint: the keystone endpoint to point client at
@param token: the keystone admin_token
@param api_version: version of the keystone api the client should use
@returns keystonemanager class used for interrogating keystone
"""
if api_version:
return _get_keystone_manager_class(endpoint, token, api_version)
else:
if 'v2.0' in endpoint.split('/'):
manager = _get_keystone_manager_class(endpoint, token, 2)
else:
manager = _get_keystone_manager_class(endpoint, token, 3)
if endpoint.endswith('/'):
base_ep = endpoint.rsplit('/', 2)[0]
else:
base_ep = endpoint.rsplit('/', 1)[0]
svc_id = None
for svc in manager.api.services.list():
if svc.type == 'identity':
svc_id = svc.id
version = None
for ep in manager.api.endpoints.list():
if ep.service_id == svc_id and hasattr(ep, 'adminurl'):
version = ep.adminurl.split('/')[-1]
if version and version == 'v2.0':
new_ep = base_ep + "/" + 'v2.0'
return _get_keystone_manager_class(new_ep, token, 2)
elif version and version == 'v3':
new_ep = base_ep + "/" + 'v3'
return _get_keystone_manager_class(new_ep, token, 3)
else:
return manager