From 45a085a72039f0f04ad896e1c571f7cab3813af2 Mon Sep 17 00:00:00 2001 From: "nikitha.t.j" Date: Wed, 2 Apr 2025 04:04:10 -0700 Subject: [PATCH] Fixed the issue with list protection sources --- .../models/key_value_str_pair.py | 60 +++++++++++++++++++ .../models/uda_connect_params.py | 4 +- samples/list_protection_sources/README.md | 25 ++++++++ samples/list_protection_sources/__init__.py | 0 .../list_protection_sources.py | 41 +++++++++++++ 5 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 cohesity_management_sdk/models/key_value_str_pair.py create mode 100644 samples/list_protection_sources/README.md create mode 100644 samples/list_protection_sources/__init__.py create mode 100644 samples/list_protection_sources/list_protection_sources.py diff --git a/cohesity_management_sdk/models/key_value_str_pair.py b/cohesity_management_sdk/models/key_value_str_pair.py new file mode 100644 index 000000000..f09a8b8e9 --- /dev/null +++ b/cohesity_management_sdk/models/key_value_str_pair.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 Cohesity Inc. + + +class KeyValueStrPair(object): + + """Implementation of the 'KeyValueStrPair' model. + + Generic structure to hold a string key value pair. + + + Attributes: + + key (string): Specifies the name of the key. + value (Value): Specifies a value for the key. + """ + + + # Create a mapping from Model property names to API property names + _names = { + "key":'key', + "value":'value', + } + def __init__(self, + key=None, + value=None, + ): + + """Constructor for the KeyValuePair class""" + + # Initialize members of the class + self.key = key + self.value = value + + @classmethod + def from_dictionary(cls, + dictionary): + """Creates an instance of this model from a dictionary + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + Returns: + object: An instance of this structure class. + + """ + if dictionary is None: + return None + + # Extract variables from the dictionary + key = dictionary.get('key') + value = dictionary.get('value') + + # Return an object of this model + return cls( + key, + value +) \ No newline at end of file diff --git a/cohesity_management_sdk/models/uda_connect_params.py b/cohesity_management_sdk/models/uda_connect_params.py index 34e13a518..a6ca9c69a 100644 --- a/cohesity_management_sdk/models/uda_connect_params.py +++ b/cohesity_management_sdk/models/uda_connect_params.py @@ -2,7 +2,7 @@ # Copyright 2023 Cohesity Inc. import cohesity_management_sdk.models.credentials -import cohesity_management_sdk.models.key_value_pair +import cohesity_management_sdk.models.key_value_str_pair import cohesity_management_sdk.models.uda_source_capabilities @@ -119,7 +119,7 @@ def from_dictionary(cls, if dictionary.get('sourceRegistrationArguments') != None: source_registration_arguments = list() for structure in dictionary.get('sourceRegistrationArguments'): - source_registration_arguments.append(cohesity_management_sdk.models.key_value_pair.KeyValuePair.from_dictionary(structure)) + source_registration_arguments.append(cohesity_management_sdk.models.key_value_str_pair.KeyValueStrPair.from_dictionary(structure)) source_type = dictionary.get('sourceType') # Return an object of this model diff --git a/samples/list_protection_sources/README.md b/samples/list_protection_sources/README.md new file mode 100644 index 000000000..40320894f --- /dev/null +++ b/samples/list_protection_sources/README.md @@ -0,0 +1,25 @@ +## Usage +``` +python list_protection_sources.py +``` + +## Connect to the Cohesity Cluster +First make sure that you are connected to a Cohesity Cluster. +``` +cohesity_client = CohesityClient(cluster_vip=CLUSTER_VIP, + username=CLUSTER_USERNAME, + password=CLUSTER_PASSWORD, + domain=DOMAIN) +``` +Note: Alternatively, you can set the above parameters in cohesity_management_sdk/configuration.py + +## Example +``` +protection_sources = cohesity_client.protection_sources +sources_list = protection_sources.list_protection_sources() + +``` +## Example Output +``` +list of Protection Sources +``` \ No newline at end of file diff --git a/samples/list_protection_sources/__init__.py b/samples/list_protection_sources/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/samples/list_protection_sources/list_protection_sources.py b/samples/list_protection_sources/list_protection_sources.py new file mode 100644 index 000000000..9be8f0dfe --- /dev/null +++ b/samples/list_protection_sources/list_protection_sources.py @@ -0,0 +1,41 @@ +# Copyright 2019 Cohesity Inc. +# +# Python example to get a list Protection jobs. +# +# Usage: python list_protection_jobs.py + +import datetime + +from cohesity_management_sdk.cohesity_client import CohesityClient + +CLUSTER_USERNAME = 'admin' +CLUSTER_PASSWORD = 'admin' +CLUSTER_VIP = '10.14.7.145' +DOMAIN = 'LOCAL' + +class ProtectionSourcesList(object): + + def list_protection_sources(self, cohesity_client): + """ + Method to display the list of ProtectionSources + :param cohesity_client(object): Cohesity client object. + :return: + """ + protection_sources = cohesity_client.protection_sources + srcs_list = protection_sources.list_protection_sources() + for srcs in srcs_list: + print(srcs) + + + +def main(): + + cohesity_client = CohesityClient(cluster_vip=CLUSTER_VIP, + username=CLUSTER_USERNAME, + password=CLUSTER_PASSWORD, + domain=DOMAIN) + protection_srcs = ProtectionSourcesList() + protection_srcs.list_protection_sources(cohesity_client) + +if __name__ == '__main__': + main() \ No newline at end of file