Debian Codegraph @

ansible_collections/cisco/ucs/plugins/modules/ucs_system_qos.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_system_qos
16 short_description: Configures system QoS settings
17 description:
18 - Configures system QoS settings
19 extends_documentation_fragment: cisco.ucs.ucs
20 options:
21 priority:
22 description: Priority to configure
23 choices: ["best-effort", "bronze", "fc", "gold","platinum", "silver"]
24 required: true
25 type: str
26 admin_state:
27 description: Admin state of QoS Policy
28 choices: ['disabled', 'enabled']
29 default: enabled
30 type: str
31 cos:
32 description: CoS setting. Choices are any or 0-6.
33 required: true
34 type: str
35 weight:
36 description: CoS profile weight. Choices are best-effort, none or 0-10.
37 required: true
38 type: str
39 mtu:
40 description: MTU size. Choices are fc, normal or 0-4294967295.
41 default: normal
42 type: str
43 multicast_optimize:
44 description: Set multicast optimization options
45 choices: ['false', 'no', 'true', 'yes']
46 default: 'no'
47 type: str
48 drop:
49 description: Set multicast optimization options
50 default: 'drop'
51 choices: ['drop', 'no-drop']
52 type: str
53 requirements: ['ucsmsdk']
54 author: "Brett Johnson (@sdbrett)"
55 '''
56
57 EXAMPLES = '''
58 - name:
59 cisco.ucs.ucs_system_qos:
60 priority: platinum
61 admin_state: enabled
62 multicast_optimize: no
63 cos: '5'
64 weight: '10'
65 mtu: '9216'
66 hostname: 192.168.99.100
67 username: admin
68 password: password
69 '''
70
71 from ansible.module_utils.basic import AnsibleModule
72 from ansible_collections.cisco.ucs.plugins.module_utils.ucs import UCSModule, ucs_argument_spec
73
74
75 # TODO Add ranges for cos, weight and mtu
76 def main():
77 argument_spec = ucs_argument_spec.copy()
78 argument_spec.update(
79 priority=dict(required=True, type='str', choices=["best-effort", "bronze", "fc", "gold", "platinum", "silver"]),
80 cos=dict(required=True, type='str'),
81 weight=dict(required=True, type='str'),
82 admin_state=dict(required=False, type='str', default='enabled', choices=['disabled', 'enabled']),
83 drop=dict(required=False, type='str', default='drop', choices=['drop', 'no-drop']),
84 mtu=dict(required=False, type='str', default='normal'),
85 multicast_optimize=dict(required=False, type='str', default='no', choices=['false', 'no', 'true', 'yes']),
86 )
87
88 module = AnsibleModule(
89 argument_spec,
90 supports_check_mode=True,
91 )
92 ucs = UCSModule(module)
93
94 err = False
95
96 changed = False
97 try:
98 dn = "fabric/lan/classes/class-" + module.params['priority']
99 mo = ucs.login_handle.query_dn(dn)
100 # check top-level mo props
101 if module.params['priority'] == 'best-effort':
102 kwargs = dict(weight=module.params['weight'])
103 kwargs['mtu'] = module.params['mtu']
104 kwargs['multicast_optimize'] = module.params['multicast_optimize']
105 if not mo.check_prop_match(**kwargs):
106 if not module.check_mode:
107 mo.weight = module.params['weight']
108 mo.mtu = module.params['mtu']
109 mo.multicast_optimize = module.params['multicast_optimize']
110 ucs.login_handle.add_mo(mo, True)
111 ucs.login_handle.commit()
112 changed = True
113 elif module.params['priority'] == 'fc':
114 kwargs = dict(weight=module.params['weight'])
115 kwargs['cos'] = module.params['cos']
116 if not mo.check_prop_match(**kwargs):
117 if not module.check_mode:
118 mo.weight = module.params['weight']
119 mo.cos = module.params['cos']
120 ucs.login_handle.add_mo(mo, True)
121 ucs.login_handle.commit()
122 changed = True
123
124 else:
125 kwargs = dict(weight=module.params['weight'])
126 kwargs['priority'] = module.params['priority']
127 kwargs['mtu'] = module.params['mtu']
128 kwargs['cos'] = module.params['cos']
129 kwargs['drop'] = module.params['drop']
130 kwargs['admin_state'] = module.params['admin_state']
131 kwargs['multicast_optimize'] = module.params['multicast_optimize']
132 if not mo.check_prop_match(**kwargs):
133 if not module.check_mode:
134 mo.weight = module.params['weight']
135 mo.mtu = module.params['mtu']
136 mo.cos = module.params['cos']
137 mo.drop = module.params['drop']
138 mo.admin_state = module.params['admin_state']
139 mo.multicast_optimize = module.params['multicast_optimize']
140
141 ucs.login_handle.add_mo(mo, True)
142 ucs.login_handle.commit()
143 changed = True
144
145 except Exception as e:
146 err = True
147 ucs.result['msg'] = "setup error: %s " % str(e)
148
149 ucs.result['changed'] = changed
150 if err:
151 module.fail_json(**ucs.result)
152 module.exit_json(**ucs.result)
153
154
155 if __name__ == '__main__':
156 main()