Debian Codegraph @

ansible_collections/cisco/ucs/plugins/modules/ucs_vlan_find.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 #
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7 __metaclass__ = type
8
9 ANSIBLE_METADATA = {'metadata_version': '1.1',
10 'status': ['preview'],
11 'supported_by': 'community'}
12
13 DOCUMENTATION = r'''
14 ---
15 module: ucs_vlan_find
16 short_description: Find VLANs on Cisco UCS Manager
17 description:
18 - Find VLANs on Cisco UCS Manager based on different criteria.
19 extends_documentation_fragment: cisco.ucs.ucs
20 options:
21 pattern:
22 description:
23 - Regex pattern to find within the name property of the fabricVlan class.
24 - This is required if C(vlanid) parameter is not supplied.
25 type: str
26 fabric:
27 description:
28 - "The fabric configuration of the VLAN. This can be one of the following:"
29 - "common - The VLAN applies to both fabrics and uses the same configuration parameters in both cases."
30 - "A — The VLAN only applies to fabric A."
31 - "B — The VLAN only applies to fabric B."
32 choices: [common, A, B]
33 default: common
34 type: str
35 vlanid:
36 description:
37 - The unique string identifier assigned to the VLAN.
38 - A VLAN ID can be between '1' and '3967', or between '4048' and '4093'.
39 - This is required if C(pattern) parameter is not supplied.
40 type: str
41 requirements:
42 - ucsmsdk
43 author:
44 - David Martinez (@dx0xm)
45 - David Soper (@dsoper2)
46 - John McDonough (@movinalot)
47 - CiscoUcs (@CiscoUcs)
48 '''
49
50 EXAMPLES = r'''
51 - name: Get all vlans in fabric A
52 cisco.ucs.ucs_vlan_find:
53 hostname: 172.16.143.150
54 username: admin
55 password: password
56 fabric: 'A'
57 pattern: '.'
58 - name: Confirm if vlan 15 is present
59 cisco.ucs.ucs_vlan_find:
60 hostname: 172.16.143.150
61 username: admin
62 password: password
63 vlanid: '15'
64 '''
65
66 RETURN = r'''
67 vlan_list:
68 description: basic details of vlans found
69 returned: on success
70 type: list
71 sample: [
72 {
73 "id": "0",
74 "name": "vlcloud1"
75 }
76 ]
77 '''
78
79
80 from ansible.module_utils.basic import AnsibleModule
81 from ansible_collections.cisco.ucs.plugins.module_utils.ucs import UCSModule, ucs_argument_spec
82
83
84 def main():
85 argument_spec = ucs_argument_spec.copy()
86 argument_spec.update(
87 fabric=dict(type='str', default='common', choices=['common', 'A', 'B']),
88 pattern=dict(type='str'),
89 vlanid=dict(type='str')
90 )
91
92 module = AnsibleModule(
93 argument_spec=argument_spec,
94 supports_check_mode=True,
95 required_one_of=[['pattern', 'vlanid']]
96 )
97
98 ucs = UCSModule(module)
99
100 filtls = ['(cloud,"ethlan")']
101 if module.params['fabric'] != 'common':
102 filtls.append('(switch_id,"' + module.params['fabric'] + '")')
103 if module.params['vlanid']:
104 filtls.append('(id,"' + module.params['vlanid'] + '")')
105 else:
106 filtls.append('(name,"' + module.params['pattern'] + '")')
107
108 object_dict = ucs.login_handle.query_classid("fabricVlan", filter_str=' and '.join(filtls))
109
110 if object_dict is None:
111 module.fail_json(msg="Failed to query vlan objects")
112
113 vlnlist = []
114 for ob in object_dict:
115 vlnlist.append(dict(name=ob.name, id=ob.id))
116
117 module.exit_json(changed=False,
118 vlan_list=vlnlist)
119
120
121 if __name__ == '__main__':
122 main()