Debian Codegraph @

ansible_collections/community/general/plugins/modules/oneview_fcoe_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_fcoe_network
10 short_description: Manage OneView FCoE Network resources
11 description:
12 - Provides an interface to manage FCoE Network resources. Can create, update, or delete.
13 requirements:
14 - "Python >= 2.7.9"
15 - "hpOneView >= 4.0.0"
16 author: "Felipe Bulsoni (@fgbulsoni)"
17 attributes:
18 check_mode:
19 support: none
20 diff_mode:
21 support: none
22 options:
23 state:
24 description:
25 - Indicates the desired state for the FCoE Network resource.
26 - V(present) ensures data properties are compliant with OneView.
27 - V(absent) removes the resource from OneView, if it exists.
28 type: str
29 default: present
30 choices: ['present', 'absent']
31 data:
32 description:
33 - List with FCoE Network properties.
34 type: dict
35 required: true
36
37 extends_documentation_fragment:
38 - community.general._oneview
39 - community.general._oneview.validateetag
40 - community.general._attributes
41 """
42
43 EXAMPLES = r"""
44 - name: Ensure that FCoE Network is present using the default configuration
45 community.general.oneview_fcoe_network:
46 config: '/etc/oneview/oneview_config.json'
47 state: present
48 data:
49 name: Test FCoE Network
50 vlanId: 201
51 delegate_to: localhost
52
53 - name: Update the FCOE network scopes
54 community.general.oneview_fcoe_network:
55 config: '/etc/oneview/oneview_config.json'
56 state: present
57 data:
58 name: New FCoE Network
59 scopeUris:
60 - '/rest/scopes/00SC123456'
61 - '/rest/scopes/01SC123456'
62 delegate_to: localhost
63
64 - name: Ensure that FCoE Network is absent
65 community.general.oneview_fcoe_network:
66 config: '/etc/oneview/oneview_config.json'
67 state: absent
68 data:
69 name: New FCoE Network
70 delegate_to: localhost
71 """
72
73 RETURN = r"""
74 fcoe_network:
75 description: Has the facts about the OneView FCoE Networks.
76 returned: On O(state=present). Can be null.
77 type: dict
78 """
79
80 from ansible_collections.community.general.plugins.module_utils._oneview import OneViewModuleBase
81
82
83 class FcoeNetworkModule(OneViewModuleBase):
84 MSG_CREATED = "FCoE Network created successfully."
85 MSG_UPDATED = "FCoE Network updated successfully."
86 MSG_DELETED = "FCoE Network deleted successfully."
87 MSG_ALREADY_PRESENT = "FCoE Network is already present."
88 MSG_ALREADY_ABSENT = "FCoE Network is already absent."
89 RESOURCE_FACT_NAME = "fcoe_network"
90
91 def __init__(self):
92 additional_arg_spec = dict(
93 data=dict(required=True, type="dict"), state=dict(default="present", choices=["present", "absent"])
94 )
95
96 super().__init__(additional_arg_spec=additional_arg_spec, validate_etag_support=True)
97
98 self.resource_client = self.oneview_client.fcoe_networks
99
100 def execute_module(self):
101 resource = self.get_by_name(self.data.get("name"))
102
103 if self.state == "present":
104 return self.__present(resource)
105 elif self.state == "absent":
106 return self.resource_absent(resource)
107
108 def __present(self, resource):
109 scope_uris = self.data.pop("scopeUris", None)
110 result = self.resource_present(resource, self.RESOURCE_FACT_NAME)
111 if scope_uris is not None:
112 result = self.resource_scopes_set(result, "fcoe_network", scope_uris)
113 return result
114
115
116 def main():
117 FcoeNetworkModule().run()
118
119
120 if __name__ == "__main__":
121 main()