mirror of
https://github.com/ceph/ceph
synced 2024-12-28 14:34:13 +00:00
Merge pull request #25238 from jan--f/c-v-refactor-strategies-into-hierachy
ceph-volume: introduce class hierachy for strategies Reviewed-by: Alfredo Deza <adeza@redhat.com> Reviewed-by: Andrew Schoen <aschoen@redhat.com>
This commit is contained in:
commit
d178a5c278
@ -3,45 +3,27 @@ import json
|
||||
from ceph_volume.util import disk, prepare, str_to_int
|
||||
from ceph_volume.api import lvm
|
||||
from . import validators
|
||||
from .strategies import Strategy
|
||||
from .strategies import MixedStrategy
|
||||
from ceph_volume.devices.lvm.create import Create
|
||||
from ceph_volume.devices.lvm.prepare import Prepare
|
||||
from ceph_volume.util import templates
|
||||
from ceph_volume.exceptions import SizeAllocationError
|
||||
|
||||
|
||||
class SingleType(object):
|
||||
class SingleType(Strategy):
|
||||
"""
|
||||
Support for all SSDs, or all HDDS
|
||||
"""
|
||||
|
||||
def __init__(self, devices, args):
|
||||
self.args = args
|
||||
self.osds_per_device = args.osds_per_device
|
||||
self.devices = devices
|
||||
# TODO: add --fast-devices and --slow-devices so these can be customized
|
||||
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}
|
||||
if self.devices:
|
||||
self.validate()
|
||||
self.compute()
|
||||
else:
|
||||
self.computed["changed"] = False
|
||||
super(SingleType, self).__init__(devices, args)
|
||||
self.validate_compute()
|
||||
|
||||
@staticmethod
|
||||
def type():
|
||||
return "bluestore.SingleType"
|
||||
|
||||
@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
|
||||
|
||||
def report_json(self):
|
||||
print(json.dumps(self.computed, indent=4, sort_keys=True))
|
||||
|
||||
def report_pretty(self):
|
||||
string = ""
|
||||
if self.args.filtered_devices:
|
||||
@ -141,34 +123,20 @@ class SingleType(object):
|
||||
Create(command).main()
|
||||
|
||||
|
||||
class MixedType(object):
|
||||
class MixedType(MixedStrategy):
|
||||
|
||||
def __init__(self, devices, args):
|
||||
self.args = args
|
||||
self.devices = devices
|
||||
self.osds_per_device = args.osds_per_device
|
||||
# TODO: add --fast-devices and --slow-devices so these can be customized
|
||||
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': [], 'filtered_devices': args.filtered_devices}
|
||||
super(MixedType, self).__init__(devices, args)
|
||||
self.block_db_size = self.get_block_size()
|
||||
self.system_vgs = lvm.VolumeGroups()
|
||||
self.dbs_needed = len(self.hdds) * self.osds_per_device
|
||||
# use block.db lvs that are as large as possible
|
||||
self.use_large_block_db = False
|
||||
if self.devices:
|
||||
self.validate()
|
||||
self.compute()
|
||||
else:
|
||||
self.computed["changed"] = False
|
||||
self.validate_compute()
|
||||
|
||||
@staticmethod
|
||||
def type():
|
||||
return "bluestore.MixedType"
|
||||
|
||||
def report_json(self):
|
||||
print(json.dumps(self.computed, indent=4, sort_keys=True))
|
||||
|
||||
def get_block_size(self):
|
||||
if self.args.block_db_size:
|
||||
return disk.Size(b=self.args.block_db_size)
|
||||
@ -317,17 +285,6 @@ class MixedType(object):
|
||||
else:
|
||||
Create(command).main()
|
||||
|
||||
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
|
||||
|
||||
def validate(self):
|
||||
"""
|
||||
HDDs represent data devices, and solid state devices are for block.db,
|
||||
|
@ -1,8 +1,9 @@
|
||||
from __future__ import print_function
|
||||
import json
|
||||
from ceph_volume.util import disk, prepare
|
||||
from ceph_volume.api import lvm
|
||||
from . import validators
|
||||
from .strategies import Strategy
|
||||
from .strategies import MixedStrategy
|
||||
from ceph_volume.devices.lvm.create import Create
|
||||
from ceph_volume.devices.lvm.prepare import Prepare
|
||||
from ceph_volume.util import templates
|
||||
@ -20,40 +21,21 @@ def get_journal_size(args):
|
||||
return prepare.get_journal_size(lv_format=False)
|
||||
|
||||
|
||||
class SingleType(object):
|
||||
class SingleType(Strategy):
|
||||
"""
|
||||
Support for all SSDs, or all HDDs, data and journal LVs will be colocated
|
||||
in the same device
|
||||
"""
|
||||
|
||||
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}
|
||||
super(SingleType, self).__init__(devices, args)
|
||||
self.journal_size = get_journal_size(args)
|
||||
if self.devices:
|
||||
self.validate()
|
||||
self.compute()
|
||||
else:
|
||||
self.computed["changed"] = False
|
||||
self.validate_compute()
|
||||
|
||||
@staticmethod
|
||||
def type():
|
||||
return "filestore.SingleType"
|
||||
|
||||
@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
|
||||
|
||||
def report_json(self):
|
||||
print(json.dumps(self.computed, indent=4, sort_keys=True))
|
||||
|
||||
def report_pretty(self):
|
||||
string = ""
|
||||
if self.args.filtered_devices:
|
||||
@ -176,7 +158,7 @@ class SingleType(object):
|
||||
Create(command).main()
|
||||
|
||||
|
||||
class MixedType(object):
|
||||
class MixedType(MixedStrategy):
|
||||
"""
|
||||
Supports HDDs with SSDs, journals will be placed on SSDs, while HDDs will
|
||||
be used fully for data.
|
||||
@ -186,36 +168,17 @@ class MixedType(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': [], 'vg': None, 'filtered_devices': args.filtered_devices}
|
||||
super(MixedType, self).__init__(devices, args)
|
||||
self.blank_ssds = []
|
||||
self.journals_needed = len(self.hdds) * self.osds_per_device
|
||||
self.journal_size = get_journal_size(args)
|
||||
self.system_vgs = lvm.VolumeGroups()
|
||||
if self.devices:
|
||||
self.validate()
|
||||
self.compute()
|
||||
else:
|
||||
self.computed["changed"] = False
|
||||
self.validate_compute()
|
||||
|
||||
@staticmethod
|
||||
def type():
|
||||
return "filestore.MixedType"
|
||||
|
||||
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
|
||||
|
||||
def report_pretty(self):
|
||||
string = ""
|
||||
if self.args.filtered_devices:
|
||||
@ -252,17 +215,6 @@ class MixedType(object):
|
||||
|
||||
print(string)
|
||||
|
||||
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
|
||||
|
||||
def validate(self):
|
||||
"""
|
||||
Ensure that the minimum requirements for this type of scenario is
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user