47
asok = "/var/run/ceph/ceph-mon.{}.asok".format(utils.get_unit_hostname())
54
if os.path.exists(asok):
56
result = json.loads(subprocess.check_output(cmd))
57
except subprocess.CalledProcessError:
60
# Non JSON response from mon_status
62
if result['state'] == LEADER:
43
70
def wait_for_quorum():
44
71
while not is_quorum():
88
116
return os.path.exists(_bootstrap_keyring)
119
def wait_for_bootstrap():
120
while (not is_bootstrapped()):
91
124
def import_osd_bootstrap_key(key):
92
125
if not os.path.exists(_bootstrap_keyring):
100
133
subprocess.check_call(cmd)
102
135
# OSD caps taken from ceph-create-keys
103
_osd_bootstrap_caps = [
104
'allow command osd create ...',
105
'allow command osd crush set ...',
106
r'allow command auth add * osd allow\ * mon allow\ rwx',
107
'allow command mon getmap'
136
_osd_bootstrap_caps = {
138
'allow command osd create ...',
139
'allow command osd crush set ...',
140
r'allow command auth add * osd allow\ * mon allow\ rwx',
141
'allow command mon getmap'
111
146
def get_osd_bootstrap_key():
147
return get_named_key('bootstrap-osd', _osd_bootstrap_caps)
150
_radosgw_keyring = "/etc/ceph/keyring.rados.gateway"
153
def import_radosgw_key(key):
154
if not os.path.exists(_radosgw_keyring):
159
'--name=client.radosgw.gateway',
160
'--add-key={}'.format(key)
162
subprocess.check_call(cmd)
164
# OSD caps taken from ceph-create-keys
171
def get_radosgw_key():
172
return get_named_key('radosgw.gateway', _radosgw_caps)
181
def get_named_key(name, caps=None):
182
caps = caps or _default_caps
114
185
'--name', 'mon.',
116
187
'/var/lib/ceph/mon/ceph-{}/keyring'.format(
117
188
utils.get_unit_hostname()
119
'auth', 'get-or-create', 'client.bootstrap-osd',
120
'mon', '; '.join(_osd_bootstrap_caps)
190
'auth', 'get-or-create', 'client.{}'.format(name),
193
for subsystem, subcaps in caps.iteritems():
122
198
output = subprocess.check_output(cmd).strip() # IGNORE:E1103
123
199
# get-or-create appears to have different output depending
124
200
# on whether its 'get' or 'create'
132
208
if 'key' in element:
133
209
key = element.split(' = ')[1].strip() # IGNORE:E1103
213
def get_ceph_version():
218
return apt.upstream_version(pkg.current_ver.ver_str)
223
def version_compare(a, b):
224
return apt.version_compare(a, b)