~ahasenack/charms/precise/landscape-client/fix-registration-relation

« back to all changes in this revision

Viewing changes to hooks/ceph.py

  • Committer: Adam Collard
  • Date: 2013-11-20 09:37:22 UTC
  • mfrom: (32.1.4 fix-ceph-relation-error)
  • Revision ID: adam.collard@canonical.com-20131120093722-1fdayh1b1rdgymyq
Merged fix-ceph-relation-error [r=bjornt,tealeg][a=adam-collard]

Move ceph-relation-changed and ceph-relation-broken hooks into hooks.py and therefore more easily testable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import os
2
2
from subprocess import check_output
3
3
 
4
 
from common import get_client_config, chown
 
4
from common import LandscapeBroker, chown
5
5
 
6
6
 
7
7
CEPH_CLIENT_DIR = "ceph-client"
16
16
"""
17
17
 
18
18
 
19
 
def get_ceph_client_path():
 
19
def get_ceph_client_path(landscape_broker):
20
20
    """Return the path for ceph client conf and keyring."""
21
 
    config = get_client_config()
22
 
    return os.path.join(config.data_path, CEPH_CLIENT_DIR)
23
 
 
24
 
 
25
 
def write_ceph_client_keyring(name, key):
 
21
    return os.path.join(landscape_broker.config.data_path, CEPH_CLIENT_DIR)
 
22
 
 
23
 
 
24
def write_ceph_client_keyring(landscape_broker, name, key):
26
25
    """Creates a ceph client keyring with the specified name and key.
27
26
 
28
27
    @param name: name of the key
29
28
    @param key: the key to include in the keyring
30
29
    """
31
 
    keyring_file = os.path.join(get_ceph_client_path(), CEPH_CLIENT_KEYRING)
 
30
    keyring_file = os.path.join(
 
31
        get_ceph_client_path(landscape_broker), CEPH_CLIENT_KEYRING)
32
32
    check_output(
33
33
        ["ceph-authtool", keyring_file, "--create-keyring",
34
34
         "--name=client.%s" % name, "--add-key=%s" % key])
36
36
    return keyring_file
37
37
 
38
38
 
39
 
def write_ceph_client_config(auth, keyring, mon_address):
 
39
def write_ceph_client_config(landscape_broker, auth, keyring, mon_address):
40
40
    """Write ceph client configuration file.
41
41
 
42
42
    @param auth: authentication type
43
43
    @param keyring: absolute path of the keyring file
44
44
    @param mon_address: address of the ceph monitor
45
45
    """
46
 
    ceph_client_conf = os.path.join(get_ceph_client_path(), CEPH_CLIENT_CONF)
 
46
    ceph_client_conf = os.path.join(
 
47
        get_ceph_client_path(landscape_broker), CEPH_CLIENT_CONF)
47
48
    with open(ceph_client_conf, "w") as file:
48
49
        file.write(
49
50
            CONF_TEMPLATE % {