Debian Codegraph @

ansible_collections/community/general/plugins/modules/ibm_sa_vol_map.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_vol_map
13 short_description: Handles volume mapping on IBM Spectrum Accelerate Family storage systems
14
15 description:
16 - This module maps volumes to or unmaps them from the hosts on IBM Spectrum Accelerate Family storage systems.
17 attributes:
18 check_mode:
19 support: none
20 diff_mode:
21 support: none
22
23 options:
24 vol:
25 description:
26 - Volume name.
27 required: true
28 type: str
29 state:
30 default: "present"
31 choices: ["present", "absent"]
32 description:
33 - When the state is present the volume is mapped. When the state is absent, the volume is meant to be unmapped.
34 type: str
35
36 cluster:
37 description:
38 - Maps the volume to a cluster.
39 type: str
40 host:
41 description:
42 - Maps the volume to a host.
43 type: str
44 lun:
45 description:
46 - The LUN identifier.
47 type: str
48 override:
49 description:
50 - Overrides the existing volume mapping.
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: Map volume to host.
63 community.general.ibm_sa_vol_map:
64 vol: volume_name
65 lun: 1
66 host: host_name
67 username: admin
68 password: secret
69 endpoints: hostdev-system
70 state: present
71
72 - name: Map volume to cluster.
73 community.general.ibm_sa_vol_map:
74 vol: volume_name
75 lun: 1
76 cluster: cluster_name
77 username: admin
78 password: secret
79 endpoints: hostdev-system
80 state: present
81
82 - name: Unmap volume.
83 community.general.ibm_sa_vol_map:
84 host: host_name
85 username: admin
86 password: secret
87 endpoints: hostdev-system
88 state: absent
89 """
90 RETURN = r"""
91 """
92
93 from ansible.module_utils.basic import AnsibleModule
94
95 from ansible_collections.community.general.plugins.module_utils._ibm_sa_utils import (
96 connect_ssl,
97 execute_pyxcli_command,
98 is_pyxcli_installed,
99 spectrum_accelerate_spec,
100 )
101
102
103 def main():
104 argument_spec = spectrum_accelerate_spec()
105 argument_spec.update(
106 dict(
107 state=dict(default="present", choices=["present", "absent"]),
108 vol=dict(required=True),
109 lun=dict(),
110 cluster=dict(),
111 host=dict(),
112 override=dict(),
113 )
114 )
115
116 module = AnsibleModule(argument_spec)
117 is_pyxcli_installed(module)
118
119 xcli_client = connect_ssl(module)
120 # required args
121 mapping = False
122 try:
123 mapped_hosts = xcli_client.cmd.vol_mapping_list(vol=module.params.get("vol")).as_list
124 for host in mapped_hosts:
125 if host["host"] == module.params.get("host", ""):
126 mapping = True
127 except Exception:
128 pass
129 state = module.params["state"]
130
131 state_changed = False
132 if state == "present" and not mapping:
133 state_changed = execute_pyxcli_command(module, "map_vol", xcli_client)
134 if state == "absent" and mapping:
135 state_changed = execute_pyxcli_command(module, "unmap_vol", xcli_client)
136
137 module.exit_json(changed=state_changed)
138
139
140 if __name__ == "__main__":
141 main()