Debian Codegraph @

ansible_collections/community/general/plugins/modules/ibm_sa_host.py

raw
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_host
13 short_description: Adds hosts to or removes them from IBM Spectrum Accelerate Family storage systems
14
15 description:
16 - This module adds hosts 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 host:
25 description:
26 - Host name.
27 required: true
28 type: str
29 state:
30 description:
31 - Host state.
32 default: "present"
33 choices: ["present", "absent"]
34 type: str
35 cluster:
36 description:
37 - The name of the cluster to include the host.
38 type: str
39 domain:
40 description:
41 - The domains the cluster is attached to. To include more than one domain, separate domain names with commas. To include
42 all existing domains, use an asterisk (V(*)).
43 type: str
44 iscsi_chap_name:
45 description:
46 - The host's CHAP name identifier.
47 type: str
48 iscsi_chap_secret:
49 description:
50 - The password of the initiator used to authenticate to the system when CHAP is enable.
51 type: str
52
53 extends_documentation_fragment:
54 - community.general._ibm_storage
55 - community.general._attributes
56
57 author:
58 - Tzur Eliyahu (@tzure)
59 """
60
61 EXAMPLES = r"""
62 - name: Define new host.
63 community.general.ibm_sa_host:
64 host: host_name
65 state: present
66 username: admin
67 password: secret
68 endpoints: hostdev-system
69
70 - name: Delete host.
71 community.general.ibm_sa_host:
72 host: host_name
73 state: absent
74 username: admin
75 password: secret
76 endpoints: hostdev-system
77 """
78 RETURN = r"""
79 """
80
81 from ansible.module_utils.basic import AnsibleModule
82
83 from ansible_collections.community.general.plugins.module_utils._ibm_sa_utils import (
84 connect_ssl,
85 execute_pyxcli_command,
86 is_pyxcli_installed,
87 spectrum_accelerate_spec,
88 )
89
90
91 def main():
92 argument_spec = spectrum_accelerate_spec()
93 argument_spec.update(
94 dict(
95 state=dict(default="present", choices=["present", "absent"]),
96 host=dict(required=True),
97 cluster=dict(),
98 domain=dict(),
99 iscsi_chap_name=dict(),
100 iscsi_chap_secret=dict(no_log=True),
101 )
102 )
103
104 module = AnsibleModule(argument_spec)
105
106 is_pyxcli_installed(module)
107
108 xcli_client = connect_ssl(module)
109 host = xcli_client.cmd.host_list(host=module.params["host"]).as_single_element
110 state = module.params["state"]
111
112 state_changed = False
113 if state == "present" and not host:
114 state_changed = execute_pyxcli_command(module, "host_define", xcli_client)
115 elif state == "absent" and host:
116 state_changed = execute_pyxcli_command(module, "host_delete", xcli_client)
117
118 module.exit_json(changed=state_changed)
119
120
121 if __name__ == "__main__":
122 main()