This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provides.py
52 lines (43 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
#!/usr/bin/env python3
# Copyright (C) 2016 Ghent University
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import json
import yaml
from charms.reactive import hook
from charms.reactive import RelationBase
from charms.reactive import scopes
class DockerImageHostProvides(RelationBase):
scope = scopes.UNIT
@hook('{provides:docker-image-host}-relation-{joined,changed}')
def changed(self):
self.set_state('{relation_name}.available')
@hook('{provides:docker-image-host}-relation-{departed}')
def broken(self):
self.remove_state('{relation_name}.available')
self.set_state('{relation_name}.broken')
@property
def container_requests(self):
container_requests = []
for conv in self.conversations():
conv_con_reqs = yaml.safe_load(
conv.get_remote('container-requests', "[]"))
container_requests.extend(conv_con_reqs)
return container_requests
def send_running_containers(self, containers):
""" There is no way to send each unit only the containers it requested due to limitations
in Juju. Even with scope=UNIT, the same data is still broadcasted to all units of a single
service. See https://tinyurl.com/hjwfwdn """
for conv in self.conversations():
conv.set_remote('running-containers', json.dumps(containers))