Initial commit
[ta/config-manager.git] / cmframework / src / cmframework / apis / cmmanage.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 cmclient
15
16
17 class CMManage(cmclient.CMClient):
18     """
19         Usage Example:
20             class VerboseLogger:
21                 def __call__(self, msg):
22                     print(msg)
23
24             logger = VerboseLogger()
25
26             client = CMManage(192.128.254.10, 51110, cmclient.CMClientImpl, logger)
27             try:
28                 value = client.create_snapshot('snapshot1')
29             except cmapis.cmerror.CMError as error:
30                 print('Got exception %s' % str(error))
31     """
32
33     def __init__(self, server_ip='config-manager', server_port=61100,
34                  client_impl_module='cmframework.lib.CMClientImpl', verbose_logger=None):
35         """ initialize the client interface
36
37             Arguments:
38
39             server_ip:  The configuration management server ip address.
40
41             server_port: The configuration management server port number.
42
43             client_lib_impl_module: The module implementing the client library.
44
45             verbose_logger: The verbose logging callable. any callable which
46                             takes a string as input argument can be used.
47
48             Raise:
49
50             CMError exception in-case of a failure.
51         """
52         cmclient.CMClient.__init__(self, server_ip, server_port, client_impl_module, verbose_logger)
53
54     @cmclient.handle_exceptions
55     def create_snapshot(self, snapshot_name):
56         """initiate a create snapshot operation
57
58            This API is used to initiate a create snapshot operation for the configuration
59            data.
60
61            Arguments:
62
63            snapshot_name: The name of the snapshot
64
65            Raise:
66
67            CMError is raised in-case of a failure.
68         """
69         return self.client_lib.create_snapshot(snapshot_name)
70
71     @cmclient.handle_exceptions
72     def restore_snapshot(self, snapshot_name):
73         """initiate a snapshot restore operation
74
75            This API is used to initiate a snapshot restore operation for the
76            configuration data.
77
78            Arguments:
79
80            snapshot_name: The name of the snapshot.
81
82            Raise:
83
84            CMError is raised in-case of a failure.
85         """
86         return self.client_lib.restore_snapshot(snapshot_name)
87
88     @cmclient.handle_exceptions
89     def delete_snapshot(self, snapshot_name):
90         """initiate a snapshot delete operation
91
92            This API is used to initiate a snapshot delete operation for the
93            configuration data.
94
95            Arguments:
96
97            snapshot_name: The name of the snapshot.
98
99            Raise:
100
101            CMError is raised in-case of a failure.
102         """
103         return self.client_lib.delete_snapshot(snapshot_name)
104
105     @cmclient.handle_exceptions
106     def list_snapshots(self):
107         """initiate a list snapshots operation
108
109            This API is used to initiate a list snapshots operation for the
110            configuration data.
111
112            Arguments:
113
114            Raise:
115
116            CMError is raised in-case of a failure.
117         """
118         return self.client_lib.list_snapshots()
119
120     @cmclient.handle_exceptions
121     def activate(self, node_name):
122         """activate configuration in all or one specific node
123
124            This API is used to initiate full activation for all or one specific node
125
126            Arguments:
127
128            node_name: a string containing the node name where
129                       the configuration is to be activated. If not specified, then activation
130                       is done for all nodes.
131
132            Raise:
133
134            CMError is raised in-case of failure.
135         """
136         return self.client_lib.activate(node_name)
137
138     @cmclient.handle_exceptions
139     def activate_node(self, node_name):
140         """for cmagent to activate configuration in specified node
141
142            This API is used only by cmagent to initiate full activation for a node
143
144            Arguments:
145
146            node_name: a string containing the name of the node to be activated.
147
148            Raise:
149
150            CMError is raised in-case of failure.
151         """
152         return self.client_lib.activate_node(node_name)
153
154     @cmclient.handle_exceptions
155     def reboot_node(self, node_name):
156         """request reboot of specified node
157
158            This API is used to initiate node reboot during full activation of a node
159
160            Arguments:
161
162            node_name: a string containing the name of the node to be rebooted
163
164            Raise:
165
166            CMError is raised in-case of failure.
167         """
168         return self.client_lib.reboot_node(node_name)
169
170     @cmclient.handle_exceptions
171     def disable_automatic_activation(self):
172         """disable automatic activation
173
174            This API is used to disable automatic activation
175
176            Arguments:
177
178            Raise:
179
180            CMError is raised in-case of failure.
181         """
182         return self.client_lib.disable_automatic_activation()
183
184     @cmclient.handle_exceptions
185     def enable_automatic_activation(self):
186         """enable automatic activation
187
188            This API is used to enable automatic activation
189
190            Arguments:
191
192            Raise:
193
194            CMError is raised in-case of failure.
195         """
196         return self.client_lib.enable_automatic_activation()