summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Holcombe <xfactor973@gmail.com>2017-01-30 13:11:48 -0800
committerChris Holcombe <xfactor973@gmail.com>2017-01-30 13:15:30 -0800
commita7f29e52efdf2a047306fa3d064040c97678d82d (patch)
tree27a01e83d749d1e28ca37dc1b9ba6291a0914070
parentf11843671bf4cda4ae6ea37ece17197174c0fcd7 (diff)
Use libblkid instead of CLI
This patch changes the get_block_uuid function around to use libblkid instead of scraping the cli. Closes-Bug: 1660240 Change-Id: Ieebf5714bceb9d41c70fc1dd0cfd17c903c3a107
Notes
Notes (review): Code-Review+1: Alex Kavanagh <alex.kavanagh@canonical.com> Code-Review+2: James Page <james.page@canonical.com> Workflow+1: James Page <james.page@canonical.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Wed, 01 Feb 2017 09:32:53 +0000 Reviewed-on: https://review.openstack.org/426929 Project: openstack/charms.ceph Branch: refs/heads/master
-rw-r--r--ceph/__init__.py54
1 files changed, 42 insertions, 12 deletions
diff --git a/ceph/__init__.py b/ceph/__init__.py
index db3772b..375b19e 100644
--- a/ceph/__init__.py
+++ b/ceph/__init__.py
@@ -11,6 +11,7 @@
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and 12# See the License for the specific language governing permissions and
13# limitations under the License. 13# limitations under the License.
14from _ctypes import POINTER, byref
14import ctypes 15import ctypes
15import collections 16import collections
16import json 17import json
@@ -309,22 +310,52 @@ def set_hdd_read_ahead(dev_name, read_ahead_sectors=256):
309 310
310def get_block_uuid(block_dev): 311def get_block_uuid(block_dev):
311 """ 312 """
312 This queries blkid to get the uuid for a block device. 313 This queries blkid to get the uuid for a block device. Note: This function
314 needs to be called with root priv. It will raise an error otherwise.
313 :param block_dev: Name of the block device to query. 315 :param block_dev: Name of the block device to query.
314 :return: The UUID of the device or None on Error. 316 :return: The UUID of the device or None on Error. Raises OSError
315 """ 317 """
316 try: 318 try:
317 block_info = subprocess.check_output( 319 blkid = ctypes.cdll.LoadLibrary("libblkid.so")
318 ['blkid', '-o', 'export', block_dev]) 320 # Header signature
319 for tag in block_info.split('\n'): 321 # extern int blkid_probe_lookup_value(blkid_probe pr, const char *name,
320 parts = tag.split('=') 322 # const char **data, size_t *len);
321 if parts[0] == 'UUID': 323 blkid.blkid_new_probe_from_filename.argtypes = [ctypes.c_char_p]
322 return parts[1] 324 blkid.blkid_probe_lookup_value.argtypes = [ctypes.c_void_p,
323 return None 325 ctypes.c_char_p,
324 except subprocess.CalledProcessError as err: 326 POINTER(ctypes.c_char_p),
325 log('get_block_uuid failed with error: {}'.format(err.output), 327 POINTER(ctypes.c_ulong)]
328 except OSError as err:
329 log('get_block_uuid loading libblkid.so failed with error: {}'.format(
330 os.strerror(err.errno)),
326 level=ERROR) 331 level=ERROR)
332 raise err
333 if not os.path.exists(block_dev):
327 return None 334 return None
335 probe = blkid.blkid_new_probe_from_filename(ctypes.c_char_p(block_dev))
336 if probe < 0:
337 log('get_block_uuid new_probe_from_filename failed: {}'.format(
338 os.strerror(probe)),
339 level=ERROR)
340 raise OSError(probe, os.strerror(probe))
341 result = blkid.blkid_do_probe(probe)
342 if result != 0:
343 log('get_block_uuid do_probe failed with error: {}'.format(
344 os.strerror(result)),
345 level=ERROR)
346 raise OSError(result, os.strerror(result))
347 uuid = ctypes.c_char_p()
348 result = blkid.blkid_probe_lookup_value(probe,
349 ctypes.c_char_p(
350 'UUID'.encode('ascii')),
351 byref(uuid), None)
352 if result < 0:
353 log('get_block_uuid lookup_value failed with error: {}'.format(
354 os.strerror(result)),
355 level=ERROR)
356 raise OSError(result, os.strerror(result))
357 blkid.blkid_free_probe(probe)
358 return ctypes.string_at(uuid).decode('ascii')
328 359
329 360
330def check_max_sectors(save_settings_dict, 361def check_max_sectors(save_settings_dict,
@@ -1615,7 +1646,6 @@ def list_pools(service):
1615 log("rados lspools failed with error: {}".format(err.output)) 1646 log("rados lspools failed with error: {}".format(err.output))
1616 raise 1647 raise
1617 1648
1618
1619# A dict of valid ceph upgrade paths. Mapping is old -> new 1649# A dict of valid ceph upgrade paths. Mapping is old -> new
1620UPGRADE_PATHS = { 1650UPGRADE_PATHS = {
1621 'firefly': 'hammer', 1651 'firefly': 'hammer',