Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_ethernet_network_control_policy.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: intersight_ethernet_network_control_policy
16 short_description: Ethernet Network Control Policy configuration for Cisco Intersight
17 description:
18 - Manages Ethernet Network Control Policy configuration on Cisco Intersight.
19 - A policy to configure network control settings for ethernet connections on Cisco Intersight managed servers.
20 - This policy is applicable only for UCS Servers (FI-Attached).
21 - For more information see L(Cisco Intersight,https://intersight.com/apidocs/fabric/EthNetworkControlPolicy/get/).
22 extends_documentation_fragment: intersight
23 options:
24 state:
25 description:
26 - If C(present), will verify the resource is present and will create if needed.
27 - If C(absent), will verify the resource is absent and will delete if needed.
28 type: str
29 choices: [present, absent]
30 default: present
31 organization:
32 description:
33 - The name of the Organization this resource is assigned to.
34 - Profiles, Policies, and Pools that are created within a Custom Organization are applicable only to devices in the same Organization.
35 type: str
36 default: default
37 name:
38 description:
39 - The name assigned to the Ethernet Network Control Policy.
40 - The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_.
41 type: str
42 required: true
43 description:
44 description:
45 - The user-defined description for the Ethernet Network Control Policy.
46 - Description can contain letters(a-z, A-Z), numbers(0-9), hyphen(-), period(.), colon(:), or an underscore(_).
47 type: str
48 aliases: [descr]
49 tags:
50 description:
51 - List of tags in Key:<user-defined key> Value:<user-defined value> format.
52 type: list
53 elements: dict
54 cdp_enabled:
55 description:
56 - Enables the CDP on an interface.
57 - Cisco Discovery Protocol (CDP) is a proprietary Data Link Layer protocol developed by Cisco Systems.
58 type: bool
59 default: false
60 mac_registration_mode:
61 description:
62 - Determines the MAC addresses that have to be registered with the switch.
63 - nativeVlanOnly - Register only the MAC addresses learned in the native VLAN.
64 - allVlans - Register the MAC addresses learned in all VLANs.
65 type: str
66 choices: ['nativeVlanOnly', 'allVlans']
67 default: 'nativeVlanOnly'
68 uplink_fail_action:
69 description:
70 - Determines the state of the virtual interface (vethernet / vfc) on the switch when a suitable uplink is not pinned.
71 - linkDown - The vethernet will go down.
72 - warning - The vethernet will remain up and will not fail over if uplink connectivity is lost.
73 - "Important! If the Action on Uplink is set to Warning, the switch will not fail over if uplink connectivity is lost."
74 type: str
75 choices: ['linkDown', 'warning']
76 default: 'linkDown'
77 forge_mac:
78 description:
79 - Determines if the MAC forging is allowed or denied on an interface.
80 - allow - Allows MAC forging on the interface.
81 - deny - Denies MAC forging on the interface.
82 type: str
83 choices: ['allow', 'deny']
84 default: 'allow'
85 lldp_transmit_enabled:
86 description:
87 - Determines if the LLDP frames can be transmitted by an interface on the switch.
88 - Link Layer Discovery Protocol (LLDP) is a vendor-neutral link layer protocol.
89 type: bool
90 default: false
91 lldp_receive_enabled:
92 description:
93 - Determines if the LLDP frames can be received by an interface on the switch.
94 - Link Layer Discovery Protocol (LLDP) is a vendor-neutral link layer protocol.
95 type: bool
96 default: false
97 author:
98 - Ron Gershburg (@rgershbu)
99 '''
100
101 EXAMPLES = r'''
102 - name: Create an Ethernet Network Control Policy with default settings
103 cisco.intersight.intersight_ethernet_network_control_policy:
104 api_private_key: "{{ api_private_key }}"
105 api_key_id: "{{ api_key_id }}"
106 organization: "default"
107 name: "default-network-control-policy"
108 description: "Default Ethernet Network Control policy"
109 state: present
110
111 - name: Create an Ethernet Network Control Policy with CDP and LLDP enabled
112 cisco.intersight.intersight_ethernet_network_control_policy:
113 api_private_key: "{{ api_private_key }}"
114 api_key_id: "{{ api_key_id }}"
115 organization: "default"
116 name: "discovery-enabled-policy"
117 description: "Network Control policy with discovery protocols enabled"
118 tags:
119 - Key: "Environment"
120 Value: "Production"
121 cdp_enabled: true
122 mac_registration_mode: "allVlans"
123 uplink_fail_action: "warning"
124 forge_mac: "deny"
125 lldp_transmit_enabled: true
126 lldp_receive_enabled: true
127 state: present
128
129 - name: Create an Ethernet Network Control Policy with strict security settings
130 cisco.intersight.intersight_ethernet_network_control_policy:
131 api_private_key: "{{ api_private_key }}"
132 api_key_id: "{{ api_key_id }}"
133 name: "secure-network-control-policy"
134 description: "Secure Network Control policy with MAC forging denied"
135 cdp_enabled: false
136 mac_registration_mode: "nativeVlanOnly"
137 uplink_fail_action: "linkDown"
138 forge_mac: "deny"
139 lldp_transmit_enabled: false
140 lldp_receive_enabled: false
141 state: present
142
143 - name: Delete an Ethernet Network Control Policy
144 cisco.intersight.intersight_ethernet_network_control_policy:
145 api_private_key: "{{ api_private_key }}"
146 api_key_id: "{{ api_key_id }}"
147 name: "secure-network-control-policy"
148 state: absent
149 '''
150
151 RETURN = r'''
152 api_response:
153 description: The API response output returned by the specified resource.
154 returned: always
155 type: dict
156 sample:
157 "api_response": {
158 "Name": "discovery-enabled-policy",
159 "ObjectType": "fabric.EthNetworkControlPolicy",
160 "CdpEnabled": true,
161 "MacRegistrationMode": "allVlans",
162 "UplinkFailAction": "warning",
163 "ForgeMac": "deny",
164 "LldpSettings": {
165 "TransmitEnabled": true,
166 "ReceiveEnabled": true
167 },
168 "Tags": [
169 {
170 "Key": "Environment",
171 "Value": "Production"
172 }
173 ]
174 }
175 '''
176
177
178 from ansible.module_utils.basic import AnsibleModule
179 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
180
181
182 def main():
183 argument_spec = intersight_argument_spec.copy()
184 argument_spec.update(
185 state=dict(type='str', choices=['present', 'absent'], default='present'),
186 organization=dict(type='str', default='default'),
187 name=dict(type='str', required=True),
188 description=dict(type='str', aliases=['descr']),
189 tags=dict(type='list', elements='dict'),
190 cdp_enabled=dict(type='bool', default=False),
191 mac_registration_mode=dict(
192 type='str',
193 choices=['nativeVlanOnly', 'allVlans'],
194 default='nativeVlanOnly'
195 ),
196 uplink_fail_action=dict(
197 type='str',
198 choices=['linkDown', 'warning'],
199 default='linkDown'
200 ),
201 forge_mac=dict(
202 type='str',
203 choices=['allow', 'deny'],
204 default='allow'
205 ),
206 lldp_transmit_enabled=dict(type='bool', default=False),
207 lldp_receive_enabled=dict(type='bool', default=False),
208 )
209 module = AnsibleModule(
210 argument_spec,
211 supports_check_mode=True,
212 )
213
214 intersight = IntersightModule(module)
215 intersight.result['api_response'] = {}
216 intersight.result['trace_id'] = ''
217
218 # Resource path used to configure policy
219 resource_path = '/fabric/EthNetworkControlPolicies'
220
221 # Define API body used in compares or create
222 intersight.api_body = {
223 'Organization': {
224 'Name': intersight.module.params['organization'],
225 },
226 'Name': intersight.module.params['name']
227 }
228
229 if module.params['state'] == 'present':
230 intersight.set_tags_and_description()
231
232 intersight.api_body['CdpEnabled'] = module.params['cdp_enabled']
233 intersight.api_body['MacRegistrationMode'] = module.params['mac_registration_mode']
234 intersight.api_body['UplinkFailAction'] = module.params['uplink_fail_action']
235 intersight.api_body['ForgeMac'] = module.params['forge_mac']
236 intersight.api_body['LldpSettings'] = {
237 'TransmitEnabled': module.params['lldp_transmit_enabled'],
238 'ReceiveEnabled': module.params['lldp_receive_enabled']
239 }
240
241 intersight.configure_policy_or_profile(resource_path=resource_path)
242
243 module.exit_json(**intersight.result)
244
245
246 if __name__ == '__main__':
247 main()