Add ModelEntity callbacks and async return values.
[osm/N2VC.git] / juju / application.py
1 import logging
2
3 from . import model
4 from .client import client
5
6 log = logging.getLogger(__name__)
7
8
9 class Application(model.ModelEntity):
10 @property
11 def _unit_match_pattern(self):
12 return r'^{}.*$'.format(self.entity_id)
13
14 def on_unit_add(self, callable_):
15 """Add a "unit added" observer to this entity, which will be called
16 whenever a unit is added to this application.
17
18 """
19 self.model.add_observer(
20 callable_, 'unit', 'add', self._unit_match_pattern)
21
22 def on_unit_remove(self, callable_):
23 """Add a "unit removed" observer to this entity, which will be called
24 whenever a unit is removed from this application.
25
26 """
27 self.model.add_observer(
28 callable_, 'unit', 'remove', self._unit_match_pattern)
29
30 @property
31 def units(self):
32 return [
33 unit for unit in self.model.units.values()
34 if unit.application == self.name
35 ]
36
37 def add_relation(self, local_relation, remote_relation):
38 """Add a relation to another service.
39
40 :param str local_relation: Name of relation on this service
41 :param str remote_relation: Name of relation on the other service in
42 the form '<service>[:<relation_name>]'
43
44 """
45 pass
46
47 def add_unit(self, count=1, to=None):
48 """Add one or more units to this service.
49
50 :param int count: Number of units to add
51 :param str to: Placement directive, e.g.::
52 '23' - machine 23
53 'lxc:7' - new lxc container on machine 7
54 '24/lxc/3' - lxc container 3 or machine 24
55
56 If None, a new machine is provisioned.
57
58 """
59 pass
60 add_units = add_unit
61
62 def allocate(self, budget, value):
63 """Allocate budget to this service.
64
65 :param str budget: Name of budget
66 :param int value: Budget limit
67
68 """
69 pass
70
71 def attach(self, resource_name, file_path):
72 """Upload a file as a resource for this service.
73
74 :param str resource: Name of the resource
75 :param str file_path: Path to the file to upload
76
77 """
78 pass
79
80 def collect_metrics(self):
81 """Collect metrics on this service.
82
83 """
84 pass
85
86 def destroy_relation(self, local_relation, remote_relation):
87 """Remove a relation to another service.
88
89 :param str local_relation: Name of relation on this service
90 :param str remote_relation: Name of relation on the other service in
91 the form '<service>[:<relation_name>]'
92
93 """
94 pass
95 remove_relation = destroy_relation
96
97 async def destroy(self):
98 """Remove this service from the model.
99
100 """
101 app_facade = client.ApplicationFacade()
102 app_facade.connect(self.connection)
103
104 log.debug(
105 'Destroying %s', self.name)
106
107 return await app_facade.Destroy(self.name)
108 remove = destroy
109
110 def expose(self):
111 """Make this service publicly available over the network.
112
113 """
114 pass
115
116 def get_config(self):
117 """Return the configuration settings for this service.
118
119 """
120 pass
121
122 def get_constraints(self):
123 """Return the machine constraints for this service.
124
125 """
126 pass
127
128 def get_actions(self, schema=False):
129 """Get actions defined for this service.
130
131 :param bool schema: Return the full action schema
132
133 """
134 pass
135
136 def get_resources(self, details=False):
137 """Return resources for this service.
138
139 :param bool details: Include detailed info about resources used by each
140 unit
141
142 """
143 pass
144
145 def run(self, command, timeout=None):
146 """Run command on all units for this service.
147
148 :param str command: The command to run
149 :param int timeout: Time to wait before command is considered failed
150
151 """
152 pass
153
154 def set_config(self, to_default=False, **config):
155 """Set configuration options for this service.
156
157 :param bool to_default: Set service options to default values
158 :param \*\*config: Config key/values
159
160 """
161 pass
162
163 def set_constraints(self, constraints):
164 """Set machine constraints for this service.
165
166 :param :class:`juju.Constraints` constraints: Machine constraints
167
168 """
169 pass
170
171 def set_meter_status(self, status, info=None):
172 """Set the meter status on this status.
173
174 :param str status: Meter status, e.g. 'RED', 'AMBER'
175 :param str info: Extra info message
176
177 """
178 pass
179
180 def set_plan(self, plan_name):
181 """Set the plan for this service, effective immediately.
182
183 :param str plan_name: Name of plan
184
185 """
186 pass
187
188 def unexpose(self):
189 """Remove public availability over the network for this service.
190
191 """
192 pass
193
194 def update_allocation(self, allocation):
195 """Update existing allocation for this service.
196
197 :param int allocation: The allocation to set
198
199 """
200 pass
201
202 def upgrade_charm(
203 self, channel=None, force_series=False, force_units=False,
204 path=None, resources=None, revision=-1, switch=None):
205 """Upgrade the charm for this service.
206
207 :param str channel: Channel to use when getting the charm from the
208 charm store, e.g. 'development'
209 :param bool force_series: Upgrade even if series of deployed service
210 is not supported by the new charm
211 :param bool force_units: Upgrade all units immediately, even if in
212 error state
213 :param str path: Uprade to a charm located at path
214 :param dict resources: Dictionary of resource name/filepath pairs
215 :param int revision: Explicit upgrade revision
216 :param str switch: Crossgrade charm url
217
218 """
219 pass