Debian Codegraph @

ansible_collections/community/general/plugins/modules/ibm_sa_vol.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
13 short_description: Handle volumes on IBM Spectrum Accelerate Family storage systems
14
15 description:
16 - This module creates or deletes volumes to be used 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 pool:
30 description:
31 - Volume pool.
32 type: str
33 state:
34 description:
35 - Volume state.
36 default: "present"
37 choices: ["present", "absent"]
38 type: str
39 size:
40 description:
41 - Volume size.
42 type: str
43
44 extends_documentation_fragment:
45 - community.general._ibm_storage
46 - community.general._attributes
47
48 author:
49 - Tzur Eliyahu (@tzure)
50 """
51
52 EXAMPLES = r"""
53 - name: Create a new volume.
54 community.general.ibm_sa_vol:
55 vol: volume_name
56 pool: pool_name
57 size: 17
58 state: present
59 username: admin
60 password: secret
61 endpoints: hostdev-system
62
63 - name: Delete an existing volume.
64 community.general.ibm_sa_vol:
65 vol: volume_name
66 state: absent
67 username: admin
68 password: secret
69 endpoints: hostdev-system
70 """
71 RETURN = r"""
72 """
73
74 from ansible.module_utils.basic import AnsibleModule
75
76 from ansible_collections.community.general.plugins.module_utils._ibm_sa_utils import (
77 connect_ssl,
78 execute_pyxcli_command,
79 is_pyxcli_installed,
80 spectrum_accelerate_spec,
81 )
82
83
84 def main():
85 argument_spec = spectrum_accelerate_spec()
86 argument_spec.update(
87 dict(
88 state=dict(default="present", choices=["present", "absent"]),
89 vol=dict(required=True),
90 pool=dict(),
91 size=dict(),
92 )
93 )
94
95 module = AnsibleModule(argument_spec)
96
97 is_pyxcli_installed(module)
98
99 xcli_client = connect_ssl(module)
100 # required args
101 volume = xcli_client.cmd.vol_list(vol=module.params.get("vol")).as_single_element
102 state = module.params["state"]
103
104 state_changed = False
105 if state == "present" and not volume:
106 state_changed = execute_pyxcli_command(module, "vol_create", xcli_client)
107 elif state == "absent" and volume:
108 state_changed = execute_pyxcli_command(module, "vol_delete", xcli_client)
109
110 module.exit_json(changed=state_changed)
111
112
113 if __name__ == "__main__":
114 main()