Base class for Endpoints that create requests in the request / response pattern.
Subclasses must set the REQUEST_CLASS
attribute to a subclass
of :class:BaseRequest
which defines the fields the request will use.
Collection of all units that were previously part of any relation on this endpoint but which have since departed.
This collection is persistent and mutable. The departed units will be kept until they are explicitly removed, to allow for reasonable cleanup of units that have left.
Example: You need to run a command each time a unit departs the relation.
.. code-block:: python
@when('endpoint.{endpoint_name}.departed')
def handle_departed_unit(self):
for name, unit in self.all_departed_units.items():
# run the command to remove `unit` from the cluster
# ..
self.all_departed_units.clear()
clear_flag(self.expand_name('departed'))
Once a unit is departed, it will no longer show up in
:attr:all_joined_units
. Note that units are considered departed as
soon as the departed hook is entered, which differs slightly from how
the Juju primitives behave (departing units are still returned from
related-units
until after the departed hook is complete).
This collection is a :class:KeyList
, so can be used as a mapping to
look up units by their unit name, or iterated or accessed by index.
A list view of all the units of all relations attached to this
:class:~charms.reactive.endpoints.Endpoint
.
This is actually a
:class:~charms.reactive.endpoints.CombinedUnitsView
, so the units
will be in order by relation ID and then unit name, and you can access a
merged view of all the units' data as a single mapping. You should be
very careful when using the merged data collections, however, and
consider carefully what will happen when the endpoint has multiple
relations and multiple remote units on each. It is probably better to
iterate over each unit and handle its data individually. See
:class:~charms.reactive.endpoints.CombinedUnitsView
for an
explanation of how the merged data collections work.
Note that, because a given application might be related multiple times on a given endpoint, units may show up in this collection more than once.
.. deprecated:: 0.6.1
Use :attr:all_joined_units
instead
Relation name of this endpoint.
Whether this endpoint has remote applications attached to it.
.. deprecated:: 0.6.3
Use :attr:is_joined
instead
Method that subclasses can override to perform any flag management needed during startup.
This will be called automatically after the framework-managed automatic flags have been updated.
Register a manual job.
The job data should be the (unserialized) data defining the job.
To ensure uniqueness, a UUID will be added to the job name, and it will be injected into the job data.
If a CA cert is given, the value of any ca_file field in the job data will be replaced with a filename after the CA cert data is written, so a placeholder value should be used.
If a client cert and key are given, the value of any cert_file/key_file fields in the job data will be replaced with filenames pointing to the corresponding files after there data is written.
Collection of :class:Relation
instances that are established for
this :class:Endpoint
.
This is a :class:KeyList
, so it can be iterated and indexed as a list,
or you can look up relations by their ID. For example::
rel0 = endpoint.relations[0]
assert rel0 is endpoint.relations[rel0.relation_id]
assert all(rel is endpoint.relations[rel.relation_id]
for rel in endpoint.relations)
print(', '.join(endpoint.relations.keys()))
A list of all requests which have been submitted.
A list of all responses which have been received.