Skip to content

Commit

Permalink
Merge pull request #39 from sdodsley/drives
Browse files Browse the repository at this point in the history
Add drives module
  • Loading branch information
sdodsley authored Dec 19, 2024
2 parents ea750d6 + c1c32b8 commit 079fe22
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Release notes for this collection can be found [here](https://github.com/Pure-St

- pure1_alerts - Get alerts from Pure1
- pure1_array_tags - Manage array tags for managed devices in Pure1
- pure1_drives - Get array drives information from Pure1
- pure1_info - Get information on fleet configuration
- pure1_nics - Get network interface information from Pure1
- pure1_pods - Get FlashArray pod information from Pure1
Expand Down
112 changes: 112 additions & 0 deletions plugins/modules/pure1_drives.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# (c) 2024, Simon Dodsley ([email protected])
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {
"metadata_version": "1.1",
"status": ["preview"],
"supported_by": "community",
}

DOCUMENTATION = r"""
---
module: pure1_drives
version_added: '1.5.0'
short_description: Collect array drives information from Pure1
description:
- Collect array drives information from a Pure1
options:
array:
description:
- Filter to provide only drives for a specifically named array or blade
type: str
author:
- Pure Storage Ansible Team (@sdodsley) <[email protected]>
extends_documentation_fragment:
- purestorage.pure1.purestorage.p1
"""

EXAMPLES = r"""
- name: collect all drives information
purestorage.pure1.pure1_drives:
register: pure1_drives
- name: collect only drives information for array X
purestorage.pure1.pure1_drives:
array: X
register: pure1_drives
- name: show drives information
debug:
msg: "{{ pure1_info['pure1_drives']['drives'] }}"
"""

RETURN = r"""
pure1_drives:
description: Returns array drives information collected from Pure1
returned: always
type: dict
"""


from ansible.module_utils.basic import AnsibleModule
from ansible_collections.purestorage.pure1.plugins.module_utils.pure1 import (
get_pure1,
pure1_argument_spec,
)


def generate_drives_dict(module, pure_1):
drives_info = {}
if module.params["array"]:
res = pure_1.get_drives(filter="arrays.name='" + module.params["array"] + "'")
if res.status_code == 200 and res.total_item_count != 0:
drives = list(res.items)
else:
module.warn(
"No drives information available for array {0}".format(
module.params["array"]
)
)
module.exit_json(changed=False)
else:
drives = list(pure_1.get_drives().items)
for drive in range(0, len(drives)):
array = drives[drive].arrays[0].name
drives_info[array] = []
for drive in range(0, len(drives)):
array = drives[drive].arrays[0].name
drive_name = drives[drive].name
drive_details = {
drive_name: {
"capacity": getattr(drives[drive], "capacity", None),
"protocol": getattr(drives[drive], "protocol", None),
"status": getattr(drives[drive], "status", None),
"type": getattr(drives[drive], "type", None),
}
}
drives_info[array].append(drive_details)
return drives_info


def main():
argument_spec = pure1_argument_spec()
argument_spec.update(dict(array=dict(type="str")))
module = AnsibleModule(argument_spec, supports_check_mode=True)
pure_1 = get_pure1(module)

drives = {}

drives["drives"] = generate_drives_dict(module, pure_1)

module.exit_json(changed=False, pure1_drives=drives)


if __name__ == "__main__":
main()

0 comments on commit 079fe22

Please sign in to comment.