Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # Copyright (c) 2016-2017 Hewlett Packard Enterprise Development LP
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 from __future__ import annotations
7
8 DOCUMENTATION = r"""
9 module: oneview_fc_network
10 short_description: Manage OneView Fibre Channel Network resources
11 description:
12 - Provides an interface to manage Fibre Channel Network resources. Can create, update, and delete.
13 requirements:
14 - "hpOneView >= 4.0.0"
15 author: "Felipe Bulsoni (@fgbulsoni)"
16 attributes:
17 check_mode:
18 support: none
19 diff_mode:
20 support: none
21 options:
22 state:
23 description:
24 - Indicates the desired state for the Fibre Channel Network resource.
25 - V(present) ensures data properties are compliant with OneView.
26 - V(absent) removes the resource from OneView, if it exists.
27 type: str
28 choices: ['present', 'absent']
29 required: true
30 data:
31 description:
32 - List with the Fibre Channel Network properties.
33 type: dict
34 required: true
35
36 extends_documentation_fragment:
37 - community.general._oneview
38 - community.general._oneview.validateetag
39 - community.general._attributes
40 """
41
42 EXAMPLES = r"""
43 - name: Ensure that the Fibre Channel Network is present using the default configuration
44 community.general.oneview_fc_network:
45 config: "{{ config_file_path }}"
46 state: present
47 data:
48 name: 'New FC Network'
49
50 - name: Ensure that the Fibre Channel Network is present with fabricType 'DirectAttach'
51 community.general.oneview_fc_network:
52 config: "{{ config_file_path }}"
53 state: present
54 data:
55 name: 'New FC Network'
56 fabricType: 'DirectAttach'
57
58 - name: Ensure that the Fibre Channel Network is present and is inserted in the desired scopes
59 community.general.oneview_fc_network:
60 config: "{{ config_file_path }}"
61 state: present
62 data:
63 name: 'New FC Network'
64 scopeUris:
65 - '/rest/scopes/00SC123456'
66 - '/rest/scopes/01SC123456'
67
68 - name: Ensure that the Fibre Channel Network is absent
69 community.general.oneview_fc_network:
70 config: "{{ config_file_path }}"
71 state: absent
72 data:
73 name: 'New FC Network'
74 """
75
76 RETURN = r"""
77 fc_network:
78 description: Has the facts about the managed OneView FC Network.
79 returned: On O(state=present). Can be null.
80 type: dict
81 """
82
83 from ansible_collections.community.general.plugins.module_utils._oneview import OneViewModuleBase
84
85
86 class FcNetworkModule(OneViewModuleBase):
87 MSG_CREATED = "FC Network created successfully."
88 MSG_UPDATED = "FC Network updated successfully."
89 MSG_DELETED = "FC Network deleted successfully."
90 MSG_ALREADY_PRESENT = "FC Network is already present."
91 MSG_ALREADY_ABSENT = "FC Network is already absent."
92 RESOURCE_FACT_NAME = "fc_network"
93
94 def __init__(self):
95 additional_arg_spec = dict(
96 data=dict(required=True, type="dict"), state=dict(required=True, choices=["present", "absent"])
97 )
98
99 super().__init__(additional_arg_spec=additional_arg_spec, validate_etag_support=True)
100
101 self.resource_client = self.oneview_client.fc_networks
102
103 def execute_module(self):
104 resource = self.get_by_name(self.data["name"])
105
106 if self.state == "present":
107 return self._present(resource)
108 else:
109 return self.resource_absent(resource)
110
111 def _present(self, resource):
112 scope_uris = self.data.pop("scopeUris", None)
113 result = self.resource_present(resource, self.RESOURCE_FACT_NAME)
114 if scope_uris is not None:
115 result = self.resource_scopes_set(result, "fc_network", scope_uris)
116 return result
117
118
119 def main():
120 FcNetworkModule().run()
121
122
123 if __name__ == "__main__":
124 main()