Initial commit
[ta/config-manager.git] / cmframework / src / cmframework / utils / cmsnapshothandler.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 __future__ import print_function
15 import logging
16 import json
17
18 from cmframework.utils.cmstatehandler import CMStateHandler
19
20
21 class CMSnapshotHandler(CMStateHandler):
22     SNAPSHOTS_DOMAIN = 'cm.snapshots'
23
24     def get_data(self, snapshot_name):
25         logging.debug('get_data called for: %s', snapshot_name)
26
27         data_json = self.plugin.get(CMSnapshotHandler.SNAPSHOTS_DOMAIN, snapshot_name)
28
29         return json.loads(data_json)
30
31     def set_data(self, snapshot_name, data):
32         logging.debug('set_properties called for: %s with: %s', snapshot_name, data)
33
34         self.plugin.set(CMSnapshotHandler.SNAPSHOTS_DOMAIN, snapshot_name, json.dumps(data))
35
36     def snapshot_exists(self, snapshot_name):
37         logging.debug('snapshot_exists called for: %s', snapshot_name)
38
39         return self.plugin.get(CMSnapshotHandler.SNAPSHOTS_DOMAIN, snapshot_name) is not None
40
41     def list_snapshots(self):
42         logging.debug('list_snapshots called')
43
44         snapshots = self.plugin.get_domain(CMSnapshotHandler.SNAPSHOTS_DOMAIN)
45
46         return snapshots.keys()
47
48     def delete_snapshot(self, snapshot_name):
49         logging.debug('delete_snapshot called for: %s', snapshot_name)
50
51         self.plugin.delete(CMSnapshotHandler.SNAPSHOTS_DOMAIN, snapshot_name)