| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
|
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
ANSIBLE_METADATA = { |
| 12 |
"metadata_version": "1.1", |
| 13 |
"status": ["preview"], |
| 14 |
"supported_by": "community", |
| 15 |
} |
| 16 |
|
| 17 |
DOCUMENTATION = r""" |
| 18 |
--- |
| 19 |
module: purefb_inventory |
| 20 |
version_added: '1.0.0' |
| 21 |
short_description: Collect information from Pure Storage FlashBlade |
| 22 |
description: |
| 23 |
- Collect information from a Pure Storage FlashBlade running the |
| 24 |
Purity//FB operating system. By default, the module will collect basic |
| 25 |
information including hosts, host groups, protection |
| 26 |
groups and volume counts. Additional information can be collected |
| 27 |
based on the configured set of arguements. |
| 28 |
author: |
| 29 |
- Pure Storage ansible Team (@sdodsley) <[email protected]> |
| 30 |
extends_documentation_fragment: |
| 31 |
- purestorage.flashblade.purestorage.fb |
| 32 |
""" |
| 33 |
|
| 34 |
EXAMPLES = r""" |
| 35 |
- name: collect FlashBlade inventory |
| 36 |
purestorage.flashblade.purefb_inventory: |
| 37 |
fb_url: 10.10.10.2 |
| 38 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 39 |
register: blade_info |
| 40 |
- name: show default information |
| 41 |
debug: |
| 42 |
msg: "{{ blade_info['purefb_info'] }}" |
| 43 |
""" |
| 44 |
|
| 45 |
RETURN = r""" |
| 46 |
purefb_inventory: |
| 47 |
description: Returns the inventory information for the FlashBlade |
| 48 |
returned: always |
| 49 |
type: dict |
| 50 |
""" |
| 51 |
|
| 52 |
|
| 53 |
from ansible.module_utils.basic import AnsibleModule |
| 54 |
from ansible_collections.purestorage.flashblade.plugins.module_utils.purefb import ( |
| 55 |
get_system, |
| 56 |
purefb_argument_spec, |
| 57 |
) |
| 58 |
|
| 59 |
|
| 60 |
PART_NUMBER_API_VERSION = "2.8" |
| 61 |
|
| 62 |
|
| 63 |
def generate_hardware_dict(blade): |
| 64 |
api_version = list(blade.get_versions().items) |
| 65 |
hw_info = { |
| 66 |
"modules": {}, |
| 67 |
"ethernet": {}, |
| 68 |
"mgmt_ports": {}, |
| 69 |
"fans": {}, |
| 70 |
"bays": {}, |
| 71 |
"controllers": {}, |
| 72 |
"blades": {}, |
| 73 |
"chassis": {}, |
| 74 |
"power": {}, |
| 75 |
"switch": {}, |
| 76 |
} |
| 77 |
components = list(blade.get_hardware(filter="type='fm'").items) |
| 78 |
for component in range(len(components)): |
| 79 |
component_name = components[component].name |
| 80 |
hw_info["modules"][component_name] = { |
| 81 |
"slot": components[component].slot, |
| 82 |
"status": components[component].status, |
| 83 |
"serial": components[component].serial, |
| 84 |
"model": components[component].model, |
| 85 |
"identify": components[component].identify_enabled, |
| 86 |
} |
| 87 |
if PART_NUMBER_API_VERSION in api_version: |
| 88 |
hw_info["modules"][component_name]["part_number"] = components[ |
| 89 |
component |
| 90 |
].part_number |
| 91 |
components = list(blade.get_hardware(filter="type='eth'").items) |
| 92 |
for component in range(len(components)): |
| 93 |
component_name = components[component].name |
| 94 |
hw_info["ethernet"][component_name] = { |
| 95 |
"slot": components[component].slot, |
| 96 |
"status": components[component].status, |
| 97 |
"serial": components[component].serial, |
| 98 |
"model": components[component].model, |
| 99 |
"speed": components[component].speed, |
| 100 |
} |
| 101 |
if PART_NUMBER_API_VERSION in api_version: |
| 102 |
hw_info["ethernet"][component_name]["part_number"] = components[ |
| 103 |
component |
| 104 |
].part_number |
| 105 |
components = list(blade.get_hardware(filter="type='mgmt_port'").items) |
| 106 |
for component in range(len(components)): |
| 107 |
component_name = components[component].name |
| 108 |
hw_info["mgmt_ports"][component_name] = { |
| 109 |
"slot": components[component].slot, |
| 110 |
"status": components[component].status, |
| 111 |
"serial": components[component].serial, |
| 112 |
"model": components[component].model, |
| 113 |
"speed": components[component].speed, |
| 114 |
} |
| 115 |
if PART_NUMBER_API_VERSION in api_version: |
| 116 |
hw_info["mgmt_ports"][component_name]["part_number"] = components[ |
| 117 |
component |
| 118 |
].part_number |
| 119 |
components = list(blade.get_hardware(filter="type='fan'").items) |
| 120 |
for component in range(len(components)): |
| 121 |
component_name = components[component].name |
| 122 |
hw_info["fans"][component_name] = { |
| 123 |
"slot": components[component].slot, |
| 124 |
"status": components[component].status, |
| 125 |
"identify": components[component].identify_enabled, |
| 126 |
} |
| 127 |
if PART_NUMBER_API_VERSION in api_version: |
| 128 |
hw_info["fans"][component_name]["part_number"] = components[ |
| 129 |
component |
| 130 |
].part_number |
| 131 |
components = list(blade.get_hardware(filter="type='fb'").items) |
| 132 |
for component in range(len(components)): |
| 133 |
component_name = components[component].name |
| 134 |
hw_info["blades"][component_name] = { |
| 135 |
"slot": components[component].slot, |
| 136 |
"status": components[component].status, |
| 137 |
"serial": components[component].serial, |
| 138 |
"model": components[component].model, |
| 139 |
"temperature": components[component].temperature, |
| 140 |
"identify": components[component].identify_enabled, |
| 141 |
} |
| 142 |
if PART_NUMBER_API_VERSION in api_version: |
| 143 |
hw_info["blades"][component_name]["part_number"] = components[ |
| 144 |
component |
| 145 |
].part_number |
| 146 |
components = list(blade.get_hardware(filter="type='pwr'").items) |
| 147 |
for component in range(len(components)): |
| 148 |
component_name = components[component].name |
| 149 |
hw_info["power"][component_name] = { |
| 150 |
"slot": components[component].slot, |
| 151 |
"status": components[component].status, |
| 152 |
"serial": components[component].serial, |
| 153 |
"model": components[component].model, |
| 154 |
} |
| 155 |
if PART_NUMBER_API_VERSION in api_version: |
| 156 |
hw_info["power"][component_name]["part_number"] = components[ |
| 157 |
component |
| 158 |
].part_number |
| 159 |
components = list(blade.get_hardware(filter="type='xfm'").items) |
| 160 |
for component in range(len(components)): |
| 161 |
component_name = components[component].name |
| 162 |
hw_info["switch"][component_name] = { |
| 163 |
"slot": components[component].slot, |
| 164 |
"status": components[component].status, |
| 165 |
"serial": components[component].serial, |
| 166 |
"model": components[component].model, |
| 167 |
} |
| 168 |
if PART_NUMBER_API_VERSION in api_version: |
| 169 |
hw_info["switch"][component_name]["part_number"] = components[ |
| 170 |
component |
| 171 |
].part_number |
| 172 |
components = list(blade.get_hardware(filter="type='ch'").items) |
| 173 |
for component in range(len(components)): |
| 174 |
component_name = components[component].name |
| 175 |
hw_info["chassis"][component_name] = { |
| 176 |
"slot": components[component].slot, |
| 177 |
"index": components[component].index, |
| 178 |
"status": components[component].status, |
| 179 |
"serial": components[component].serial, |
| 180 |
"model": components[component].model, |
| 181 |
} |
| 182 |
if PART_NUMBER_API_VERSION in api_version: |
| 183 |
hw_info["chassis"][component_name]["part_number"] = components[ |
| 184 |
component |
| 185 |
].part_number |
| 186 |
components = list(blade.get_hardware(filter="type='bay'").items) |
| 187 |
for component in range(len(components)): |
| 188 |
component_name = components[component].name |
| 189 |
hw_info["bays"][component_name] = { |
| 190 |
"slot": components[component].slot, |
| 191 |
"index": components[component].index, |
| 192 |
"status": components[component].status, |
| 193 |
"serial": components[component].serial, |
| 194 |
"model": components[component].model, |
| 195 |
"identify": components[component].identify_enabled, |
| 196 |
} |
| 197 |
if PART_NUMBER_API_VERSION in api_version: |
| 198 |
hw_info["bays"][component_name]["part_number"] = components[ |
| 199 |
component |
| 200 |
].part_number |
| 201 |
|
| 202 |
return hw_info |
| 203 |
|
| 204 |
|
| 205 |
def main(): |
| 206 |
argument_spec = purefb_argument_spec() |
| 207 |
|
| 208 |
module = AnsibleModule(argument_spec, supports_check_mode=True) |
| 209 |
blade = get_system(module) |
| 210 |
module.exit_json(changed=False, purefb_info=generate_hardware_dict(blade)) |
| 211 |
|
| 212 |
|
| 213 |
if __name__ == "__main__": |
| 214 |
main() |