| 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_hardware |
| 20 |
version_added: '1.15.0' |
| 21 |
short_description: Manage FlashBlade Hardware |
| 22 |
description: |
| 23 |
- Enable or disable FlashBlade visual identification lights and set connector parameters |
| 24 |
author: |
| 25 |
- Pure Storage Ansible Team (@sdodsley) <[email protected]> |
| 26 |
options: |
| 27 |
name: |
| 28 |
description: |
| 29 |
- Name of hardware component |
| 30 |
type: str |
| 31 |
required: true |
| 32 |
enabled: |
| 33 |
description: |
| 34 |
- State of the component identification LED |
| 35 |
type: bool |
| 36 |
speed: |
| 37 |
description: |
| 38 |
- If the component specified is a connector, set the configured speed |
| 39 |
of each lane in the connector in gigabits-per-second |
| 40 |
type: int |
| 41 |
choices: [ 10, 25, 40 ] |
| 42 |
ports: |
| 43 |
description: |
| 44 |
- If the component specificed is a connector, the number of configured |
| 45 |
ports in the connector |
| 46 |
type: int |
| 47 |
choices: [ 1, 4 ] |
| 48 |
extends_documentation_fragment: |
| 49 |
- purestorage.flashblade.purestorage.fb |
| 50 |
""" |
| 51 |
|
| 52 |
EXAMPLES = r""" |
| 53 |
- name: Set connector to be 4 x 40Gb ports |
| 54 |
purestorage.flashblade.purefb_hardware: |
| 55 |
name: "CH1.FM1.ETH1" |
| 56 |
speed: 40 |
| 57 |
ports: 4 |
| 58 |
fb_url: 10.10.10.2 |
| 59 |
api_token: T-68618f31-0c9e-4e57-aa44-5306a2cf10e3 |
| 60 |
|
| 61 |
- name: Enable identification LED |
| 62 |
purestorage.flashblade.purefb_hardware: |
| 63 |
name: "CH1.FB1" |
| 64 |
enabled: true |
| 65 |
fb_url: 10.10.10.2 |
| 66 |
api_token: T-68618f31-0c9e-4e57-aa44-5306a2cf10e3 |
| 67 |
|
| 68 |
- name: Disable identification LED |
| 69 |
purestorage.flashblade.purefb_hardware: |
| 70 |
name: "CH1.FB1" |
| 71 |
enabled: false |
| 72 |
fb_url: 10.10.10.2 |
| 73 |
api_token: T-68618f31-0c9e-4e57-aa44-5306a2cf10e3 |
| 74 |
""" |
| 75 |
|
| 76 |
RETURN = r""" |
| 77 |
""" |
| 78 |
|
| 79 |
HAS_PURESTORAGE = True |
| 80 |
try: |
| 81 |
from pypureclient import flashblade |
| 82 |
except ImportError: |
| 83 |
HAS_PURESTORAGE = False |
| 84 |
|
| 85 |
from ansible.module_utils.basic import AnsibleModule |
| 86 |
from ansible_collections.purestorage.flashblade.plugins.module_utils.purefb import ( |
| 87 |
get_system, |
| 88 |
purefb_argument_spec, |
| 89 |
) |
| 90 |
|
| 91 |
|
| 92 |
def main(): |
| 93 |
argument_spec = purefb_argument_spec() |
| 94 |
argument_spec.update( |
| 95 |
dict( |
| 96 |
enabled=dict(type="bool"), |
| 97 |
name=dict(type="str", required=True), |
| 98 |
speed=dict( |
| 99 |
type="int", |
| 100 |
choices=[10, 25, 40], |
| 101 |
), |
| 102 |
ports=dict( |
| 103 |
type="int", |
| 104 |
choices=[1, 4], |
| 105 |
), |
| 106 |
) |
| 107 |
) |
| 108 |
|
| 109 |
module = AnsibleModule(argument_spec, supports_check_mode=True) |
| 110 |
if not HAS_PURESTORAGE: |
| 111 |
module.fail_json(msg="py-pure-client sdk is required for this module") |
| 112 |
|
| 113 |
blade = get_system(module) |
| 114 |
api_version = list(blade.get_versions().items) |
| 115 |
|
| 116 |
if module.params["speed"]: |
| 117 |
speed = module.params["speed"] * 1000000000 |
| 118 |
changed = False |
| 119 |
hardware = None |
| 120 |
res = blade.get_hardware(names=[module.params["name"]]) |
| 121 |
if res.status_code == 200: |
| 122 |
hardware = list(res.items)[0] |
| 123 |
if hardware.identify_enabled != module.params["enabled"]: |
| 124 |
changed = True |
| 125 |
if not module.check_mode: |
| 126 |
res = blade.patch_hardware( |
| 127 |
names=[module.params["name"]], |
| 128 |
hardware=flashblade.Hardware( |
| 129 |
identify_enabled=module.params["enabled"] |
| 130 |
), |
| 131 |
) |
| 132 |
if res.status_code != 200: |
| 133 |
module.fail_json( |
| 134 |
msg="Failed to set identification LED for {0}. Error: {1}".format( |
| 135 |
module.params["name"], res.errors[0].message |
| 136 |
) |
| 137 |
) |
| 138 |
res = blade.get_hardware_connectors(names=[module.params["name"]]) |
| 139 |
if res.status_code == 200: |
| 140 |
connector = list(res.items)[0] |
| 141 |
if connector.port_count != module.params["ports"]: |
| 142 |
changed = True |
| 143 |
if not module.check_mode: |
| 144 |
res = blade.patch_hardware_connectors( |
| 145 |
names=[module.params["name"]], |
| 146 |
hardware_connector=flashblade.HardwareConnector( |
| 147 |
port_count=module.params["ports"] |
| 148 |
), |
| 149 |
) |
| 150 |
if res.status_code != 200: |
| 151 |
module.fail_json( |
| 152 |
msg="Failed to change connector port count {0}. Error: Invalid port count".format( |
| 153 |
module.params["name"] |
| 154 |
) |
| 155 |
) |
| 156 |
if connector.lane_speed != speed: |
| 157 |
changed = True |
| 158 |
if not module.check_mode: |
| 159 |
res = blade.patch_hardware_connectors( |
| 160 |
names=[module.params["name"]], |
| 161 |
hardware_connector=flashblade.HardwareConnector(lane_speed=speed), |
| 162 |
) |
| 163 |
if res.status_code != 200: |
| 164 |
module.fail_json( |
| 165 |
msg="Failed to change connector lane speed {0}. Error: Invalid lane speed".format( |
| 166 |
module.params["name"] |
| 167 |
) |
| 168 |
) |
| 169 |
|
| 170 |
module.exit_json(changed=changed) |
| 171 |
|
| 172 |
|
| 173 |
if __name__ == "__main__": |
| 174 |
main() |