]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume util.disk add a helper to remove partitions
authorAlfredo Deza <adeza@redhat.com>
Tue, 27 Nov 2018 14:45:17 +0000 (09:45 -0500)
committerAlfredo Deza <adeza@redhat.com>
Fri, 30 Nov 2018 17:24:18 +0000 (12:24 -0500)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
src/ceph-volume/ceph_volume/util/disk.py

index 995a9685649dd5d1277cf6783ff3b4d35c5ffdac..3179e67b745ae0904405b521ad0cd45dab1e7665 100644 (file)
@@ -127,6 +127,23 @@ def get_device_from_partuuid(partuuid):
     return ' '.join(out).strip()
 
 
+def remove_partition(device):
+    """
+    Removes a partition using parted
+
+    :param device: A ``Device()`` object
+    """
+    parent_device = '/dev/%s' % device.disk_api['PKNAME']
+    udev_info = udevadm_property(device.abspath)
+    partition_number = udev_info.get('ID_PART_ENTRY_NUMBER')
+    if not partition_number:
+        raise RuntimeError('Unable to detect the partition number for device: %s' % device_path)
+
+    process.run(
+        ['parted', parent_device, '--script', '--', 'rm', partition_number]
+    )
+
+
 def _stat_is_device(stat_obj):
     """
     Helper function that will interpret ``os.stat`` output directly, so that other