本文整理汇总了Python中juju.state.service.ServiceStateManager.join_descriptors方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceStateManager.join_descriptors方法的具体用法?Python ServiceStateManager.join_descriptors怎么用?Python ServiceStateManager.join_descriptors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类juju.state.service.ServiceStateManager
的用法示例。
在下文中一共展示了ServiceStateManager.join_descriptors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_relation
# 需要导入模块: from juju.state.service import ServiceStateManager [as 别名]
# 或者: from juju.state.service.ServiceStateManager import join_descriptors [as 别名]
def add_relation(env_config, environment, verbose, log, *descriptors):
"""Add relation between relation endpoints described by `descriptors`"""
provider = environment.get_machine_provider()
client = yield provider.connect()
relation_state_manager = RelationStateManager(client)
service_state_manager = ServiceStateManager(client)
endpoint_pairs = yield service_state_manager.join_descriptors(
*descriptors)
if verbose:
log.info("Endpoint pairs: %s", endpoint_pairs)
if len(endpoint_pairs) == 0:
raise NoMatchingEndpoints()
elif len(endpoint_pairs) > 1:
raise AmbiguousRelation(descriptors, endpoint_pairs)
# At this point we just have one endpoint pair. We need to pick
# just one of the endpoints if it's a peer endpoint, since that's
# our current API - join descriptors takes two descriptors, but
# add_relation_state takes one or two endpoints. TODO consider
# refactoring.
endpoints = endpoint_pairs[0]
if endpoints[0] == endpoints[1]:
endpoints = endpoints[0:1]
yield relation_state_manager.add_relation_state(*endpoints)
yield client.close()
log.info("Added %s relation to all service units.",
endpoints[0].relation_type)
示例2: remove_relation
# 需要导入模块: from juju.state.service import ServiceStateManager [as 别名]
# 或者: from juju.state.service.ServiceStateManager import join_descriptors [as 别名]
def remove_relation(env_config, environment, verbose, log, *descriptors):
"""Remove relation between relation endpoints described by `descriptors`"""
provider = environment.get_machine_provider()
client = yield provider.connect()
relation_state_manager = RelationStateManager(client)
service_state_manager = ServiceStateManager(client)
endpoint_pairs = yield service_state_manager.join_descriptors(
*descriptors)
if verbose:
log.info("Endpoint pairs: %s", endpoint_pairs)
if len(endpoint_pairs) == 0:
raise NoMatchingEndpoints()
elif len(endpoint_pairs) > 1:
raise AmbiguousRelation(descriptors, endpoint_pairs)
# At this point we just have one endpoint pair. We need to pick
# just one of the endpoints if it's a peer endpoint, since that's
# our current API - join descriptors takes two descriptors, but
# add_relation_state takes one or two endpoints. TODO consider
# refactoring.
endpoints = endpoint_pairs[0]
if endpoints[0] == endpoints[1]:
endpoints = endpoints[0:1]
relation_state = yield relation_state_manager.get_relation_state(
*endpoints)
# Look at both endpoints, if we are dealing with a container relation
# decide if one end is a principal.
service_pair = [] # ordered such that sub, principal
is_container = False
has_principal = True
for ep in endpoints:
if ep.relation_scope == "container":
is_container = True
service = yield service_state_manager.get_service_state(
ep.service_name)
if (yield service.is_subordinate()):
service_pair.append(service)
has_principal = True
else:
service_pair.insert(0, service)
if is_container and len(service_pair) == 2 and has_principal:
sub, principal = service_pair
raise UnsupportedSubordinateServiceRemoval(sub.service_name,
principal.service_name)
yield relation_state_manager.remove_relation_state(relation_state)
yield client.close()
log.info("Removed %s relation from all service units.",
endpoints[0].relation_type)