Exemplo n.º 1
0
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)
    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)
Exemplo n.º 2
0
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)
    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)
Exemplo n.º 3
0
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)