]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: Device - add vg_free property
authorJan Fajerski <jfajerski@suse.com>
Mon, 27 Apr 2020 09:34:19 +0000 (11:34 +0200)
committerJan Fajerski <jfajerski@suse.com>
Wed, 7 Oct 2020 09:22:39 +0000 (11:22 +0200)
This new property returns the free space in any VGs present. If no VGs
are on the device we project how much space a VG will have.

Signed-off-by: Jan Fajerski <jfajerski@suse.com>
(cherry picked from commit b34f130f30daeca034b6b2365cc5a832ba8faa56)

src/ceph-volume/ceph_volume/util/device.py

index 572e2afaea4cf510e5b4ee6b09e7031e23120f8c..f5e418ad7631421f7312b0d24f0f11cad1cbe4ad 100644 (file)
@@ -421,10 +421,39 @@ class Device(object):
     @property
     def vg_free_percent(self):
         if self.vgs:
-            return [vg.vg_free_count / vg.vg_extent_count for vg in self.vgs]
+            return [vg.free_percent for vg in self.vgs]
         else:
             return [1]
 
+    @property
+    def vg_size(self):
+        if self.vgs:
+            return [vg.size for vg in self.vgs]
+        else:
+            # TODO fix this...we can probably get rid of vg_free
+            return self.vg_free
+
+    @property
+    def vg_free(self):
+        '''
+        Returns the free space in all VGs on this device. If no VGs are
+        present, returns the disk size.
+        '''
+        if self.vgs:
+            return [vg.free for vg in self.vgs]
+        else:
+            # We could also query 'lvmconfig
+            # --typeconfig full' and use allocations -> physical_extent_size
+            # value to project the space for a vg
+            # assuming 4M extents here
+            extent_size = 4194304
+            vg_free = int(self.size / extent_size) * extent_size
+            if self.size % 4194304 == 0:
+                # If the extent size divides size exactly, deduct on extent for
+                # LVM metadata
+                vg_free -= extent_size
+            return [vg_free]
+
     def _check_generic_reject_reasons(self):
         reasons = [
             ('removable', 1, 'removable'),