Debian Codegraph @

ansible_collections/community/general/plugins/modules/oneview_network_set_info.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_network_set_info
10 short_description: Retrieve information about the OneView Network Sets
11 description:
12 - Retrieve information about the Network Sets from OneView.
13 requirements:
14 - hpOneView >= 2.0.1
15 author:
16 - Felipe Bulsoni (@fgbulsoni)
17 - Thiago Miotto (@tmiotto)
18 - Adriane Cardozo (@adriane-cardozo)
19 attributes:
20 check_mode:
21 version_added: 3.3.0
22 # This was backported to 2.5.4 and 1.3.11 as well, since this was a bugfix
23 options:
24 name:
25 description:
26 - Network Set name.
27 type: str
28
29 options:
30 description:
31 - 'List with options to gather information about Network Set. Option allowed: V(withoutEthernet). The option V(withoutEthernet)
32 retrieves the list of network_sets excluding Ethernet networks.'
33 type: list
34 elements: str
35
36 extends_documentation_fragment:
37 - community.general._oneview
38 - community.general._oneview.factsparams
39 - community.general._attributes
40 - community.general._attributes.info_module
41 """
42
43 EXAMPLES = r"""
44 - name: Gather information about all Network Sets
45 community.general.oneview_network_set_info:
46 hostname: 172.16.101.48
47 username: administrator
48 password: my_password
49 api_version: 500
50 no_log: true
51 delegate_to: localhost
52 register: result
53
54 - name: Print fetched information about Network Sets
55 ansible.builtin.debug:
56 msg: "{{ result.network_sets }}"
57
58 - name: Gather paginated, filtered and sorted information about Network Sets
59 community.general.oneview_network_set_info:
60 hostname: 172.16.101.48
61 username: administrator
62 password: my_password
63 api_version: 500
64 params:
65 start: 0
66 count: 3
67 sort: 'name:descending'
68 filter: name='netset001'
69 no_log: true
70 delegate_to: localhost
71 register: result
72
73 - name: Print fetched information about paginated, filtered and sorted list of Network Sets
74 ansible.builtin.debug:
75 msg: "{{ result.network_sets }}"
76
77 - name: Gather information about all Network Sets, excluding Ethernet networks
78 community.general.oneview_network_set_info:
79 hostname: 172.16.101.48
80 username: administrator
81 password: my_password
82 api_version: 500
83 options:
84 - withoutEthernet
85 no_log: true
86 delegate_to: localhost
87 register: result
88
89 - name: Print fetched information about Network Sets, excluding Ethernet networks
90 ansible.builtin.debug:
91 msg: "{{ result.network_sets }}"
92
93 - name: Gather information about a Network Set by name
94 community.general.oneview_network_set_info:
95 hostname: 172.16.101.48
96 username: administrator
97 password: my_password
98 api_version: 500
99 name: Name of the Network Set
100 no_log: true
101 delegate_to: localhost
102 register: result
103
104 - name: Print fetched information about Network Set found by name
105 ansible.builtin.debug:
106 msg: "{{ result.network_sets }}"
107
108 - name: Gather information about a Network Set by name, excluding Ethernet networks
109 community.general.oneview_network_set_info:
110 hostname: 172.16.101.48
111 username: administrator
112 password: my_password
113 api_version: 500
114 name: Name of the Network Set
115 options:
116 - withoutEthernet
117 no_log: true
118 delegate_to: localhost
119 register: result
120
121 - name: Print fetched information about Network Set found by name, excluding Ethernet networks
122 ansible.builtin.debug:
123 msg: "{{ result.network_sets }}"
124 """
125
126 RETURN = r"""
127 network_sets:
128 description: Has all the OneView information about the Network Sets.
129 returned: Always, but can be empty.
130 type: dict
131 """
132
133 from ansible_collections.community.general.plugins.module_utils._oneview import OneViewModuleBase
134
135
136 class NetworkSetInfoModule(OneViewModuleBase):
137 argument_spec = dict(
138 name=dict(type="str"),
139 options=dict(type="list", elements="str"),
140 params=dict(type="dict"),
141 )
142
143 def __init__(self):
144 super().__init__(
145 additional_arg_spec=self.argument_spec,
146 supports_check_mode=True,
147 )
148
149 def execute_module(self):
150 name = self.module.params.get("name")
151
152 if "withoutEthernet" in self.options:
153 filter_by_name = f"\"'name'='{name}'\"" if name else ""
154 network_sets = self.oneview_client.network_sets.get_all_without_ethernet(filter=filter_by_name)
155 elif name:
156 network_sets = self.oneview_client.network_sets.get_by("name", name)
157 else:
158 network_sets = self.oneview_client.network_sets.get_all(**self.facts_params)
159
160 return dict(changed=False, network_sets=network_sets)
161
162
163 def main():
164 NetworkSetInfoModule().run()
165
166
167 if __name__ == "__main__":
168 main()