summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ceph/__init__.py53
1 files changed, 11 insertions, 42 deletions
diff --git a/ceph/__init__.py b/ceph/__init__.py
index 6982155..b238792 100644
--- a/ceph/__init__.py
+++ b/ceph/__init__.py
@@ -11,7 +11,6 @@
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
15import ctypes 14import ctypes
16import collections 15import collections
17import json 16import json
@@ -321,52 +320,22 @@ def set_hdd_read_ahead(dev_name, read_ahead_sectors=256):
321 320
322def get_block_uuid(block_dev): 321def get_block_uuid(block_dev):
323 """ 322 """
324 This queries blkid to get the uuid for a block device. Note: This function 323 This queries blkid to get the uuid for a block device.
325 needs to be called with root priv. It will raise an error otherwise.
326 :param block_dev: Name of the block device to query. 324 :param block_dev: Name of the block device to query.
327 :return: The UUID of the device or None on Error. Raises OSError 325 :return: The UUID of the device or None on Error.
328 """ 326 """
329 try: 327 try:
330 blkid = ctypes.cdll.LoadLibrary("libblkid.so") 328 block_info = subprocess.check_output(
331 # Header signature 329 ['blkid', '-o', 'export', block_dev])
332 # extern int blkid_probe_lookup_value(blkid_probe pr, const char *name, 330 for tag in block_info.split('\n'):
333 # const char **data, size_t *len); 331 parts = tag.split('=')
334 blkid.blkid_new_probe_from_filename.argtypes = [ctypes.c_char_p] 332 if parts[0] == 'UUID':
335 blkid.blkid_probe_lookup_value.argtypes = [ctypes.c_void_p, 333 return parts[1]
336 ctypes.c_char_p,
337 POINTER(ctypes.c_char_p),
338 POINTER(ctypes.c_ulong)]
339 except OSError as err:
340 log('get_block_uuid loading libblkid.so failed with error: {}'.format(
341 os.strerror(err.errno)),
342 level=ERROR)
343 raise err
344 if not os.path.exists(block_dev):
345 return None 334 return None
346 probe = blkid.blkid_new_probe_from_filename(ctypes.c_char_p(block_dev)) 335 except subprocess.CalledProcessError as err:
347 if probe < 0: 336 log('get_block_uuid failed with error: {}'.format(err.output),
348 log('get_block_uuid new_probe_from_filename failed: {}'.format(
349 os.strerror(probe)),
350 level=ERROR)
351 raise OSError(probe, os.strerror(probe))
352 result = blkid.blkid_do_probe(probe)
353 if result != 0:
354 log('get_block_uuid do_probe failed with error: {}'.format(
355 os.strerror(result)),
356 level=ERROR)
357 raise OSError(result, os.strerror(result))
358 uuid = ctypes.c_char_p()
359 result = blkid.blkid_probe_lookup_value(probe,
360 ctypes.c_char_p(
361 'UUID'.encode('ascii')),
362 byref(uuid), None)
363 if result < 0:
364 log('get_block_uuid lookup_value failed with error: {}'.format(
365 os.strerror(result)),
366 level=ERROR) 337 level=ERROR)
367 raise OSError(result, os.strerror(result)) 338 return None
368 blkid.blkid_free_probe(probe)
369 return ctypes.string_at(uuid).decode('ascii')
370 339
371 340
372def check_max_sectors(save_settings_dict, 341def check_max_sectors(save_settings_dict,