-
Notifications
You must be signed in to change notification settings - Fork 1
/
requires.py
61 lines (51 loc) · 1.95 KB
/
requires.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
56
57
58
59
60
61
from charms.reactive import (
Endpoint,
clear_flag,
data_changed,
is_data_changed,
toggle_flag
)
class ContainerRuntimeRequires(Endpoint):
def manage_flags(self):
toggle_flag(self.expand_name('endpoint.{endpoint_name}.available'),
self.is_joined)
toggle_flag(self.expand_name('endpoint.{endpoint_name}.reconfigure'),
self.is_joined and self._config_changed())
def _config_changed(self):
"""
Determine if our received data has changed.
:return: Boolean
"""
# NB: this call should match whatever we're tracking in handle_remote_config
return is_data_changed('containerd.remote_config',
[self.get_sandbox_image()])
def handle_remote_config(self):
"""
Keep track of received data so we can know if it changes.
:return: None
"""
clear_flag(self.expand_name('endpoint.{endpoint_name}.reconfigure'))
# Presently, we only care about one piece of remote config. Expand
# the list as needed.
data_changed('containerd.remote_config',
[self.get_sandbox_image()])
def get_sandbox_image(self):
"""
Get the sandbox image URI if a remote has published one.
:return: String: remotely configured sandbox image
"""
return self.all_joined_units.received.get('sandbox_image')
def set_config(self, socket, runtime, nvidia_enabled):
"""
Set the configuration to be published.
:param socket: String uri to runtime socket
:param runtime: String runtime executable
:param nvidia_enabled: Boolean nvidia runtime enabled
:return: None
"""
for relation in self.relations:
relation.to_publish.update({
'socket': socket,
'runtime': runtime,
'nvidia_enabled': nvidia_enabled
})