~chris.macnaughton/charms/trusty/ceph-mon/trunk

« back to all changes in this revision

Viewing changes to hooks/ceph.py

  • Committer: James Page
  • Date: 2012-10-04 13:24:12 UTC
  • Revision ID: james.page@canonical.com-20121004132412-inhybi1vhf0f3wuj
Updated README verbosity, added checks to harden ceph admin-daemon usage in ceph utils

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
import subprocess
12
12
import time
13
13
import utils
 
14
import os
14
15
 
15
16
QUORUM = ['leader', 'peon']
16
17
 
17
18
 
18
19
def is_quorum():
 
20
    asok = "/var/run/ceph/ceph-mon.{}.asok".format(utils.get_unit_hostname())
19
21
    cmd = [
20
22
        "ceph",
21
23
        "--admin-daemon",
22
 
        "/var/run/ceph/ceph-mon.{}.asok".format(utils.get_unit_hostname()),
 
24
        asok,
23
25
        "mon_status"
24
26
        ]
25
 
 
26
 
    try:
27
 
        result = json.loads(subprocess.check_output(cmd))
28
 
    except subprocess.CalledProcessError:
29
 
        return False
30
 
 
31
 
    if result['state'] in QUORUM:
32
 
        return True
 
27
    if os.path.exists(asok):
 
28
        try:
 
29
            result = json.loads(subprocess.check_output(cmd))
 
30
        except subprocess.CalledProcessError:
 
31
            return False
 
32
        except ValueError:
 
33
            # Non JSON response from mon_status
 
34
            return False
 
35
        if result['state'] in QUORUM:
 
36
            return True
 
37
        else:
 
38
            return False
33
39
    else:
34
40
        return False
35
41
 
40
46
 
41
47
 
42
48
def add_bootstrap_hint(peer):
 
49
    asok = "/var/run/ceph/ceph-mon.{}.asok".format(utils.get_unit_hostname())
43
50
    cmd = [
44
51
        "ceph",
45
52
        "--admin-daemon",
46
 
        "/var/run/ceph/ceph-mon.{}.asok".format(utils.get_unit_hostname()),
 
53
        asok,
47
54
        "add_bootstrap_peer_hint",
48
55
        peer
49
56
        ]
50
 
    # Ignore any errors for this call
51
 
    subprocess.call(cmd)
 
57
    if os.path.exists(asok):
 
58
        # Ignore any errors for this call
 
59
        subprocess.call(cmd)