Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_thermal_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_thermal_policy
16 short_description: Thermal Policy configuration for Cisco Intersight
17 description:
18 - Manages Thermal Policy configuration on Cisco Intersight.
19 - A policy to configure the fan control mode on Cisco Intersight managed servers.
20 - For more information see L(Cisco Intersight,https://intersight.com/apidocs/thermal/Policy/get/).
21 extends_documentation_fragment: intersight
22 options:
23 state:
24 description:
25 - If C(present), will verify the resource is present and will create if needed.
26 - If C(absent), will verify the resource is absent and will delete if needed.
27 type: str
28 choices: [present, absent]
29 default: present
30 organization:
31 description:
32 - The name of the Organization this resource is assigned to.
33 - Profiles, Policies, and Pools that are created within a Custom Organization are applicable only to devices in the same Organization.
34 type: str
35 default: default
36 name:
37 description:
38 - The name assigned to the Thermal Policy.
39 - The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_.
40 type: str
41 required: true
42 description:
43 description:
44 - The user-defined description for the Thermal Policy.
45 - Description can contain letters(a-z, A-Z), numbers(0-9), hyphen(-), period(.), colon(:), or an underscore(_).
46 type: str
47 aliases: [descr]
48 tags:
49 description:
50 - List of tags in Key:<user-defined key> Value:<user-defined value> format.
51 type: list
52 elements: dict
53 fan_control_mode:
54 description:
55 - Sets the Fan Control Mode.
56 - High Power, Maximum Power and Acoustic modes are supported only on the Cisco UCS C-Series servers and on the X-Series Chassis.
57 type: str
58 choices: ['Balanced', 'LowPower', 'HighPower', 'MaximumPower', 'Acoustic']
59 default: 'Balanced'
60 author:
61 - Ron Gershburg (@rgershbu)
62 '''
63
64 EXAMPLES = r'''
65 - name: Create a Thermal Policy with High Power fan mode
66 cisco.intersight.intersight_thermal_policy:
67 api_private_key: "{{ api_private_key }}"
68 api_key_id: "{{ api_key_id }}"
69 organization: "default"
70 name: "HighPower-Thermal-Policy"
71 description: "High power thermal policy"
72 tags:
73 - Key: "Site"
74 Value: "DataCenter-A"
75 fan_control_mode: "HighPower"
76 state: present
77
78 - name: Create a Thermal Policy using the default Balanced fan mode
79 cisco.intersight.intersight_thermal_policy:
80 api_private_key: "{{ api_private_key }}"
81 api_key_id: "{{ api_key_id }}"
82 name: "Balanced-Power-Policy"
83 description: "A standard thermal policy for general use."
84 state: present
85
86 - name: Delete a Thermal Policy
87 cisco.intersight.intersight_thermal_policy:
88 api_private_key: "{{ api_private_key }}"
89 api_key_id: "{{ api_key_id }}"
90 name: "HighPower-Thermal-Policy"
91 state: absent
92 '''
93
94 RETURN = r'''
95 api_response:
96 description: The API response output returned by the specified resource.
97 returned: always
98 type: dict
99 sample:
100 "api_response": {
101 "Name": "test_thermal_policy",
102 "ObjectType": "thermal.Policy",
103 "FanControlMode": "LowPower",
104 "Tags": [
105 {
106 "Key": "Site",
107 "Value": "tag1"
108 },
109 {
110 "Key": "Site2",
111 "Value": "tag2"
112 }
113 ]
114 }
115 '''
116
117
118 from ansible.module_utils.basic import AnsibleModule
119 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
120
121
122 def main():
123 argument_spec = intersight_argument_spec.copy()
124 argument_spec.update(
125 state=dict(type='str', choices=['present', 'absent'], default='present'),
126 organization=dict(type='str', default='default'),
127 name=dict(type='str', required=True),
128 description=dict(type='str', aliases=['descr']),
129 tags=dict(type='list', elements='dict'),
130 fan_control_mode=dict(
131 type='str',
132 choices=['Balanced', 'LowPower', 'HighPower', 'MaximumPower', 'Acoustic'],
133 default='Balanced'
134 )
135 )
136 module = AnsibleModule(
137 argument_spec,
138 supports_check_mode=True,
139 )
140
141 intersight = IntersightModule(module)
142 intersight.result['api_response'] = {}
143 intersight.result['trace_id'] = ''
144
145 # Resource path used to configure policy
146 resource_path = '/thermal/Policies'
147 # Define API body used in compares or create
148 intersight.api_body = {
149 'Organization': {
150 'Name': intersight.module.params['organization'],
151 },
152 'Name': intersight.module.params['name'],
153 'FanControlMode': intersight.module.params['fan_control_mode']
154 }
155
156 intersight.set_tags_and_description()
157
158 intersight.configure_policy_or_profile(resource_path=resource_path)
159
160 module.exit_json(**intersight.result)
161
162
163 if __name__ == '__main__':
164 main()