| 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: purefa_ra |
| 20 |
version_added: '1.0.0' |
| 21 |
short_description: Enable or Disable Pure Storage FlashArray Remote Assist |
| 22 |
description: |
| 23 |
- Enable or Disable Remote Assist for a Pure Storage FlashArray. |
| 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: [ enable, disable, absent, present, test ] |
| 35 |
duration: |
| 36 |
description: |
| 37 |
- Number of hours Remote Assist port stays open for. |
| 38 |
- Must be an integer between 4 and 48 |
| 39 |
type: int |
| 40 |
default: 24 |
| 41 |
version_added: 1.33.0 |
| 42 |
extends_documentation_fragment: |
| 43 |
- purestorage.flasharray.purestorage.fa |
| 44 |
""" |
| 45 |
|
| 46 |
EXAMPLES = r""" |
| 47 |
- name: Enable Remote Assist port |
| 48 |
purestorage.flasharray.purefa_ra: |
| 49 |
duration: 12 |
| 50 |
fa_url: 10.10.10.2 |
| 51 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 52 |
register: result |
| 53 |
|
| 54 |
debug: |
| 55 |
msg: "Remote Assist: {{ result['ra_info'] }}" |
| 56 |
|
| 57 |
- name: Disable Remote Assist port |
| 58 |
purestorage.flasharray.purefa_ra: |
| 59 |
state: disable |
| 60 |
fa_url: 10.10.10.2 |
| 61 |
api_token: e31060a7-21fc-e277-6240-25983c6c4592 |
| 62 |
""" |
| 63 |
|
| 64 |
RETURN = r""" |
| 65 |
""" |
| 66 |
|
| 67 |
from ansible.module_utils.basic import AnsibleModule |
| 68 |
from ansible_collections.purestorage.flasharray.plugins.module_utils.purefa import ( |
| 69 |
get_array, |
| 70 |
purefa_argument_spec, |
| 71 |
) |
| 72 |
from ansible_collections.purestorage.flasharray.plugins.module_utils.version import ( |
| 73 |
LooseVersion, |
| 74 |
) |
| 75 |
|
| 76 |
HAS_PURESTORAGE = True |
| 77 |
try: |
| 78 |
from pypureclient.flasharray import SupportPatch |
| 79 |
except ImportError: |
| 80 |
HAS_PURESTORAGE = False |
| 81 |
|
| 82 |
DURATION_API = "2.35" |
| 83 |
|
| 84 |
|
| 85 |
def test_ra(module, array): |
| 86 |
"""Test support/remote assist configuration""" |
| 87 |
test_response = [] |
| 88 |
response = list(array.get_support_test().items) |
| 89 |
for component in response: |
| 90 |
if component.enabled: |
| 91 |
enabled = "true" |
| 92 |
else: |
| 93 |
enabled = "false" |
| 94 |
if component.success: |
| 95 |
success = "true" |
| 96 |
else: |
| 97 |
success = "false" |
| 98 |
test_response.append( |
| 99 |
{ |
| 100 |
"component_address": component.component_address, |
| 101 |
"component_name": component.component_name, |
| 102 |
"description": component.description, |
| 103 |
"destination": component.destination, |
| 104 |
"enabled": enabled, |
| 105 |
"result_details": getattr(component, "result_details", ""), |
| 106 |
"success": success, |
| 107 |
"test_type": component.test_type, |
| 108 |
"resource_name": component.resource.name, |
| 109 |
} |
| 110 |
) |
| 111 |
module.exit_json(changed=True, test_response=test_response) |
| 112 |
|
| 113 |
|
| 114 |
def enable_ra(module, array): |
| 115 |
"""Enable Remote Assist""" |
| 116 |
changed = False |
| 117 |
ra_facts = {} |
| 118 |
if not list(array.get_support().items)[0].remote_assist_status in [ |
| 119 |
"connected", |
| 120 |
"connecting", |
| 121 |
"enabled", |
| 122 |
]: |
| 123 |
changed = True |
| 124 |
res = {} |
| 125 |
api_version = array.get_rest_version() |
| 126 |
if not module.check_mode: |
| 127 |
if LooseVersion(DURATION_API) <= LooseVersion(api_version): |
| 128 |
if not 4 <= module.params["duration"] <= 48: |
| 129 |
module.fail_json(msg="The duration must be between 4-48 hours.") |
| 130 |
else: |
| 131 |
duration = module.params["duration"] * 3600000 |
| 132 |
res = array.patch_support( |
| 133 |
support=SupportPatch( |
| 134 |
remote_assist_duration=duration, remote_assist_active=True |
| 135 |
) |
| 136 |
) |
| 137 |
else: |
| 138 |
res = array.patch_support( |
| 139 |
support=SupportPatch(remote_assist_active=True) |
| 140 |
) |
| 141 |
if res.status_code == 200: |
| 142 |
ra_data = list(res.items)[0] |
| 143 |
ra_facts["fa_ra"] = { |
| 144 |
"name": ra_data.remote_assist_paths[0].component_name, |
| 145 |
"port": None, |
| 146 |
} |
| 147 |
else: |
| 148 |
module.fail_json( |
| 149 |
msg="Enabling Remote Assist failed. Error: {0}".format( |
| 150 |
res.errors[0].message |
| 151 |
) |
| 152 |
) |
| 153 |
else: |
| 154 |
res = array.get_support() |
| 155 |
if res.status_code == 200: |
| 156 |
ra_data = list(res.items)[0] |
| 157 |
ra_facts["fa_ra"] = { |
| 158 |
"name": ra_data.remote_assist_paths[0].component_name, |
| 159 |
"port": None, |
| 160 |
} |
| 161 |
else: |
| 162 |
module.fail_json( |
| 163 |
msg="Getting Remote Assist failed. Error: {0}".format( |
| 164 |
res.errors[0].message |
| 165 |
) |
| 166 |
) |
| 167 |
module.exit_json(changed=changed, ra_info=ra_facts) |
| 168 |
|
| 169 |
|
| 170 |
def disable_ra(module, array): |
| 171 |
"""Disable Remote Assist""" |
| 172 |
changed = False |
| 173 |
if list(array.get_support().items)[0].remote_assist_status in [ |
| 174 |
"connected", |
| 175 |
"connecting", |
| 176 |
"enabled", |
| 177 |
]: |
| 178 |
changed = True |
| 179 |
if not module.check_mode: |
| 180 |
res = array.patch_support(support=SupportPatch(remote_assist_active=False)) |
| 181 |
if res.status_code != 200: |
| 182 |
module.fail_json( |
| 183 |
msg="Disabling Remote Assist failed. Error: {0}".format( |
| 184 |
res.errors[0].message |
| 185 |
) |
| 186 |
) |
| 187 |
module.exit_json(changed=changed) |
| 188 |
|
| 189 |
|
| 190 |
def main(): |
| 191 |
argument_spec = purefa_argument_spec() |
| 192 |
argument_spec.update( |
| 193 |
dict( |
| 194 |
state=dict( |
| 195 |
type="str", |
| 196 |
default="present", |
| 197 |
choices=["enable", "disable", "absent", "present", "test"], |
| 198 |
), |
| 199 |
duration=dict(type="int", default=24), |
| 200 |
) |
| 201 |
) |
| 202 |
|
| 203 |
module = AnsibleModule(argument_spec, supports_check_mode=True) |
| 204 |
if not HAS_PURESTORAGE: |
| 205 |
module.fail_json(msg="py-pure-client sdk is required for this module") |
| 206 |
|
| 207 |
array = get_array(module) |
| 208 |
|
| 209 |
if module.params["state"] in ["enable", "present"]: |
| 210 |
enable_ra(module, array) |
| 211 |
elif module.params["state"] == "test": |
| 212 |
test_ra(module, array) |
| 213 |
else: |
| 214 |
disable_ra(module, array) |
| 215 |
module.exit_json(changed=False) |
| 216 |
|
| 217 |
|
| 218 |
if __name__ == "__main__": |
| 219 |
main() |