Move expose() logic to Application
[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 async def expose(self):
111 """Make this service publicly available over the network.
112
113 """
114 app_facade = client.ApplicationFacade()
115 app_facade.connect(self.connection)
116
117 log.debug(
118 'Exposing %s', self.name)
119
120 return await app_facade.Expose(self.name)
121
122 def get_config(self):
123 """Return the configuration settings for this service.
124
125 """
126 pass
127
128 def get_constraints(self):
129 """Return the machine constraints for this service.
130
131 """
132 pass
133
134 def get_actions(self, schema=False):
135 """Get actions defined for this service.
136
137 :param bool schema: Return the full action schema
138
139 """
140 pass
141
142 def get_resources(self, details=False):
143 """Return resources for this service.
144
145 :param bool details: Include detailed info about resources used by each
146 unit
147
148 """
149 pass
150
151 def run(self, command, timeout=None):
152 """Run command on all units for this service.
153
154 :param str command: The command to run
155 :param int timeout: Time to wait before command is considered failed
156
157 """
158 pass
159
160 def set_config(self, to_default=False, **config):
161 """Set configuration options for this service.
162
163 :param bool to_default: Set service options to default values
164 :param \*\*config: Config key/values
165
166 """
167 pass
168
169 def set_constraints(self, constraints):
170 """Set machine constraints for this service.
171
172 :param :class:`juju.Constraints` constraints: Machine constraints
173
174 """
175 pass
176
177 def set_meter_status(self, status, info=None):
178 """Set the meter status on this status.
179
180 :param str status: Meter status, e.g. 'RED', 'AMBER'
181 :param str info: Extra info message
182
183 """
184 pass
185
186 def set_plan(self, plan_name):
187 """Set the plan for this service, effective immediately.
188
189 :param str plan_name: Name of plan
190
191 """
192 pass
193
194 def unexpose(self):
195 """Remove public availability over the network for this service.
196
197 """
198 pass
199
200 def update_allocation(self, allocation):
201 """Update existing allocation for this service.
202
203 :param int allocation: The allocation to set
204
205 """
206 pass
207
208 def upgrade_charm(
209 self, channel=None, force_series=False, force_units=False,
210 path=None, resources=None, revision=-1, switch=None):
211 """Upgrade the charm for this service.
212
213 :param str channel: Channel to use when getting the charm from the
214 charm store, e.g. 'development'
215 :param bool force_series: Upgrade even if series of deployed service
216 is not supported by the new charm
217 :param bool force_units: Upgrade all units immediately, even if in
218 error state
219 :param str path: Uprade to a charm located at path
220 :param dict resources: Dictionary of resource name/filepath pairs
221 :param int revision: Explicit upgrade revision
222 :param str switch: Crossgrade charm url
223
224 """
225 pass