Initial commit
[ta/config-manager.git] / cmframework / src / cmframework / apis / cmansibleinventoryconfig.py
1 # Copyright 2019 Nokia
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain 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,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 from cmframework.apis import cmerror
15
16
17 class CMAnsibleInventoryConfigPlugin(object):
18
19     def __init__(self, confman, inventory, ownhost):
20         self.confman = confman
21         self.inventory = inventory
22         self.ownhost = ownhost
23
24     def add_host_var(self, host, name, value):
25         """add a host specific variable
26            Arguments:
27            host: The name of the host
28            name: The name of the variable.
29            value: The value
30         """
31         if host not in self.inventory['_meta']['hostvars']:
32             self.inventory['_meta']['hostvars'][host] = {}
33         self.inventory['_meta']['hostvars'][host][name] = value
34
35     def add_global_var(self, name, value):
36         """add a global variable to the inventory
37            Arguments:
38            name: The name of the variable
39            value: The value
40         """
41         self.inventory['all']['vars'][name] = value
42
43     def add_host_group(self, name, value):
44         self.inventory[name] = value
45
46     # pylint: disable=no-self-use
47     def handle_bootstrapping(self):
48         """provide inventory extensions
49
50            Raise:
51
52            CMError is raised in-case of failure
53         """
54
55         raise cmerror.CMError('No implemented')
56
57     # pylint: disable=no-self-use
58     def handle_provisioning(self):
59         """provide inventory extensions
60
61            Raise:
62
63            CMError is raised in-case of failure
64         """
65
66         raise cmerror.CMError('No implemented')
67
68     # pylint: disable=no-self-use
69     def handle_postconfig(self):
70         """provide inventory extensions
71
72            Raise:
73
74            CMError is raised in-case of failure
75         """
76
77         raise cmerror.CMError('No implemented')
78
79     # pylint: disable=no-self-use
80     def handle_setup(self):
81         """provide inventory extensions
82
83            Raise:
84
85            CMError is raised in-case of failure
86         """
87
88         raise cmerror.CMError('No implemented')