Merge lp:~james-page/charms/precise/ceph-osd/dir-support into lp:~charmers/charms/precise/ceph-osd/trunk

Proposed by James Page
Status: Merged
Approved by: Mark Mims
Approved revision: 21
Merge reported by: Mark Mims
Merged at revision: not available
Proposed branch: lp:~james-page/charms/precise/ceph-osd/dir-support
Merge into: lp:~charmers/charms/precise/ceph-osd/trunk
Diff against target: 207 lines (+88/-22)
4 files modified
config.yaml (+3/-0)
hooks/ceph.py (+73/-17)
hooks/hooks.py (+11/-4)
revision (+1/-1)
To merge this branch: bzr merge lp:~james-page/charms/precise/ceph-osd/dir-support
Reviewer Review Type Date Requested Status
Mark Mims (community) Approve
Review via email: mp+182608@code.launchpad.net

Description of the change

This update add support for using directories to host ceph OSD's; allowing
use with the Juju local provider.

To post a comment you must log in.
Revision history for this message
Mark Mims (mark-mims) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'config.yaml'
--- config.yaml 2013-06-10 13:48:23 +0000
+++ config.yaml 2013-08-28 11:44:29 +0000
@@ -7,6 +7,9 @@
7 .7 .
8 These devices are the range of devices that will be checked for and8 These devices are the range of devices that will be checked for and
9 used across all service units.9 used across all service units.
10 .
11 For ceph >= 0.56.6 these can also be directories instead of devices - the
12 charm assumes anything not starting with /dev is a directory instead.
10 osd-journal:13 osd-journal:
11 type: string14 type: string
12 description: |15 description: |
1316
=== modified file 'hooks/ceph.py'
--- hooks/ceph.py 2013-07-08 08:33:02 +0000
+++ hooks/ceph.py 2013-08-28 11:44:29 +0000
@@ -15,14 +15,17 @@
15from charmhelpers.core.host import (15from charmhelpers.core.host import (
16 mkdir,16 mkdir,
17 service_restart,17 service_restart,
18 log18)
19from charmhelpers.core.hookenv import (
20 log,
21 ERROR,
19)22)
20from charmhelpers.contrib.storage.linux.utils import (23from charmhelpers.contrib.storage.linux.utils import (
21 zap_disk,24 zap_disk,
22 is_block_device25 is_block_device,
23)26)
24from utils import (27from utils import (
25 get_unit_hostname28 get_unit_hostname,
26)29)
2730
28LEADER = 'leader'31LEADER = 'leader'
@@ -119,6 +122,16 @@
119 return False122 return False
120123
121124
125def start_osds(devices):
126 # Scan for ceph block devices
127 rescan_osd_devices()
128 if get_ceph_version() >= "0.56.6":
129 # Use ceph-disk-activate for directory based OSD's
130 for dev_or_path in devices:
131 if os.path.exists(dev_or_path) and os.path.isdir(dev_or_path):
132 subprocess.check_call(['ceph-disk-activate', dev_or_path])
133
134
122def rescan_osd_devices():135def rescan_osd_devices():
123 cmd = [136 cmd = [
124 'udevadm', 'trigger',137 'udevadm', 'trigger',
@@ -161,9 +174,38 @@
161 ]174 ]
162}175}
163176
177_osd_bootstrap_caps_profile = {
178 'mon': [
179 'allow profile bootstrap-osd'
180 ]
181}
182
183
184def parse_key(raw_key):
185 # get-or-create appears to have different output depending
186 # on whether its 'get' or 'create'
187 # 'create' just returns the key, 'get' is more verbose and
188 # needs parsing
189 key = None
190 if len(raw_key.splitlines()) == 1:
191 key = raw_key
192 else:
193 for element in raw_key.splitlines():
194 if 'key' in element:
195 key = element.split(' = ')[1].strip() # IGNORE:E1103
196 return key
197
164198
165def get_osd_bootstrap_key():199def get_osd_bootstrap_key():
166 return get_named_key('bootstrap-osd', _osd_bootstrap_caps)200 try:
201 # Attempt to get/create a key using the OSD bootstrap profile first
202 key = get_named_key('bootstrap-osd',
203 _osd_bootstrap_caps_profile)
204 except:
205 # If that fails try with the older style permissions
206 key = get_named_key('bootstrap-osd',
207 _osd_bootstrap_caps)
208 return key
167209
168210
169_radosgw_keyring = "/etc/ceph/keyring.rados.gateway"211_radosgw_keyring = "/etc/ceph/keyring.rados.gateway"
@@ -214,19 +256,7 @@
214 subsystem,256 subsystem,
215 '; '.join(subcaps),257 '; '.join(subcaps),
216 ])258 ])
217 output = subprocess.check_output(cmd).strip() # IGNORE:E1103259 return parse_key(subprocess.check_output(cmd).strip()) # IGNORE:E1103
218 # get-or-create appears to have different output depending
219 # on whether its 'get' or 'create'
220 # 'create' just returns the key, 'get' is more verbose and
221 # needs parsing
222 key = None
223 if len(output.splitlines()) == 1:
224 key = output
225 else:
226 for element in output.splitlines():
227 if 'key' in element:
228 key = element.split(' = ')[1].strip() # IGNORE:E1103
229 return key
230260
231261
232def bootstrap_monitor_cluster(secret):262def bootstrap_monitor_cluster(secret):
@@ -291,6 +321,13 @@
291321
292322
293def osdize(dev, osd_format, osd_journal, reformat_osd=False):323def osdize(dev, osd_format, osd_journal, reformat_osd=False):
324 if dev.startswith('/dev'):
325 osdize_dev(dev, osd_format, osd_journal, reformat_osd)
326 else:
327 osdize_dir(dev)
328
329
330def osdize_dev(dev, osd_format, osd_journal, reformat_osd=False):
294 if not os.path.exists(dev):331 if not os.path.exists(dev):
295 log('Path {} does not exist - bailing'.format(dev))332 log('Path {} does not exist - bailing'.format(dev))
296 return333 return
@@ -327,6 +364,25 @@
327 subprocess.check_call(cmd)364 subprocess.check_call(cmd)
328365
329366
367def osdize_dir(path):
368 if os.path.exists(os.path.join(path, 'upstart')):
369 log('Path {} is already configured as an OSD - bailing'.format(path))
370 return
371
372 if get_ceph_version() < "0.56.6":
373 log('Unable to use directories for OSDs with ceph < 0.56.6',
374 level=ERROR)
375 raise
376
377 mkdir(path)
378 cmd = [
379 'ceph-disk-prepare',
380 '--data-dir',
381 path
382 ]
383 subprocess.check_call(cmd)
384
385
330def device_mounted(dev):386def device_mounted(dev):
331 return subprocess.call(['grep', '-wqs', dev + '1', '/proc/mounts']) == 0387 return subprocess.call(['grep', '-wqs', dev + '1', '/proc/mounts']) == 0
332388
333389
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2013-07-03 09:04:42 +0000
+++ hooks/hooks.py 2013-08-28 11:44:29 +0000
@@ -96,10 +96,10 @@
96 if ceph.is_bootstrapped():96 if ceph.is_bootstrapped():
97 log('ceph bootstrapped, rescanning disks')97 log('ceph bootstrapped, rescanning disks')
98 emit_cephconf()98 emit_cephconf()
99 for dev in config('osd-devices').split(' '):99 for dev in get_devices():
100 ceph.osdize(dev, config('osd-format'),100 ceph.osdize(dev, config('osd-format'),
101 config('osd-journal'), config('osd-reformat'))101 config('osd-journal'), config('osd-reformat'))
102 ceph.rescan_osd_devices()102 ceph.start_osds(get_devices())
103103
104 log('End config-changed hook.')104 log('End config-changed hook.')
105105
@@ -142,6 +142,13 @@
142 return False142 return False
143143
144144
145def get_devices():
146 if config('osd-devices'):
147 return config('osd-devices').split(' ')
148 else:
149 return []
150
151
145@hooks.hook('mon-relation-changed',152@hooks.hook('mon-relation-changed',
146 'mon-relation-departed')153 'mon-relation-departed')
147def mon_relation():154def mon_relation():
@@ -152,10 +159,10 @@
152 log('mon has provided conf- scanning disks')159 log('mon has provided conf- scanning disks')
153 emit_cephconf()160 emit_cephconf()
154 ceph.import_osd_bootstrap_key(bootstrap_key)161 ceph.import_osd_bootstrap_key(bootstrap_key)
155 for dev in config('osd-devices').split(' '):162 for dev in get_devices():
156 ceph.osdize(dev, config('osd-format'),163 ceph.osdize(dev, config('osd-format'),
157 config('osd-journal'), config('osd-reformat'))164 config('osd-journal'), config('osd-reformat'))
158 ceph.rescan_osd_devices()165 ceph.start_osds(get_devices())
159 else:166 else:
160 log('mon cluster has not yet provided conf')167 log('mon cluster has not yet provided conf')
161168
162169
=== modified file 'revision'
--- revision 2012-11-12 10:00:51 +0000
+++ revision 2013-08-28 11:44:29 +0000
@@ -1,1 +1,1 @@
17111

Subscribers

People subscribed via source and target branches