Debian Codegraph @

ansible_collections/theforeman/foreman/plugins/modules/compute_attribute.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # (c) 2019 Manisha Singhal (ATIX AG)
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 from __future__ import absolute_import, division, print_function
19 __metaclass__ = type
20
21
22 DOCUMENTATION = '''
23 ---
24 module: compute_attribute
25 version_added: 1.0.0
26 short_description: Manage Compute Attributes
27 description:
28 - "Manage Compute Attributes"
29 - "This beta version can create, and update compute attributes"
30 author:
31 - "Manisha Singhal (@Manisha15) ATIX AG"
32 options:
33 compute_resource:
34 description:
35 - Name of compute resource
36 required: true
37 type: str
38 compute_profile:
39 description:
40 - Name of compute profile
41 required: true
42 type: str
43 vm_attrs:
44 description:
45 - Hash containing the data of vm_attrs
46 required: false
47 aliases:
48 - vm_attributes
49 type: dict
50 extends_documentation_fragment:
51 - theforeman.foreman.foreman
52 - theforeman.foreman.foreman.entity_state
53 '''
54
55 EXAMPLES = '''
56 - name: "Create compute attribute"
57 theforeman.foreman.compute_attribute:
58 username: "admin"
59 password: "changeme"
60 server_url: "https://foreman.example.com"
61 compute_profile: "Test Compute Profile"
62 compute_resource: "Test Compute Resource"
63 vm_attrs:
64 memory_mb: '2048'
65 cpu: '2'
66 state: present
67
68 - name: "Update compute attribute"
69 theforeman.foreman.compute_attribute:
70 username: "admin"
71 password: "changeme"
72 server_url: "https://foreman.example.com"
73 compute_profile: "Test Compute Profile"
74 compute_resource: "Test Compute Resource"
75 vm_attrs:
76 memory_mb: '1024'
77 cpu: '1'
78 state: present
79 '''
80
81 RETURN = '''
82 entity:
83 description: Final state of the affected entities grouped by their type.
84 returned: success
85 type: dict
86 contains:
87 compute_attributes:
88 description: List of compute attributes.
89 type: list
90 elements: dict
91 contains:
92 id:
93 description: Database id of the compute_attribute.
94 type: int
95 compute_profile_id:
96 description: Database id of the associated compute profile.
97 type: int
98 compute_profile_name:
99 description: Name of the associated compute profile.
100 type: str
101 compute_resource_id:
102 description: Database id of the associated compute resource.
103 type: int
104 compute_resource_name:
105 description: Name of the associated compute resource.
106 type: str
107 created_at:
108 description: Creation date of the compute attribute.
109 type: str
110 updated_at:
111 description: Date of last change to the compute attribute.
112 type: str
113 name:
114 description: Generated friendly name for the compute attribute.
115 type: str
116 provider_friendly_name:
117 description: Name of the provider type of the compute resource.
118 type: str
119 attributes:
120 description: Effective attributes for the given combination of compute profile and resource.
121 type: dict
122 vm_attrs:
123 description: Configured attributes.
124 type: dict
125 '''
126
127 from ansible_collections.theforeman.foreman.plugins.module_utils.foreman_helper import ForemanEntityAnsibleModule
128
129
130 class ForemanComputeAttributeModule(ForemanEntityAnsibleModule):
131 pass
132
133
134 def main():
135 module = ForemanComputeAttributeModule(
136 foreman_spec=dict(
137 compute_profile=dict(required=True, type='entity'),
138 compute_resource=dict(required=True, type='entity', thin=False),
139 vm_attrs=dict(type='dict', aliases=['vm_attributes']),
140 ),
141 entity_opts=dict(resolve=False),
142 )
143
144 with module.api_connection():
145 compute_attributes = module.lookup_entity('compute_resource').get('compute_attributes')
146 compute_profile_id = module.lookup_entity('compute_profile').get('id')
147 entity = next((item for item in compute_attributes if item.get('compute_profile_id') == compute_profile_id), None)
148 module.set_entity('entity', entity)
149 module.run()
150
151
152 if __name__ == '__main__':
153 main()