-
Notifications
You must be signed in to change notification settings - Fork 191
class and template for client profile #11759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dahorak
merged 3 commits into
red-hat-storage:master-converged-mode
from
DanielOsypenko:client-profile-class
Apr 7, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import logging | ||
| import tempfile | ||
|
|
||
| from ocs_ci.ocs import constants, ocp | ||
| from ocs_ci.framework import config | ||
| from ocs_ci.utility import templating | ||
| from ocs_ci.utility.templating import dump_data_to_temp_yaml | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class ClientProfile: | ||
| """ | ||
| Base ClientProfile class | ||
| """ | ||
|
|
||
| def __init__(self, client_profile_name, consumer_context): | ||
|
|
||
| self.consumer_context = consumer_context | ||
| self.name = client_profile_name | ||
| self.ocp = ocp.OCP( | ||
| resource_name=self.name, | ||
| kind=constants.CLIENT_PROFILE, | ||
| namespace=config.cluster_ctx.ENV_DATA["cluster_namespace"], | ||
| ) | ||
| if self.consumer_context: | ||
| self.provider_context = config.cluster_ctx.MULTICLUSTER[ | ||
| "multicluster_index" | ||
| ] | ||
| else: | ||
| self.provider_context = None | ||
|
|
||
| def get_ceph_connection_reference(self): | ||
| """ | ||
| Get the CephConnectionReference name | ||
| Returns: | ||
| str: CephConnectionReference name | ||
| """ | ||
| with config.RunWithConfigContext(self.consumer_context): | ||
| return ( | ||
| self.ocp.get(resource_name=self.name) | ||
| .get("spec") | ||
| .get("cephConnectionRef") | ||
| .get("name") | ||
| ) | ||
|
|
||
| def get_ceph_fs_map(self): | ||
| """ | ||
| Get the CephFSMap from the client profile | ||
| SubVolumeGroup string json:"subVolumeGroup,omitempty" | ||
| KernelMountOptions map[string] string `json:"kernelMountOptions,omitempty"` | ||
| FuseMountOptions map[string] string `json:"fuseMountOptions,omitempty"` | ||
| Starting from ODF 4.19 (Converged) this CR has optional Spec field RadosNamespace. | ||
| It is to ensure ceph fs has namespace for storing metadata (OMAP data) | ||
| RadosNamespace string(can be nil) json:"radosNamespace,omitempty" | ||
| Returns: | ||
| dict: CephFSMap | ||
| """ | ||
| with config.RunWithConfigContext(self.consumer_context): | ||
| return self.ocp.get(resource_name=self.name).get("spec").get("cephFs") | ||
|
|
||
| def get_rbd_map(self): | ||
| """ | ||
| Get the RBDMap from the client profile | ||
| Returns: | ||
| dict: RBDMap | ||
| """ | ||
| with config.RunWithConfigContext(self.consumer_context): | ||
| return self.ocp.get(resource_name=self.name).get("spec").get("rbd") | ||
|
|
||
| def get_nfs_map(self): | ||
| """ | ||
| Get the NFSMap from the client profile | ||
| Returns: | ||
| dict: NFSMap | ||
| """ | ||
| with config.RunWithConfigContext(self.consumer_context): | ||
| return self.ocp.get(resource_name=self.name).get("spec").get("nfs") | ||
|
|
||
| def create_client_profile( | ||
| self, | ||
| name, | ||
| ceph_connection_reference, | ||
| ceph_fs_map: dict, | ||
| rbd_map: dict, | ||
| nfs_map: dict, | ||
| ): | ||
| """ | ||
| Create a client profile | ||
| Returns: | ||
| dict: ClientProfile | ||
| """ | ||
| with config.RunWithConfigContext(self.consumer_context): | ||
| client_profile_data = templating.load_yaml(constants.CLIENT_PROFILE_PATH) | ||
| client_profile_data["metadata"]["name"] = name | ||
| client_profile_data["spec"]["cephConnectionRef"][ | ||
| "name" | ||
| ] = ceph_connection_reference | ||
| if ceph_fs_map: | ||
| client_profile_data["spec"]["cephFs"] = ceph_fs_map | ||
| if rbd_map: | ||
| client_profile_data["spec"]["rbd"] = rbd_map | ||
| if nfs_map: | ||
| client_profile_data["spec"]["nfs"] = nfs_map | ||
|
|
||
| client_profile_file = tempfile.NamedTemporaryFile( | ||
| mode="w+", prefix="client_profile", delete=False | ||
| ) | ||
| dump_data_to_temp_yaml(client_profile_data, client_profile_file.name) | ||
|
|
||
| return self.ocp.create(yaml_file=client_profile_file.name) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
ocs_ci/templates/ocs-deployment/provider-mode/client_profile.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| apiVersion: csi.ceph.io/v1alpha1 | ||
| kind: ClientProfile | ||
| metadata: | ||
| name: sample-clientprofile | ||
| spec: | ||
| cephConnectionRef: | ||
| name: ocs-storagecluster # by default storageCluster name | ||
| cephFs: | ||
| # fuseMountOptions provides a user-space file system interface and is often used for mounting file systems like CephFS | ||
| fuseMountOptions: {} | ||
| kernelMountOptions: {} | ||
| # radosNamespace is to ensure ceph fs has namespace for storing metadata (OMAP data) | ||
| radosNamespace: {} | ||
| subVolumeGroup: {} | ||
| nfs: {} | ||
| rbd: | ||
| radosNamespace: rados-namespace |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.