]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
ceph-volume: add strategies.py to for shared code
authorJan Fajerski <jfajerski@suse.com>
Mon, 26 Nov 2018 13:01:57 +0000 (14:01 +0100)
committerJan Fajerski <jfajerski@suse.com>
Wed, 12 Dec 2018 14:02:59 +0000 (15:02 +0100)
Signed-off-by: Jan Fajerski <jfajerski@suse.com>
src/ceph-volume/ceph_volume/devices/lvm/strategies/strategies.py [new file with mode: 0644]

diff --git a/src/ceph-volume/ceph_volume/devices/lvm/strategies/strategies.py b/src/ceph-volume/ceph_volume/devices/lvm/strategies/strategies.py
new file mode 100644 (file)
index 0000000..d4ec5a7
--- /dev/null
@@ -0,0 +1,50 @@
+import json
+
+class Strategy(object):
+
+    def __init__(self, devices, args):
+        self.args = args
+        self.osds_per_device = args.osds_per_device
+        self.devices = devices
+        self.hdds = [device for device in devices if device.sys_api['rotational'] == '1']
+        self.ssds = [device for device in devices if device.sys_api['rotational'] == '0']
+        self.computed = {'osds': [], 'vgs': [], 'filtered_devices': args.filtered_devices}
+
+    def validate_compute(self):
+        if self.devices:
+            self.validate()
+            self.compute()
+        else:
+            self.computed["changed"] = False
+
+    def report_json(self):
+        print(json.dumps(self.computed, indent=4, sort_keys=True))
+
+    @property
+    def total_osds(self):
+        if self.hdds:
+            return len(self.hdds) * self.osds_per_device
+        else:
+            return len(self.ssds) * self.osds_per_device
+
+    # protect against base class instantiation and incomplete implementations.
+    # We could also use the abc module and implement this as an
+    # AbstractBaseClass
+    def compute(self):
+        raise NotImplementedError('compute() must be implemented in a child class')
+
+    def execute(self):
+        raise NotImplementedError('execute() must be implemented in a child class')
+
+class MixedStrategy(Strategy):
+
+    def get_common_vg(self):
+        # find all the vgs associated with the current device
+        for ssd in self.ssds:
+            for pv in ssd.pvs_api:
+                vg = self.system_vgs.get(vg_name=pv.vg_name)
+                if not vg:
+                    continue
+                # this should give us just one VG, it would've been caught by
+                # the validator otherwise
+                return vg