6
from subprocess import CalledProcessError
7
from common import write_json_file, JujuBroker, LandscapeBroker
8
from common import write_json_file, JujuBroker, LandscapeBroker, chown
10
get_ceph_client_path, write_ceph_client_keyring, write_ceph_client_config)
10
13
def _write_certificate(certificate, filename):
109
def ceph_relation_changed(juju_broker, landscape_broker):
110
relation_config = juju_broker.get_relation_config()
111
# The key is only reported once the ceph ring has quorum (there are enough
112
# nodes in the service). There's nothing to do until the key is provided.
113
if "key" not in relation_config:
115
"Ceph key not reported in relation config, nothing to do.")
118
ceph_client_dir = get_ceph_client_path(landscape_broker)
119
if not os.path.exists(ceph_client_dir):
120
os.mkdir(ceph_client_dir)
121
chown(ceph_client_dir)
123
# Create ceph client keyring and config for landscape-client use.
125
keyring_file = write_ceph_client_keyring(
126
landscape_broker, "landscape-client", relation_config["key"])
127
except CalledProcessError as err:
129
"Writing ceph keyring file failed with code %d" % err.returncode)
133
write_ceph_client_config(
134
landscape_broker, relation_config["auth"], keyring_file,
135
relation_config["private-address"])
136
except IOError as err:
137
juju_broker.log("Writing ceph configuration file failed: %s" % err)
140
juju_broker.log("Ceph configuration written to file.")
107
145
"config-changed": config_changed,
108
146
"upgrade-charm": upgrade_charm,
114
152
"container-relation-departed": lambda juju_broker, landscape_broker:
115
153
landscape_broker.clear_registration(),
116
154
"ceph-client-relation-joined": container_relation_joined,
155
"ceph-client-relation-changed": ceph_relation_changed,
117
156
"ceph-client-relation-departed": lambda juju_broker, landscape_broker:
118
157
landscape_broker.clear_registration()}