This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
provides.py
55 lines (45 loc) · 1.95 KB
/
provides.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from charms.reactive import (
toggle_flag,
RequesterEndpoint,
)
from .common import JobRequest
class PrometheusManualProvides(RequesterEndpoint):
REQUEST_CLASS = JobRequest
def manage_flags(self):
super().manage_flags()
toggle_flag(self.expand_name('endpoint.{endpoint_name}.available'),
self.is_joined and self.requests)
def register_job(
self,
job_name,
job_data,
ca_cert=None,
client_cert=None,
client_key=None,
relation=None,
):
"""
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.
If a specific relation is not given, the job will be registered with
every related Prometheus.
"""
# we might be connected to multiple prometheuses for some strange
# reason, so just send the job to all of them
relations = [relation] if relation is not None else self.relations
for relation in relations:
JobRequest.create_or_update(match_fields=['job_name'],
relation=relation,
job_name=job_name,
job_data=job_data,
ca_cert=ca_cert,
client_cert=client_cert,
client_key=client_key)