~adam-collard/charms/trusty/landscape-client/trunk

« back to all changes in this revision

Viewing changes to hooks/ceph-client-relation-changed

  • Committer: Adam Collard
  • Date: 2013-11-19 12:39:44 UTC
  • mto: This revision was merged to the branch mainline in revision 33.
  • Revision ID: adam.collard@canonical.com-20131119123944-vqv3t6323n6tsbqb
Move logic for ceph-client-relation-changed into hooks.py
 * Make it testable
 * Test it
 * Bump revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
 
import os
4
 
import sys
5
 
 
6
 
from subprocess import CalledProcessError
7
 
from common import get_relation_config, chown, log
8
 
from ceph import (
9
 
    get_ceph_client_path, write_ceph_client_keyring, write_ceph_client_config)
10
 
 
11
 
 
12
 
relation_config = get_relation_config()
13
 
# The key is only reported once the ceph ring has quorum (there are enough
14
 
# nodes in the service). There's nothing to do until the key is provided.
15
 
if "key" not in relation_config:
16
 
    log("Ceph key not reported in relation config, nothing to do.")
17
 
    sys.exit(0)
18
 
 
19
 
ceph_client_dir = get_ceph_client_path()
20
 
if not os.path.exists(ceph_client_dir):
21
 
    os.mkdir(ceph_client_dir)
22
 
    chown(ceph_client_dir)
23
 
 
24
 
# Create ceph client keyring and config for landscape-client use.
25
 
try:
26
 
    keyring_file = write_ceph_client_keyring(
27
 
        "landscape-client", relation_config["key"])
28
 
except CalledProcessError as err:
29
 
    log("Writing ceph keyring file failed with code %d" % err.returncode)
30
 
    sys.exit(1)
31
 
 
32
 
try:
33
 
    write_ceph_client_config(
34
 
        relation_config["auth"], keyring_file,
35
 
        relation_config["private-address"])
36
 
    log("Ceph configuration written to file.")
37
 
except IOError as err:
38
 
    log("Writing ceph configuratin file failed: %s" % err)
39
 
    sys.exit(1)