Merge "Remove Compass from genesis."
[genesis.git] / opensteak / tools / opensteak / foreman_objects / itemOverrideValues.py
1 #!/usr/bin/python3
2 # -*- coding: utf-8 -*-
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14 #
15 # Authors:
16 # @author: David Blaisonneau <david.blaisonneau@orange.com>
17 # @author: Arnaud Morin <arnaud1.morin@orange.com>
18
19
20 from opensteak.foreman_objects.item import ForemanItem
21 from pprint import pprint as pp
22
23 class ItemOverrideValues(ForemanItem):
24     """
25     ItemOverrideValues class
26     Represent the content of a foreman smart class parameter as a dict
27     """
28
29     objName = 'override_values'
30     payloadObj = 'override_value'
31
32     def __init__(self, api, key, parentName, parentKey, *args, **kwargs):
33         """ Function __init__
34         Represent the content of a foreman object as a dict
35
36         @param api: The foreman api
37         @param key: The object Key
38         @param parentName: The object parent name (eg: smart_class_parameter)
39         @param parentKey: The object parent key
40         @param *args, **kwargs: the dict representation
41         @return RETURN: Itself
42         """
43         self.parentName = parentName
44         self.parentKey = parentKey
45         ForemanItem.__init__(self, api, key,
46                              self.objName, self.payloadObj,
47                              *args, **kwargs)
48
49     def __setitem__(self, key, attributes):
50         """ Function __setitem__
51         Set a parameter of a foreman object as a dict
52
53         @param key: The key to modify
54         @param attribute: The data
55         @return RETURN: The API result
56         """
57         payload = {self.payloadObj: {key: attributes}}
58         return self.api.set('{}/{}/{}'.format(self.parentName,
59                                               self.parentKey,
60                                               self.objName),
61                             self.key, payload)