| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from __future__ import (absolute_import, division, print_function) |
| 6 |
|
| 7 |
__metaclass__ = type |
| 8 |
|
| 9 |
from ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell \ |
| 10 |
import utils |
| 11 |
|
| 12 |
LOG = utils.get_logger('configuration') |
| 13 |
|
| 14 |
|
| 15 |
class Configuration: |
| 16 |
|
| 17 |
""" |
| 18 |
The configuration SDK class with shared configuration operations. |
| 19 |
""" |
| 20 |
|
| 21 |
def __init__(self, powerflex_conn, module): |
| 22 |
""" |
| 23 |
Initialize the configuration class |
| 24 |
:param configuration: The configuration SDK instance |
| 25 |
:param module: Ansible module object |
| 26 |
""" |
| 27 |
self.module = module |
| 28 |
self.powerflex_conn = powerflex_conn |
| 29 |
|
| 30 |
def get_protection_domain( |
| 31 |
self, protection_domain_name=None, protection_domain_id=None |
| 32 |
): |
| 33 |
""" |
| 34 |
Get protection domain details |
| 35 |
:param protection_domain_name: Name of the protection domain |
| 36 |
:param protection_domain_id: ID of the protection domain |
| 37 |
:return: Protection domain details if exists |
| 38 |
:rtype: dict |
| 39 |
""" |
| 40 |
|
| 41 |
name_or_id = ( |
| 42 |
protection_domain_id if protection_domain_id else protection_domain_name |
| 43 |
) |
| 44 |
|
| 45 |
try: |
| 46 |
if protection_domain_id: |
| 47 |
pd_details = self.powerflex_conn.protection_domain.get( |
| 48 |
filter_fields={"id": protection_domain_id} |
| 49 |
) |
| 50 |
|
| 51 |
else: |
| 52 |
pd_details = self.powerflex_conn.protection_domain.get( |
| 53 |
filter_fields={"name": protection_domain_name} |
| 54 |
) |
| 55 |
|
| 56 |
if len(pd_details) == 0: |
| 57 |
error_msg = ( |
| 58 |
"Unable to find the protection domain with " "'%s'." % name_or_id |
| 59 |
) |
| 60 |
LOG.error(error_msg) |
| 61 |
self.module.fail_json(msg=error_msg) |
| 62 |
|
| 63 |
return pd_details[0] |
| 64 |
|
| 65 |
except Exception as e: |
| 66 |
error_msg = ( |
| 67 |
"Failed to get the protection domain '%s' with " |
| 68 |
"error '%s'" % (name_or_id, str(e)) |
| 69 |
) |
| 70 |
LOG.error(error_msg) |
| 71 |
self.module.fail_json(msg=error_msg) |
| 72 |
|
| 73 |
def get_fault_set(self, fault_set_name=None, fault_set_id=None, protection_domain_id=None): |
| 74 |
"""Get fault set details |
| 75 |
:param fault_set_name: Name of the fault set |
| 76 |
:param fault_set_id: Id of the fault set |
| 77 |
:param protection_domain_id: ID of the protection domain |
| 78 |
:return: Fault set details |
| 79 |
:rtype: dict |
| 80 |
""" |
| 81 |
name_or_id = fault_set_id if fault_set_id \ |
| 82 |
else fault_set_name |
| 83 |
try: |
| 84 |
fs_details = {} |
| 85 |
if fault_set_id: |
| 86 |
fs_details = self.powerflex_conn.fault_set.get( |
| 87 |
filter_fields={'id': name_or_id}) |
| 88 |
|
| 89 |
if fault_set_name: |
| 90 |
fs_details = self.powerflex_conn.fault_set.get( |
| 91 |
filter_fields={'name': name_or_id, 'protectionDomainId': protection_domain_id}) |
| 92 |
|
| 93 |
if not fs_details: |
| 94 |
msg = f"Unable to find the fault set with {name_or_id}" |
| 95 |
LOG.info(msg) |
| 96 |
return None |
| 97 |
|
| 98 |
return fs_details[0] |
| 99 |
|
| 100 |
except Exception as e: |
| 101 |
error_msg = f"Failed to get the fault set '{name_or_id}' with error '{str(e)}'" |
| 102 |
LOG.error(error_msg) |
| 103 |
self.module.fail_json(msg=error_msg) |
| 104 |
|
| 105 |
def get_associated_sds(self, fault_set_id=None): |
| 106 |
"""Get associated SDS to a fault set |
| 107 |
:param fault_set_id: Id of the fault set |
| 108 |
:return: Associated SDS details |
| 109 |
:rtype: dict |
| 110 |
""" |
| 111 |
try: |
| 112 |
if fault_set_id: |
| 113 |
sds_details = self.powerflex_conn.fault_set.get_sdss( |
| 114 |
fault_set_id=fault_set_id) |
| 115 |
|
| 116 |
return sds_details |
| 117 |
|
| 118 |
except Exception as e: |
| 119 |
error_msg = f"Failed to get the associated SDS with error '{str(e)}'" |
| 120 |
LOG.error(error_msg) |
| 121 |
self.module.fail_json(msg=error_msg) |