~hazmat/pyjuju/proposed-support

« back to all changes in this revision

Viewing changes to juju/control/remove_relation.py

  • Committer: kapil.thangavelu at canonical
  • Date: 2012-05-22 22:08:15 UTC
  • mfrom: (484.1.53 trunk)
  • Revision ID: kapil.thangavelu@canonical.com-20120522220815-acyt8m89i9ybe0w1
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
from twisted.internet.defer import inlineCallbacks
4
4
 
5
5
from juju.control.utils import get_environment
6
 
from juju.state.errors import AmbiguousRelation, NoMatchingEndpoints
 
6
from juju.state.errors import (AmbiguousRelation, NoMatchingEndpoints,
 
7
                               UnsupportedSubordinateServiceRemoval)
7
8
from juju.state.relation import RelationStateManager
8
9
from juju.state.service import ServiceStateManager
9
10
 
62
63
        endpoints = endpoints[0:1]
63
64
    relation_state = yield relation_state_manager.get_relation_state(
64
65
        *endpoints)
 
66
 
 
67
    # Look at both endpoints, if we are dealing with a container relation
 
68
    # decide if one end is a principal.
 
69
    service_pair = []  # ordered such that sub, principal
 
70
 
 
71
    is_container = False
 
72
    has_principal = True
 
73
    for ep in endpoints:
 
74
        if ep.relation_scope == "container":
 
75
            is_container = True
 
76
        service = yield service_state_manager.get_service_state(
 
77
            ep.service_name)
 
78
        if (yield service.is_subordinate()):
 
79
            service_pair.append(service)
 
80
            has_principal = True
 
81
        else:
 
82
            service_pair.insert(0, service)
 
83
    if is_container and len(service_pair) == 2 and has_principal:
 
84
        sub, principal = service_pair
 
85
        raise UnsupportedSubordinateServiceRemoval(sub.service_name,
 
86
                                                   principal.service_name)
 
87
 
65
88
    yield relation_state_manager.remove_relation_state(relation_state)
66
89
    yield client.close()
67
90