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 __future__ import print_function
18 from cmframework.utils.cmstatehandler import CMStateHandler
21 class CMSnapshotHandler(CMStateHandler):
22 SNAPSHOTS_DOMAIN = 'cm.snapshots'
24 def get_data(self, snapshot_name):
25 logging.debug('get_data called for: %s', snapshot_name)
27 data_json = self.plugin.get(CMSnapshotHandler.SNAPSHOTS_DOMAIN, snapshot_name)
29 return json.loads(data_json)
31 def set_data(self, snapshot_name, data):
32 logging.debug('set_properties called for: %s with: %s', snapshot_name, data)
34 self.plugin.set(CMSnapshotHandler.SNAPSHOTS_DOMAIN, snapshot_name, json.dumps(data))
36 def snapshot_exists(self, snapshot_name):
37 logging.debug('snapshot_exists called for: %s', snapshot_name)
39 return self.plugin.get(CMSnapshotHandler.SNAPSHOTS_DOMAIN, snapshot_name) is not None
41 def list_snapshots(self):
42 logging.debug('list_snapshots called')
44 snapshots = self.plugin.get_domain(CMSnapshotHandler.SNAPSHOTS_DOMAIN)
46 return snapshots.keys()
48 def delete_snapshot(self, snapshot_name):
49 logging.debug('delete_snapshot called for: %s', snapshot_name)
51 self.plugin.delete(CMSnapshotHandler.SNAPSHOTS_DOMAIN, snapshot_name)