def add_capacity(osd_size_capacity_requested): """ Add storage capacity to the cluster Args: osd_size_capacity_requested(int): Requested osd size capacity Returns: new storage device set count (int) : Returns True if all OSDs are in Running state Note: "StoragedeviceSets->count" represents the set of 3 OSDs. That is, if there are 3 OSDs in the system then count will be 1. If there are 6 OSDs then count is 2 and so on. By changing this value,we can add extra devices to the cluster. For example, if we want to expand the cluster by 3 more osds in a cluster that already has 3 osds, we can set count as 2. So, with each increase of count by 1, we get 3 OSDs extra added to the cluster. This is how we are going to 'add capacity' via automation. As we know that OCS has 3 way replica. That is, same data is placed in 3 OSDs. Because of this, the total usable capacity for apps from 3 OSDs will be the size of one OSD (all osds are of same size). If we want to add more capacity to the cluster then we need to add 3 OSDs of same size as that of the original OSD. add_capacity needs to accept the 'capacity_to_add' as an argument. From this we need to arrive at storagedeviceSets -> count and then "Patch" this count to get the required capacity to add. To do so, we use following formula: storageDeviceSets->count = (capacity reqested / osd capacity ) + existing count storageDeviceSets """ osd_size_existing = get_osd_size() device_sets_required = int(osd_size_capacity_requested / osd_size_existing) old_storage_devices_sets_count = get_deviceset_count() new_storage_devices_sets_count = int(device_sets_required + old_storage_devices_sets_count) lvpresent = localstorage.check_local_volume() if lvpresent: final_device_list = localstorage.get_new_device_paths(device_sets_required, osd_size_capacity_requested) param = f"""[{{ "op": "replace", "path": "/spec/storageClassDevices/0/devicePaths", "value": {final_device_list}}}]""" log.info(f"Final device list : {final_device_list}") lvcr = localstorage.get_local_volume_cr() log.info("Patching Local Volume CR...") lvcr.patch( resource_name=lvcr.get()['items'][0]['metadata']['name'], params=param.strip('\n'), format_type='json' ) localstorage.check_pvs_created(int(len(final_device_list) / new_storage_devices_sets_count)) sc = get_storage_cluster() # adding the storage capacity to the cluster params = f"""[{{ "op": "replace", "path": "/spec/storageDeviceSets/0/count", "value": {new_storage_devices_sets_count}}}]""" sc.patch( resource_name=sc.get()['items'][0]['metadata']['name'], params=params.strip('\n'), format_type='json' ) return new_storage_devices_sets_count
def add_capacity(osd_size_capacity_requested, add_extra_disk_to_existing_worker=True): """ Add storage capacity to the cluster Args: osd_size_capacity_requested(int): Requested osd size capacity add_extra_disk_to_existing_worker(bool): Add Disk if True Returns: new storage device set count (int) : Returns True if all OSDs are in Running state Note: "StoragedeviceSets->count" represents the set of 3 OSDs. That is, if there are 3 OSDs in the system then count will be 1. If there are 6 OSDs then count is 2 and so on. By changing this value,we can add extra devices to the cluster. For example, if we want to expand the cluster by 3 more osds in a cluster that already has 3 osds, we can set count as 2. So, with each increase of count by 1, we get 3 OSDs extra added to the cluster. This is how we are going to 'add capacity' via automation. As we know that OCS has 3 way replica. That is, same data is placed in 3 OSDs. Because of this, the total usable capacity for apps from 3 OSDs will be the size of one OSD (all osds are of same size). If we want to add more capacity to the cluster then we need to add 3 OSDs of same size as that of the original OSD. add_capacity needs to accept the 'capacity_to_add' as an argument. From this we need to arrive at storagedeviceSets -> count and then "Patch" this count to get the required capacity to add. To do so, we use following formula: storageDeviceSets->count = (capacity reqested / osd capacity ) + existing count storageDeviceSets """ lvpresent = None lv_set_present = None osd_size_existing = get_osd_size() device_sets_required = int(osd_size_capacity_requested / osd_size_existing) old_storage_devices_sets_count = get_deviceset_count() new_storage_devices_sets_count = int(device_sets_required + old_storage_devices_sets_count) is_lso = config.DEPLOYMENT.get("local_storage") if is_lso: lv_lvs_data = localstorage.check_local_volume_local_volume_set() if lv_lvs_data.get("localvolume"): lvpresent = True elif lv_lvs_data.get("localvolumeset"): lv_set_present = True else: log.info(lv_lvs_data) raise ResourceNotFoundError( "No LocalVolume and LocalVolume Set found") platform = config.ENV_DATA.get("platform", "").lower() if lvpresent: ocp_obj = OCP(kind="localvolume", namespace=config.ENV_DATA["local_storage_namespace"]) localvolume_data = ocp_obj.get(resource_name="local-block") device_list = localvolume_data["spec"]["storageClassDevices"][0][ "devicePaths"] final_device_list = localstorage.get_new_device_paths( device_sets_required, osd_size_capacity_requested) device_list.sort() final_device_list.sort() if device_list == final_device_list: raise ResourceNotFoundError("No Extra device found") param = f"""[{{ "op": "replace", "path": "/spec/storageClassDevices/0/devicePaths", "value": {final_device_list}}}]""" log.info(f"Final device list : {final_device_list}") lvcr = localstorage.get_local_volume_cr() log.info("Patching Local Volume CR...") lvcr.patch( resource_name=lvcr.get()["items"][0]["metadata"]["name"], params=param.strip("\n"), format_type="json", ) localstorage.check_pvs_created( int(len(final_device_list) / new_storage_devices_sets_count)) if lv_set_present: if check_pvs_present_for_ocs_expansion(): log.info("Found Extra PV") else: if (platform == constants.VSPHERE_PLATFORM and add_extra_disk_to_existing_worker): log.info("No Extra PV found") log.info("Adding Extra Disk to existing VSphere Worker node") add_new_disk_for_vsphere(sc_name=constants.LOCALSTORAGE_SC) else: raise PVNotSufficientException( f"No Extra PV found in {constants.OPERATOR_NODE_LABEL}") sc = get_storage_cluster() # adding the storage capacity to the cluster params = f"""[{{ "op": "replace", "path": "/spec/storageDeviceSets/0/count", "value": {new_storage_devices_sets_count}}}]""" sc.patch( resource_name=sc.get()["items"][0]["metadata"]["name"], params=params.strip("\n"), format_type="json", ) return new_storage_devices_sets_count
def add_capacity(osd_size_capacity_requested): """ Add storage capacity to the cluster Args: osd_size_capacity_requested(int): Requested osd size capacity Returns: new storage device set count (int) : Returns True if all OSDs are in Running state Note: "StoragedeviceSets->count" represents the set of 3 OSDs. That is, if there are 3 OSDs in the system then count will be 1. If there are 6 OSDs then count is 2 and so on. By changing this value,we can add extra devices to the cluster. For example, if we want to expand the cluster by 3 more osds in a cluster that already has 3 osds, we can set count as 2. So, with each increase of count by 1, we get 3 OSDs extra added to the cluster. This is how we are going to 'add capacity' via automation. As we know that OCS has 3 way replica. That is, same data is placed in 3 OSDs. Because of this, the total usable capacity for apps from 3 OSDs will be the size of one OSD (all osds are of same size). If we want to add more capacity to the cluster then we need to add 3 OSDs of same size as that of the original OSD. add_capacity needs to accept the 'capacity_to_add' as an argument. From this we need to arrive at storagedeviceSets -> count and then "Patch" this count to get the required capacity to add. To do so, we use following formula: storageDeviceSets->count = (capacity reqested / osd capacity ) + existing count storageDeviceSets """ osd_size_existing = get_osd_size() device_sets_required = int(osd_size_capacity_requested / osd_size_existing) old_storage_devices_sets_count = get_deviceset_count() new_storage_devices_sets_count = int(device_sets_required + old_storage_devices_sets_count) lvpresent = localstorage.check_local_volume() ocp_version = get_ocp_version() platform = config.ENV_DATA.get("platform", "").lower() is_lso = config.DEPLOYMENT.get("local_storage") if (ocp_version == "4.7" and (platform == constants.AWS_PLATFORM or platform == constants.VSPHERE_PLATFORM) and (not is_lso)): logging.info("Add capacity via UI") setup_ui = login_ui() add_ui_obj = AddReplaceDeviceUI(setup_ui) add_ui_obj.add_capacity_ui() close_browser(setup_ui) else: if lvpresent: ocp_obj = OCP(kind="localvolume", namespace=config.ENV_DATA["local_storage_namespace"]) localvolume_data = ocp_obj.get(resource_name="local-block") device_list = localvolume_data["spec"]["storageClassDevices"][0][ "devicePaths"] final_device_list = localstorage.get_new_device_paths( device_sets_required, osd_size_capacity_requested) device_list.sort() final_device_list.sort() if device_list == final_device_list: raise ResourceNotFoundError("No Extra device found") param = f"""[{{ "op": "replace", "path": "/spec/storageClassDevices/0/devicePaths", "value": {final_device_list}}}]""" log.info(f"Final device list : {final_device_list}") lvcr = localstorage.get_local_volume_cr() log.info("Patching Local Volume CR...") lvcr.patch( resource_name=lvcr.get()["items"][0]["metadata"]["name"], params=param.strip("\n"), format_type="json", ) localstorage.check_pvs_created( int(len(final_device_list) / new_storage_devices_sets_count)) sc = get_storage_cluster() # adding the storage capacity to the cluster params = f"""[{{ "op": "replace", "path": "/spec/storageDeviceSets/0/count", "value": {new_storage_devices_sets_count}}}]""" sc.patch( resource_name=sc.get()["items"][0]["metadata"]["name"], params=params.strip("\n"), format_type="json", ) return new_storage_devices_sets_count