~1chb1n/charms/trusty/ceph-radosgw/next.1601-test-update2

« back to all changes in this revision

Viewing changes to hooks/ceph.py

  • Committer: James Page
  • Date: 2013-02-08 11:12:07 UTC
  • mfrom: (9.1.4 ceph-radosgw)
  • Revision ID: james.page@canonical.com-20130208111207-gt2222i1heux7hl6
Add support for Ceph Bobtail LTS release

- Add support for keystone based authentication (use keystone charm).
- Misc other updates including new cephx options.

Fixes

- Improve hostname -> ip address resolution
- Disable 100-continue processing as requires a fork of mod_fastcgi
- Resync utils.py, ceph.py across ceph charms.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
import time
13
13
import utils
14
14
import os
 
15
import apt_pkg as apt
15
16
 
16
 
QUORUM = ['leader', 'peon']
 
17
LEADER = 'leader'
 
18
PEON = 'peon'
 
19
QUORUM = [LEADER, PEON]
17
20
 
18
21
 
19
22
def is_quorum():
40
43
        return False
41
44
 
42
45
 
 
46
def is_leader():
 
47
    asok = "/var/run/ceph/ceph-mon.{}.asok".format(utils.get_unit_hostname())
 
48
    cmd = [
 
49
        "ceph",
 
50
        "--admin-daemon",
 
51
        asok,
 
52
        "mon_status"
 
53
        ]
 
54
    if os.path.exists(asok):
 
55
        try:
 
56
            result = json.loads(subprocess.check_output(cmd))
 
57
        except subprocess.CalledProcessError:
 
58
            return False
 
59
        except ValueError:
 
60
            # Non JSON response from mon_status
 
61
            return False
 
62
        if result['state'] == LEADER:
 
63
            return True
 
64
        else:
 
65
            return False
 
66
    else:
 
67
        return False
 
68
 
 
69
 
43
70
def wait_for_quorum():
44
71
    while not is_quorum():
45
72
        time.sleep(3)
58
85
        # Ignore any errors for this call
59
86
        subprocess.call(cmd)
60
87
 
 
88
DISK_FORMATS = [
 
89
    'xfs',
 
90
    'ext4',
 
91
    'btrfs'
 
92
    ]
 
93
 
61
94
 
62
95
def is_osd_disk(dev):
63
96
    try:
72
105
        pass
73
106
    return False
74
107
 
 
108
 
 
109
def rescan_osd_devices():
 
110
    cmd = [
 
111
        'udevadm', 'trigger',
 
112
        '--subsystem-match=block', '--action=add'
 
113
        ]
 
114
 
 
115
    subprocess.call(cmd)
 
116
 
 
117
 
 
118
def zap_disk(dev):
 
119
    cmd = ['sgdisk', '--zap-all', dev]
 
120
    subprocess.check_call(cmd)
 
121
 
 
122
 
75
123
_bootstrap_keyring = "/var/lib/ceph/bootstrap-osd/ceph.keyring"
76
124
 
77
125
 
 
126
def is_bootstrapped():
 
127
    return os.path.exists(_bootstrap_keyring)
 
128
 
 
129
 
 
130
def wait_for_bootstrap():
 
131
    while (not is_bootstrapped()):
 
132
        time.sleep(3)
 
133
 
 
134
 
78
135
def import_osd_bootstrap_key(key):
79
136
    if not os.path.exists(_bootstrap_keyring):
80
137
        cmd = [
98
155
 
99
156
 
100
157
def get_osd_bootstrap_key():
101
 
    cmd = [
102
 
        'ceph',
103
 
        '--name', 'mon.',
104
 
        '--keyring',
105
 
        '/var/lib/ceph/mon/ceph-{}/keyring'.format(
106
 
                                        utils.get_unit_hostname()
107
 
                                        ),
108
 
        'auth', 'get-or-create', 'client.bootstrap-osd',
109
 
        ]
110
 
    # Add capabilities
111
 
    for subsystem, subcaps in _osd_bootstrap_caps.iteritems():
112
 
        cmd.extend([
113
 
            subsystem,
114
 
            '; '.join(subcaps),
115
 
            ])
116
 
    output = subprocess.check_output(cmd).strip()  # IGNORE:E1103
117
 
    # get-or-create appears to have different output depending
118
 
    # on whether its 'get' or 'create'
119
 
    # 'create' just returns the key, 'get' is more verbose and
120
 
    # needs parsing
121
 
    key = None
122
 
    if len(output.splitlines()) == 1:
123
 
        key = output
124
 
    else:
125
 
        for element in output.splitlines():
126
 
            if 'key' in element:
127
 
                key = element.split(' = ')[1].strip()  # IGNORE:E1103
128
 
    return key
 
158
    return get_named_key('bootstrap-osd', _osd_bootstrap_caps)
129
159
 
130
160
 
131
161
_radosgw_keyring = "/etc/ceph/keyring.rados.gateway"
150
180
 
151
181
 
152
182
def get_radosgw_key():
 
183
    return get_named_key('radosgw.gateway', _radosgw_caps)
 
184
 
 
185
 
 
186
_default_caps = {
 
187
    'mon': ['allow r'],
 
188
    'osd': ['allow rwx']
 
189
    }
 
190
 
 
191
 
 
192
def get_named_key(name, caps=None):
 
193
    caps = caps or _default_caps
153
194
    cmd = [
154
195
        'ceph',
155
196
        '--name', 'mon.',
157
198
        '/var/lib/ceph/mon/ceph-{}/keyring'.format(
158
199
                                        utils.get_unit_hostname()
159
200
                                        ),
160
 
        'auth', 'get-or-create', 'client.radosgw.gateway',
 
201
        'auth', 'get-or-create', 'client.{}'.format(name),
161
202
        ]
162
203
    # Add capabilities
163
 
    for subsystem, subcaps in _radosgw_caps.iteritems():
 
204
    for subsystem, subcaps in caps.iteritems():
164
205
        cmd.extend([
165
206
            subsystem,
166
207
            '; '.join(subcaps),
178
219
            if 'key' in element:
179
220
                key = element.split(' = ')[1].strip()  # IGNORE:E1103
180
221
    return key
 
222
 
 
223
 
 
224
def get_ceph_version(package=None):
 
225
    apt.init()
 
226
    cache = apt.Cache()
 
227
    pkg = cache[package or 'ceph']
 
228
    if pkg.current_ver:
 
229
        return apt.upstream_version(pkg.current_ver.ver_str)
 
230
    else:
 
231
        return None
 
232
 
 
233
 
 
234
def version_compare(a, b):
 
235
    return apt.version_compare(a, b)