| 1 |
#!/usr/bin/python |
| 2 |
|
| 3 |
# Copyright (c) 2018, IBM CORPORATION |
| 4 |
# Author(s): Tzur Eliyahu <[email protected]> |
| 5 |
# |
| 6 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 7 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 8 |
|
| 9 |
from __future__ import annotations |
| 10 |
|
| 11 |
DOCUMENTATION = r""" |
| 12 |
module: ibm_sa_domain |
| 13 |
short_description: Manages domains on IBM Spectrum Accelerate Family storage systems |
| 14 |
|
| 15 |
description: |
| 16 |
- This module can be used to add domains to or removes them from IBM Spectrum Accelerate Family storage systems. |
| 17 |
attributes: |
| 18 |
check_mode: |
| 19 |
support: none |
| 20 |
diff_mode: |
| 21 |
support: none |
| 22 |
|
| 23 |
options: |
| 24 |
domain: |
| 25 |
description: |
| 26 |
- Name of the domain to be managed. |
| 27 |
required: true |
| 28 |
type: str |
| 29 |
state: |
| 30 |
description: |
| 31 |
- The desired state of the domain. |
| 32 |
default: "present" |
| 33 |
choices: ["present", "absent"] |
| 34 |
type: str |
| 35 |
ldap_id: |
| 36 |
description: |
| 37 |
- LDAP ID to add to the domain. |
| 38 |
type: str |
| 39 |
size: |
| 40 |
description: |
| 41 |
- Size of the domain. |
| 42 |
type: str |
| 43 |
hard_capacity: |
| 44 |
description: |
| 45 |
- Hard capacity of the domain. |
| 46 |
type: str |
| 47 |
soft_capacity: |
| 48 |
description: |
| 49 |
- Soft capacity of the domain. |
| 50 |
type: str |
| 51 |
max_cgs: |
| 52 |
description: |
| 53 |
- Number of max cgs. |
| 54 |
type: str |
| 55 |
max_dms: |
| 56 |
description: |
| 57 |
- Number of max dms. |
| 58 |
type: str |
| 59 |
max_mirrors: |
| 60 |
description: |
| 61 |
- Number of max_mirrors. |
| 62 |
type: str |
| 63 |
max_pools: |
| 64 |
description: |
| 65 |
- Number of max_pools. |
| 66 |
type: str |
| 67 |
max_volumes: |
| 68 |
description: |
| 69 |
- Number of max_volumes. |
| 70 |
type: str |
| 71 |
perf_class: |
| 72 |
description: |
| 73 |
- Add the domain to a performance class. |
| 74 |
type: str |
| 75 |
|
| 76 |
extends_documentation_fragment: |
| 77 |
- community.general._ibm_storage |
| 78 |
- community.general._attributes |
| 79 |
|
| 80 |
author: |
| 81 |
- Tzur Eliyahu (@tzure) |
| 82 |
""" |
| 83 |
|
| 84 |
EXAMPLES = r""" |
| 85 |
- name: Define new domain. |
| 86 |
community.general.ibm_sa_domain: |
| 87 |
domain: domain_name |
| 88 |
size: domain_size |
| 89 |
state: present |
| 90 |
username: admin |
| 91 |
password: secret |
| 92 |
endpoints: hostdev-system |
| 93 |
|
| 94 |
- name: Delete domain. |
| 95 |
community.general.ibm_sa_domain: |
| 96 |
domain: domain_name |
| 97 |
state: absent |
| 98 |
username: admin |
| 99 |
password: secret |
| 100 |
endpoints: hostdev-system |
| 101 |
""" |
| 102 |
RETURN = r""" |
| 103 |
msg: |
| 104 |
description: Module return status. |
| 105 |
returned: as needed |
| 106 |
type: str |
| 107 |
sample: "domain 'domain_name' created successfully." |
| 108 |
""" |
| 109 |
|
| 110 |
from ansible.module_utils.basic import AnsibleModule |
| 111 |
|
| 112 |
from ansible_collections.community.general.plugins.module_utils._ibm_sa_utils import ( |
| 113 |
connect_ssl, |
| 114 |
execute_pyxcli_command, |
| 115 |
is_pyxcli_installed, |
| 116 |
spectrum_accelerate_spec, |
| 117 |
) |
| 118 |
|
| 119 |
|
| 120 |
def main(): |
| 121 |
argument_spec = spectrum_accelerate_spec() |
| 122 |
argument_spec.update( |
| 123 |
dict( |
| 124 |
state=dict(default="present", choices=["present", "absent"]), |
| 125 |
domain=dict(required=True), |
| 126 |
size=dict(), |
| 127 |
max_dms=dict(), |
| 128 |
max_cgs=dict(), |
| 129 |
ldap_id=dict(), |
| 130 |
max_mirrors=dict(), |
| 131 |
max_pools=dict(), |
| 132 |
max_volumes=dict(), |
| 133 |
perf_class=dict(), |
| 134 |
hard_capacity=dict(), |
| 135 |
soft_capacity=dict(), |
| 136 |
) |
| 137 |
) |
| 138 |
|
| 139 |
module = AnsibleModule(argument_spec) |
| 140 |
|
| 141 |
is_pyxcli_installed(module) |
| 142 |
|
| 143 |
xcli_client = connect_ssl(module) |
| 144 |
domain = xcli_client.cmd.domain_list(domain=module.params["domain"]).as_single_element |
| 145 |
state = module.params["state"] |
| 146 |
|
| 147 |
state_changed = False |
| 148 |
msg = f"Domain '{module.params['domain']}'" |
| 149 |
if state == "present" and not domain: |
| 150 |
state_changed = execute_pyxcli_command(module, "domain_create", xcli_client) |
| 151 |
msg += " created successfully." |
| 152 |
elif state == "absent" and domain: |
| 153 |
state_changed = execute_pyxcli_command(module, "domain_delete", xcli_client) |
| 154 |
msg += " deleted successfully." |
| 155 |
else: |
| 156 |
msg += " state unchanged." |
| 157 |
|
| 158 |
module.exit_json(changed=state_changed, msg=msg) |
| 159 |
|
| 160 |
|
| 161 |
if __name__ == "__main__": |
| 162 |
main() |