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