1e87ced2e26ea1ab24de5badfb63f011c0b9a803
4 from .client
import client
6 log
= logging
.getLogger(__name__
)
9 class Application(model
.ModelEntity
):
11 def _unit_match_pattern(self
):
12 return r
'^{}.*$'.format(self
.entity_id
)
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.
19 self
.model
.add_observer(
20 callable_
, 'unit', 'add', self
._unit
_match
_pattern
)
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.
27 self
.model
.add_observer(
28 callable_
, 'unit', 'remove', self
._unit
_match
_pattern
)
33 unit
for unit
in self
.model
.units
.values()
34 if unit
.application
== self
.name
37 def add_relation(self
, local_relation
, remote_relation
):
38 """Add a relation to another service.
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>]'
47 def add_unit(self
, count
=1, to
=None):
48 """Add one or more units to this service.
50 :param int count: Number of units to add
51 :param str to: Placement directive, e.g.::
53 'lxc:7' - new lxc container on machine 7
54 '24/lxc/3' - lxc container 3 or machine 24
56 If None, a new machine is provisioned.
62 def allocate(self
, budget
, value
):
63 """Allocate budget to this service.
65 :param str budget: Name of budget
66 :param int value: Budget limit
71 def attach(self
, resource_name
, file_path
):
72 """Upload a file as a resource for this service.
74 :param str resource: Name of the resource
75 :param str file_path: Path to the file to upload
80 def collect_metrics(self
):
81 """Collect metrics on this service.
86 def destroy_relation(self
, local_relation
, remote_relation
):
87 """Remove a relation to another service.
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>]'
95 remove_relation
= destroy_relation
97 async def destroy(self
):
98 """Remove this service from the model.
101 app_facade
= client
.ApplicationFacade()
102 app_facade
.connect(self
.connection
)
105 'Destroying %s', self
.name
)
107 return await app_facade
.Destroy(self
.name
)
111 """Make this service publicly available over the network.
116 def get_config(self
):
117 """Return the configuration settings for this service.
122 def get_constraints(self
):
123 """Return the machine constraints for this service.
128 def get_actions(self
, schema
=False):
129 """Get actions defined for this service.
131 :param bool schema: Return the full action schema
136 def get_resources(self
, details
=False):
137 """Return resources for this service.
139 :param bool details: Include detailed info about resources used by each
145 def run(self
, command
, timeout
=None):
146 """Run command on all units for this service.
148 :param str command: The command to run
149 :param int timeout: Time to wait before command is considered failed
154 def set_config(self
, to_default
=False, **config
):
155 """Set configuration options for this service.
157 :param bool to_default: Set service options to default values
158 :param \*\*config: Config key/values
163 def set_constraints(self
, constraints
):
164 """Set machine constraints for this service.
166 :param :class:`juju.Constraints` constraints: Machine constraints
171 def set_meter_status(self
, status
, info
=None):
172 """Set the meter status on this status.
174 :param str status: Meter status, e.g. 'RED', 'AMBER'
175 :param str info: Extra info message
180 def set_plan(self
, plan_name
):
181 """Set the plan for this service, effective immediately.
183 :param str plan_name: Name of plan
189 """Remove public availability over the network for this service.
194 def update_allocation(self
, allocation
):
195 """Update existing allocation for this service.
197 :param int allocation: The allocation to set
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.
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
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