diff --git a/ocp_resources/storage_class.py b/ocp_resources/storage_class.py index a7d4a33f00..4caf579be2 100644 --- a/ocp_resources/storage_class.py +++ b/ocp_resources/storage_class.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- +from kubernetes.dynamic.exceptions import ResourceNotFoundError from ocp_resources.resource import Resource +from ocp_resources.storage_profile import StorageProfile class StorageClass(Resource): @@ -13,6 +15,9 @@ class StorageClass(Resource): class Types: """ These are names of StorageClass instances when you run `oc get sc` + + API: + https://kubernetes.io/docs/concepts/storage/storage-classes/ """ LOCAL_BLOCK = "local-block" @@ -101,3 +106,14 @@ def to_dict(self): self.res.update({"allowedTopologies": self.allowed_topologies}) if self.mount_options: self.res.update({"mountOptions": self.mount_options}) + + @property + def storage_profile(self): + try: + return StorageProfile( + client=self.client, + name=self.name, + ) + except ResourceNotFoundError: + self.logger.error(f" storageProfile is not found for {self.name} storageClass") + raise diff --git a/ocp_resources/storage_profile.py b/ocp_resources/storage_profile.py index 5a52a24326..0e34ec95c4 100644 --- a/ocp_resources/storage_profile.py +++ b/ocp_resources/storage_profile.py @@ -4,4 +4,33 @@ class StorageProfile(Resource): + """ + StorageProfile Object + + Doc: + https://github.com/kubevirt/containerized-data-importer/blob/main/doc/storageprofile.md + """ + api_group = Resource.ApiGroup.CDI_KUBEVIRT_IO + + @property + def claim_property_sets(self): + return self.instance.status.get("claimPropertySets") + + def first_claim_property_set_access_modes(self): + return self.claim_property_sets[0].get("volumeMode") if self.claim_property_sets else None + + def first_claim_property_set_volume_mode(self): + return self.claim_property_sets[0].get("volumeMode") if self.claim_property_sets else None + + @property + def clone_strategy(self): + return self.instance.status.get("cloneStrategy") + + @property + def data_import_cron_source_format(self): + return self.instance.status.get("dataImportCronSourceFormat") + + @property + def snapshotclass(self): + return self.instance.status.get("snapshotClass")