~juju/ubuntu/precise/juju/0.5

« back to all changes in this revision

Viewing changes to juju/control/destroy_service.py

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-04-18 15:45:34 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20120418154534-tkoahx8nmnrb9ph7
Tags: 0.5+bzr531-0ubuntu1
* New upstream snapshot (LP: #985249)
* d/p/fix-tests-without-aws-key.patch: Dropped as it has been
  superseded by a better upstream fix (LP: #819329)
* d/p/no-write-sample-on-help.patch: Dropped, Applied upstream.
* d/p/disable-failing-zookeeper-test.patch refreshed.
* d/control: new code requires latest txzookeeper upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
from twisted.internet.defer import inlineCallbacks
4
4
 
 
5
from juju.state.errors import UnsupportedSubordinateServiceRemoval
 
6
from juju.state.relation import RelationStateManager
5
7
from juju.state.service import ServiceStateManager
6
8
from juju.control.utils import get_environment
7
9
 
35
37
    client = yield provider.connect()
36
38
    service_manager = ServiceStateManager(client)
37
39
    service_state = yield service_manager.get_service_state(service_name)
 
40
    if (yield service_state.is_subordinate()):
 
41
        # We can destroy the service if does not have relations.
 
42
        # That implies that principals have already been torn
 
43
        # down (or were never added).
 
44
        relation_manager = RelationStateManager(client)
 
45
        relations = yield relation_manager.get_relations_for_service(
 
46
            service_state)
 
47
 
 
48
        if relations:
 
49
            principal_service = None
 
50
            # if we have a container we can destroy the subordinate
 
51
            # (revisit in the future)
 
52
            for relation in relations:
 
53
                if relation.relation_scope != "container":
 
54
                    continue
 
55
                services = yield relation.get_service_states()
 
56
                remote_service = [s for s in services if s.service_name !=
 
57
                                     service_state.service_name][0]
 
58
                if not (yield remote_service.is_subordinate()):
 
59
                    principal_service = remote_service
 
60
                    break
 
61
 
 
62
            if principal_service:
 
63
                raise UnsupportedSubordinateServiceRemoval(
 
64
                    service_state.service_name,
 
65
                    principal_service.service_name)
 
66
 
38
67
    yield service_manager.remove_service_state(service_state)
39
68
    log.info("Service %r destroyed.", service_state.service_name)