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
7 # http://www.apache.org/licenses/LICENSE-2.0
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
17 class CMManage(cmclient.CMClient):
21 def __call__(self, msg):
24 logger = VerboseLogger()
26 client = CMManage(192.128.254.10, 51110, cmclient.CMClientImpl, logger)
28 value = client.create_snapshot('snapshot1')
29 except cmapis.cmerror.CMError as error:
30 print('Got exception %s' % str(error))
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
39 server_ip: The configuration management server ip address.
41 server_port: The configuration management server port number.
43 client_lib_impl_module: The module implementing the client library.
45 verbose_logger: The verbose logging callable. any callable which
46 takes a string as input argument can be used.
50 CMError exception in-case of a failure.
52 cmclient.CMClient.__init__(self, server_ip, server_port, client_impl_module, verbose_logger)
54 @cmclient.handle_exceptions
55 def create_snapshot(self, snapshot_name):
56 """initiate a create snapshot operation
58 This API is used to initiate a create snapshot operation for the configuration
63 snapshot_name: The name of the snapshot
67 CMError is raised in-case of a failure.
69 return self.client_lib.create_snapshot(snapshot_name)
71 @cmclient.handle_exceptions
72 def restore_snapshot(self, snapshot_name):
73 """initiate a snapshot restore operation
75 This API is used to initiate a snapshot restore operation for the
80 snapshot_name: The name of the snapshot.
84 CMError is raised in-case of a failure.
86 return self.client_lib.restore_snapshot(snapshot_name)
88 @cmclient.handle_exceptions
89 def delete_snapshot(self, snapshot_name):
90 """initiate a snapshot delete operation
92 This API is used to initiate a snapshot delete operation for the
97 snapshot_name: The name of the snapshot.
101 CMError is raised in-case of a failure.
103 return self.client_lib.delete_snapshot(snapshot_name)
105 @cmclient.handle_exceptions
106 def list_snapshots(self):
107 """initiate a list snapshots operation
109 This API is used to initiate a list snapshots operation for the
116 CMError is raised in-case of a failure.
118 return self.client_lib.list_snapshots()
120 @cmclient.handle_exceptions
121 def activate(self, node_name):
122 """activate configuration in all or one specific node
124 This API is used to initiate full activation for all or one specific node
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.
134 CMError is raised in-case of failure.
136 return self.client_lib.activate(node_name)
138 @cmclient.handle_exceptions
139 def activate_node(self, node_name):
140 """for cmagent to activate configuration in specified node
142 This API is used only by cmagent to initiate full activation for a node
146 node_name: a string containing the name of the node to be activated.
150 CMError is raised in-case of failure.
152 return self.client_lib.activate_node(node_name)
154 @cmclient.handle_exceptions
155 def reboot_node(self, node_name):
156 """request reboot of specified node
158 This API is used to initiate node reboot during full activation of a node
162 node_name: a string containing the name of the node to be rebooted
166 CMError is raised in-case of failure.
168 return self.client_lib.reboot_node(node_name)
170 @cmclient.handle_exceptions
171 def disable_automatic_activation(self):
172 """disable automatic activation
174 This API is used to disable automatic activation
180 CMError is raised in-case of failure.
182 return self.client_lib.disable_automatic_activation()
184 @cmclient.handle_exceptions
185 def enable_automatic_activation(self):
186 """enable automatic activation
188 This API is used to enable automatic activation
194 CMError is raised in-case of failure.
196 return self.client_lib.enable_automatic_activation()