Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_memory_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_memory_policy
16 short_description: Memory policy configuration for Cisco Intersight
17 description:
18 - Memory policy configuration for Cisco Intersight.
19 - Used to configure memory blocklisting on Cisco Intersight managed devices.
20 - For more information see L(Cisco Intersight,https://intersight.com/apidocs).
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 and Policies 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 Memory policy.
39 - The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_.
40 type: str
41 required: true
42 tags:
43 description:
44 - List of tags in Key:<user-defined key> Value:<user-defined value> format.
45 type: list
46 elements: dict
47 description:
48 description:
49 - The user-defined description of the Memory policy.
50 - Description can contain letters(a-z, A-Z), numbers(0-9), hyphen(-), period(.), colon(:), or an underscore(_).
51 type: str
52 aliases: [descr]
53 enable_dimm_blocklisting:
54 description:
55 - Enable or disable DIMM blocklisting.
56 type: bool
57 default: false
58 author:
59 - Vincent Esposito (@vesposito)
60 '''
61
62 EXAMPLES = r'''
63 - name: Configure Memory Policy
64 cisco.intersight.intersight_memory_policy:
65 api_private_key: "{{ api_private_key }}"
66 api_key_id: "{{ api_key_id }}"
67 organization: DevNet
68 name: lab-memory
69 description: Memory policy for lab use
70 tags:
71 - Key: Site
72 Value: RCDN
73 enable_dimm_blocklisting: true
74
75 - name: Delete Memory Policy
76 cisco.intersight.intersight_memory_policy:
77 api_private_key: "{{ api_private_key }}"
78 api_key_id: "{{ api_key_id }}"
79 organization: DevNet
80 name: lab-memory
81 state: absent
82 '''
83
84 RETURN = r'''
85 api_response:
86 description: The API response output returned by the specified resource.
87 returned: always
88 type: dict
89 sample:
90 "api_response": {
91 "Name": "lab-memory",
92 "ObjectType": "memory.Policy",
93 "Tags": [
94 {
95 "Key": "Site",
96 "Value": "RCDN"
97 }
98 ]
99 }
100 '''
101
102
103 from ansible.module_utils.basic import AnsibleModule
104 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
105
106
107 def main():
108 argument_spec = intersight_argument_spec.copy()
109 argument_spec.update(
110 state=dict(type='str', choices=['present', 'absent'], default='present'),
111 organization=dict(type='str', default='default'),
112 name=dict(type='str', required=True),
113 description=dict(type='str', aliases=['descr']),
114 tags=dict(type='list', elements='dict'),
115 enable_dimm_blocklisting=dict(type='bool', default=False),
116 )
117
118 module = AnsibleModule(
119 argument_spec,
120 supports_check_mode=True,
121 )
122
123 intersight = IntersightModule(module)
124 intersight.result['api_response'] = {}
125 intersight.result['trace_id'] = ''
126
127 # Resource path used to configure policy
128 resource_path = '/memory/Policies'
129 # Define API body used in compares or create
130 intersight.api_body = {
131 'Organization': {
132 'Name': intersight.module.params['organization'],
133 },
134 'Name': intersight.module.params['name'],
135 'EnableDimmBlocklisting': intersight.module.params['enable_dimm_blocklisting']
136 }
137 if intersight.module.params['state'] == 'present':
138 intersight.set_tags_and_description()
139
140 intersight.configure_policy_or_profile(resource_path=resource_path)
141
142 module.exit_json(**intersight.result)
143
144
145 if __name__ == '__main__':
146 main()