| 1 |
#!/usr/bin/python |
| 2 |
|
| 3 |
# (c) 2025, NetApp, Inc |
| 4 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 |
|
| 6 |
""" NetApp StorageGRID pge info using REST APIs """ |
| 7 |
|
| 8 |
|
| 9 |
from __future__ import absolute_import, division, print_function |
| 10 |
|
| 11 |
__metaclass__ = type |
| 12 |
|
| 13 |
ANSIBLE_METADATA = {'metadata_version': '1.1', |
| 14 |
'status': ['preview'], |
| 15 |
'supported_by': 'community'} |
| 16 |
|
| 17 |
DOCUMENTATION = """ |
| 18 |
module: na_sg_pge_info |
| 19 |
short_description: NetApp StorageGRID node PGE information gatherer. |
| 20 |
extends_documentation_fragment: |
| 21 |
- netapp.storagegrid.netapp.sg_pge |
| 22 |
version_added: '21.16.0' |
| 23 |
author: NetApp Ansible Team (@vinaykus) <[email protected]> |
| 24 |
description: |
| 25 |
- Gather various information about StorageGRID node Pre-Grid Environment (PGE) configuration. |
| 26 |
options: |
| 27 |
gather_subset: |
| 28 |
type: list |
| 29 |
elements: str |
| 30 |
description: |
| 31 |
- When supplied, this argument will restrict the information collected to a given subset. |
| 32 |
- Either the info name or the REST API can be given. |
| 33 |
- Possible values for this argument include |
| 34 |
- C(pge_storage_configuration_networking) or C(pge/storage-configuration/networking) |
| 35 |
- C(pge_bmc_config) or C(pge/bmc-config) |
| 36 |
- C(pge_install_status) or C(pge/install-status) |
| 37 |
- C(pge_networks) or C(pge/networks) |
| 38 |
- C(pge_link_config) or C(pge/link-config) |
| 39 |
- C(pge_dns) or C(pge/dns) |
| 40 |
- C(pge_system_info) or C(pge/system-info) |
| 41 |
- C(pge_system_config) or C(pge/system-config) |
| 42 |
- C(pge_admin_connection) or C(pge/admin-connection) |
| 43 |
- C(pge_ipmi_sensors) or C(pge/ipmi-sensors) |
| 44 |
- C(pge_upgrade_status) or C(pge/upgrade/status) |
| 45 |
- C(pge_debug_dump_addr_show) or C(pge/debug/dump-addr-show) |
| 46 |
- C(pge_debug_dump_routes) or C(pge/debug/dump-routes) |
| 47 |
- C(pge_debug_dump_bonding) or C(pge/debug/dump-bonding) |
| 48 |
- C(pge_debug_dump_netlink) or C(pge/debug/dump-netlink) |
| 49 |
- C(pge_debug_dump_bonding_raw) or C(pge/debug/dump-bonding-raw) |
| 50 |
- C(pge_debug_dump_lldp_attributes) or C(pge/debug/dump-lldp-attributes) |
| 51 |
- Can specify a list of values to include a larger subset. |
| 52 |
default: all |
| 53 |
parameters: |
| 54 |
description: |
| 55 |
- Allows for any rest option to be passed in. |
| 56 |
type: dict |
| 57 |
""" |
| 58 |
|
| 59 |
EXAMPLES = """ |
| 60 |
- name: Gather StorageGRID node PGE info |
| 61 |
netapp.storagegrid.na_sg_pge_info: |
| 62 |
api_url: "https://1.2.3.4/" |
| 63 |
validate_certs: false |
| 64 |
register: sg_pge_info |
| 65 |
|
| 66 |
- name: Gather StorageGRID PGE info for pge/bmc-config and pge_dns subsets |
| 67 |
netapp.storagegrid.na_sg_pge_info: |
| 68 |
api_url: "https://1.2.3.4/" |
| 69 |
validate_certs: false |
| 70 |
gather_subset: |
| 71 |
- pge/bmc-config |
| 72 |
- pge_dns |
| 73 |
register: sg_pge_info |
| 74 |
|
| 75 |
- name: Gather StorageGRID PGE info for all subsets |
| 76 |
netapp.storagegrid.na_sg_pge_info: |
| 77 |
api_url: "https://1.2.3.4/" |
| 78 |
validate_certs: false |
| 79 |
gather_subset: |
| 80 |
- all |
| 81 |
register: sg_pge_info |
| 82 |
|
| 83 |
- name: Gather StorageGRID PGE info for pge/system-config and pge/system-info subsets, limit to 5 results for each subset |
| 84 |
netapp.storagegrid.na_sg_pge_info: |
| 85 |
api_url: "https://1.2.3.4/" |
| 86 |
validate_certs: false |
| 87 |
gather_subset: |
| 88 |
- pge/system-config |
| 89 |
- pge/system-info |
| 90 |
parameters: |
| 91 |
limit: 5 |
| 92 |
register: sg_pge_info |
| 93 |
""" |
| 94 |
|
| 95 |
RETURN = """ |
| 96 |
sg_pge_info: |
| 97 |
description: Returns various information about the StorageGRID node PGE configuration. |
| 98 |
returned: always |
| 99 |
type: dict |
| 100 |
sample: { |
| 101 |
"pge/storage-configuration/networking": {...}, |
| 102 |
"pge/bmc-config": {...}, |
| 103 |
"pge/install-status": {...}, |
| 104 |
"pge/networks": {...}, |
| 105 |
"pge/link-config": {...}, |
| 106 |
"pge/dns": {...}, |
| 107 |
"pge/system-info": {...}, |
| 108 |
"pge/system-config": {...}, |
| 109 |
"pge/admin-connection": {...}, |
| 110 |
"pge/ipmi-sensors": {...}, |
| 111 |
"pge/upgrade/status": {...}, |
| 112 |
"pge/debug/dump-addr-show": {...}, |
| 113 |
"pge/debug/dump-routes": {...}, |
| 114 |
"pge/debug/dump-bonding": {...}, |
| 115 |
"pge/debug/dump-netlink": {...}, |
| 116 |
"pge/debug/dump-bonding-raw": {...}, |
| 117 |
"pge/debug/dump-lldp-attributes": {...} |
| 118 |
} |
| 119 |
""" |
| 120 |
|
| 121 |
from ansible.module_utils.basic import AnsibleModule |
| 122 |
import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils |
| 123 |
from ansible_collections.netapp.storagegrid.plugins.module_utils.netapp_module import NetAppModule |
| 124 |
from ansible_collections.netapp.storagegrid.plugins.module_utils.netapp import PgeRestAPI |
| 125 |
|
| 126 |
|
| 127 |
class NetAppSgGatherPgeInfo(object): |
| 128 |
""" Class with gather pge info methods """ |
| 129 |
|
| 130 |
def __init__(self): |
| 131 |
""" |
| 132 |
Parse arguments, setup variables, check parameters and ensure |
| 133 |
request module is installed. |
| 134 |
""" |
| 135 |
self.argument_spec = netapp_utils.na_storagegrid_pge_argument_spec() |
| 136 |
self.argument_spec.update(dict( |
| 137 |
gather_subset=dict(default=['all'], type='list', elements='str', required=False), |
| 138 |
parameters=dict(type='dict', required=False) |
| 139 |
)) |
| 140 |
|
| 141 |
self.module = AnsibleModule( |
| 142 |
argument_spec=self.argument_spec, |
| 143 |
supports_check_mode=True |
| 144 |
) |
| 145 |
|
| 146 |
# set up variables |
| 147 |
self.na_helper = NetAppModule() |
| 148 |
self.parameters = self.na_helper.set_parameters(self.module.params) |
| 149 |
self.rest_api = PgeRestAPI(self.module) |
| 150 |
|
| 151 |
def get_subset_info(self, gather_subset_info): |
| 152 |
""" |
| 153 |
Gather StorageGRID node pge information for the given subset using REST APIs |
| 154 |
Input for REST APIs call : (api, data) |
| 155 |
return gathered_sg_info |
| 156 |
""" |
| 157 |
|
| 158 |
api = gather_subset_info['api_call'] |
| 159 |
data = {} |
| 160 |
# allow for passing in any additional rest api parameters |
| 161 |
if self.parameters.get('parameters'): |
| 162 |
for each in self.parameters['parameters']: |
| 163 |
data[each] = self.parameters['parameters'][each] |
| 164 |
|
| 165 |
gathered_sg_info, error = self.rest_api.get(api, data) |
| 166 |
|
| 167 |
if error: |
| 168 |
self.module.fail_json(msg=error) |
| 169 |
else: |
| 170 |
return gathered_sg_info |
| 171 |
|
| 172 |
return None |
| 173 |
|
| 174 |
def convert_subsets(self): |
| 175 |
""" Convert an info to the REST API """ |
| 176 |
info_to_rest_mapping = { |
| 177 |
'pge_storage_configuration_networking': 'pge/storage-configuration/networking', |
| 178 |
'pge_bmc_config': 'pge/bmc-config', |
| 179 |
'pge_install_status': 'pge/install-status', |
| 180 |
'pge_networks': 'pge/networks', |
| 181 |
'pge_link_config': 'pge/link-config', |
| 182 |
'pge_dns': 'pge/dns', |
| 183 |
'pge_system_info': 'pge/system-info', |
| 184 |
'pge_system_config': 'pge/system-config', |
| 185 |
'pge_admin_connection': 'pge/admin-connection', |
| 186 |
'pge_ipmi_sensors': 'pge/ipmi-sensors', |
| 187 |
'pge_upgrade_status': 'pge/upgrade/status', |
| 188 |
'pge_debug_dump_addr_show': 'pge/debug/dump-addr-show', |
| 189 |
'pge_debug_dump_routes': 'pge/debug/dump-routes', |
| 190 |
'pge_debug_dump_bonding': 'pge/debug/dump-bonding', |
| 191 |
'pge_debug_dump_netlink': 'pge/debug/dump-netlink', |
| 192 |
'pge_debug_dump_bonding_raw': 'pge/debug/dump-bonding-raw', |
| 193 |
'pge_debug_dump_lldp_attributes': 'pge/debug/dump-lldp-attributes', |
| 194 |
} |
| 195 |
# Add rest API names as there info version, also make sure we don't add a duplicate. |
| 196 |
subsets = [] |
| 197 |
for subset in self.parameters['gather_subset']: |
| 198 |
if subset in info_to_rest_mapping: |
| 199 |
if info_to_rest_mapping[subset] not in subsets: |
| 200 |
subsets.append(info_to_rest_mapping[subset]) |
| 201 |
else: |
| 202 |
if subset not in subsets: |
| 203 |
subsets.append(subset) |
| 204 |
return subsets |
| 205 |
|
| 206 |
def apply(self): |
| 207 |
""" Perform pre-checks, call functions and exit """ |
| 208 |
|
| 209 |
result_message = dict() |
| 210 |
|
| 211 |
# Defining gather_subset and appropriate api_call. |
| 212 |
get_sg_subset_info = { |
| 213 |
'pge/storage-configuration/networking': { |
| 214 |
'api_call': 'api/v2/storage-configuration/networking', |
| 215 |
}, |
| 216 |
'pge/bmc-config': { |
| 217 |
'api_call': 'api/v2/bmc-config', |
| 218 |
}, |
| 219 |
'pge/install-status': { |
| 220 |
'api_call': 'api/v2/install-status', |
| 221 |
}, |
| 222 |
'pge/networks': { |
| 223 |
'api_call': 'api/v2/networks', |
| 224 |
}, |
| 225 |
'pge/link-config': { |
| 226 |
'api_call': 'api/v2/link-config', |
| 227 |
}, |
| 228 |
'pge/dns': { |
| 229 |
'api_call': 'api/v2/dns', |
| 230 |
}, |
| 231 |
'pge/system-info': { |
| 232 |
'api_call': 'api/v2/system-info', |
| 233 |
}, |
| 234 |
'pge/system-config': { |
| 235 |
'api_call': 'api/v2/system-config', |
| 236 |
}, |
| 237 |
'pge/admin-connection': { |
| 238 |
'api_call': 'api/v2/admin-connection', |
| 239 |
}, |
| 240 |
'pge/ipmi-sensors': { |
| 241 |
'api_call': 'api/v2/ipmi-sensors', |
| 242 |
}, |
| 243 |
'pge/upgrade/status': { |
| 244 |
'api_call': 'api/v2/upgrade/status', |
| 245 |
}, |
| 246 |
'pge/debug/dump-addr-show': { |
| 247 |
'api_call': 'api/v2/debug/dump-addr-show', |
| 248 |
}, |
| 249 |
'pge/debug/dump-routes': { |
| 250 |
'api_call': 'api/v2/debug/dump-routes', |
| 251 |
}, |
| 252 |
'pge/debug/dump-bonding': { |
| 253 |
'api_call': 'api/v2/debug/dump-bonding', |
| 254 |
}, |
| 255 |
'pge/debug/dump-netlink': { |
| 256 |
'api_call': 'api/v2/debug/dump-netlink', |
| 257 |
}, |
| 258 |
'pge/debug/dump-bonding-raw': { |
| 259 |
'api_call': 'api/v2/debug/dump-bonding-raw', |
| 260 |
}, |
| 261 |
'pge/debug/dump-lldp-attributes': { |
| 262 |
'api_call': 'api/v2/debug/dump-lldp-attributes', |
| 263 |
}, |
| 264 |
} |
| 265 |
|
| 266 |
if 'all' in self.parameters['gather_subset']: |
| 267 |
# If all in subset list, get the information of all subsets. |
| 268 |
self.parameters['gather_subset'] = sorted(get_sg_subset_info.keys()) |
| 269 |
|
| 270 |
converted_subsets = self.convert_subsets() |
| 271 |
for subset in converted_subsets: |
| 272 |
try: |
| 273 |
# Verify whether the supported subset passed. |
| 274 |
specified_subset = get_sg_subset_info[subset] |
| 275 |
except KeyError: |
| 276 |
self.module.fail_json(msg="Specified subset %s not found, supported subsets are %s" % |
| 277 |
(subset, list(get_sg_subset_info.keys()))) |
| 278 |
|
| 279 |
result_message[subset] = self.get_subset_info(specified_subset) |
| 280 |
|
| 281 |
self.module.exit_json(changed=False, sg_info=result_message) |
| 282 |
|
| 283 |
|
| 284 |
def main(): |
| 285 |
""" Main function """ |
| 286 |
obj = NetAppSgGatherPgeInfo() |
| 287 |
obj.apply() |
| 288 |
|
| 289 |
|
| 290 |
if __name__ == '__main__': |
| 291 |
main() |