| 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_ra |
| 20 |
version_added: '1.0.0' |
| 21 |
short_description: Enable or Disable Pure Storage FlashBlade Remote Assist |
| 22 |
description: |
| 23 |
- Enablke or Disable Remote Assist for a Pure Storage FlashBlade. |
| 24 |
author: |
| 25 |
- Pure Storage Ansible Team (@sdodsley) <[email protected]> |
| 26 |
options: |
| 27 |
state: |
| 28 |
description: |
| 29 |
- Define state of remote assist |
| 30 |
- When set to I(enable) the RA port can be exposed using the |
| 31 |
I(debug) module. |
| 32 |
type: str |
| 33 |
default: present |
| 34 |
choices: [ present, absent, test ] |
| 35 |
duration: |
| 36 |
description: |
| 37 |
- Specifies the duration of the remote-assist session in hours |
| 38 |
- It determines the length of time the session will remain active after |
| 39 |
it's initiated. |
| 40 |
type: int |
| 41 |
default: 24 |
| 42 |
version_added: '1.18.0' |
| 43 |
extends_documentation_fragment: |
| 44 |
- purestorage.flashblade.purestorage.fb |
| 45 |
""" |
| 46 |
|
| 47 |
EXAMPLES = r""" |
| 48 |
- name: Enable Remote Assist port |
| 49 |
purestorage.flashblade.purefb_ra: |
| 50 |
fb_url: 10.10.10.2 |
| 51 |
api_token: T-9f276a18-50ab-446e-8a0c-666a3529a1b6 |
| 52 |
- name: Disable Remote Assist port |
| 53 |
purestorage.flashblade.purefb_ra: |
| 54 |
state: absent |
| 55 |
fb_url: 10.10.10.2 |
| 56 |
api_token: T-9f276a18-50ab-446e-8a0c-666a3529a1b6 |
| 57 |
""" |
| 58 |
|
| 59 |
RETURN = r""" |
| 60 |
""" |
| 61 |
|
| 62 |
HAS_PYPURECLIENT = True |
| 63 |
try: |
| 64 |
from pypureclient.flashblade import Support |
| 65 |
except ImportError: |
| 66 |
HAS_PYPURECLIENT = False |
| 67 |
|
| 68 |
from ansible.module_utils.basic import AnsibleModule |
| 69 |
from ansible_collections.purestorage.flashblade.plugins.module_utils.purefb import ( |
| 70 |
get_system, |
| 71 |
purefb_argument_spec, |
| 72 |
) |
| 73 |
|
| 74 |
|
| 75 |
DURATION_API = "2.14" |
| 76 |
|
| 77 |
|
| 78 |
def enable_ra(module, blade): |
| 79 |
"""Enable Remote Assist""" |
| 80 |
changed = True |
| 81 |
if not module.check_mode: |
| 82 |
if DURATION_API in list(blade.get_versions().items): |
| 83 |
duration = module.params["duration"] * 3600000 |
| 84 |
ra_settings = Support( |
| 85 |
remote_assist_active=True, remote_assist_duration=duration |
| 86 |
) |
| 87 |
else: |
| 88 |
ra_settings = Support(remote_assist_active=True) |
| 89 |
res = blade.patch_support(support=ra_settings) |
| 90 |
if res.status_code != 200: |
| 91 |
module.fail_json( |
| 92 |
msg="Enabling Remote Assist failed. Error: {0}".format( |
| 93 |
res.errors[0].message |
| 94 |
) |
| 95 |
) |
| 96 |
module.exit_json(changed=changed) |
| 97 |
|
| 98 |
|
| 99 |
def disable_ra(module, blade): |
| 100 |
"""Disable Remote Assist""" |
| 101 |
changed = True |
| 102 |
if not module.check_mode: |
| 103 |
ra_settings = Support(remote_assist_active=False) |
| 104 |
res = blade.patch_support(support=ra_settings) |
| 105 |
if res.status_code != 200: |
| 106 |
module.fail_json( |
| 107 |
msg="Disabling Remote Assist failed. Error: {0}".format( |
| 108 |
res.errors[0].message |
| 109 |
) |
| 110 |
) |
| 111 |
module.exit_json(changed=changed) |
| 112 |
|
| 113 |
|
| 114 |
def test_ra(module, blade): |
| 115 |
"""Test support/remote assist configuration""" |
| 116 |
test_response = [] |
| 117 |
response = list(blade.get_support_test(test_type="remote-assist").items) |
| 118 |
for component in range(len(response)): |
| 119 |
if response[component].enabled: |
| 120 |
enabled = "true" |
| 121 |
else: |
| 122 |
enabled = "false" |
| 123 |
if response[component].success: |
| 124 |
success = "true" |
| 125 |
else: |
| 126 |
success = "false" |
| 127 |
test_response.append( |
| 128 |
{ |
| 129 |
"component_address": response[component].component_address, |
| 130 |
"component_name": response[component].component_name, |
| 131 |
"description": response[component].description, |
| 132 |
"destination": response[component].destination, |
| 133 |
"enabled": enabled, |
| 134 |
"result_details": getattr(response[component], "result_details", ""), |
| 135 |
"success": success, |
| 136 |
"test_type": response[component].test_type, |
| 137 |
} |
| 138 |
) |
| 139 |
module.exit_json(changed=False, test_response=test_response) |
| 140 |
|
| 141 |
|
| 142 |
def main(): |
| 143 |
argument_spec = purefb_argument_spec() |
| 144 |
argument_spec.update( |
| 145 |
dict( |
| 146 |
state=dict( |
| 147 |
type="str", default="present", choices=["present", "absent", "test"] |
| 148 |
), |
| 149 |
duration=dict(type="int", default=24), |
| 150 |
) |
| 151 |
) |
| 152 |
|
| 153 |
module = AnsibleModule(argument_spec, supports_check_mode=True) |
| 154 |
|
| 155 |
blade = get_system(module) |
| 156 |
|
| 157 |
if not HAS_PYPURECLIENT: |
| 158 |
module.fail_json(msg="pypureclient SDK is required for this module") |
| 159 |
active = list(blade.get_support().items)[0].remote_assist_active |
| 160 |
if module.params["state"] == "present" and not active: |
| 161 |
enable_ra(module, blade) |
| 162 |
elif module.params["state"] == "absent" and active: |
| 163 |
disable_ra(module, blade) |
| 164 |
elif module.params["state"] == "test": |
| 165 |
test_ra(module, blade) |
| 166 |
module.exit_json(changed=False) |
| 167 |
|
| 168 |
|
| 169 |
if __name__ == "__main__": |
| 170 |
main() |