summaryrefslogtreecommitdiff
path: root/novaclient/v2/volume_snapshots.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/volume_snapshots.py')
-rw-r--r--novaclient/v2/volume_snapshots.py90
1 files changed, 90 insertions, 0 deletions
diff --git a/novaclient/v2/volume_snapshots.py b/novaclient/v2/volume_snapshots.py
new file mode 100644
index 0000000..d3bc918
--- /dev/null
+++ b/novaclient/v2/volume_snapshots.py
@@ -0,0 +1,90 @@
1# Copyright 2011 Denali Systems, Inc.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16"""
17Volume snapshot interface (1.1 extension).
18"""
19
20from novaclient import base
21
22
23class Snapshot(base.Resource):
24 """
25 A Snapshot is a point-in-time snapshot of an openstack volume.
26 """
27 NAME_ATTR = 'display_name'
28
29 def __repr__(self):
30 return "<Snapshot: %s>" % self.id
31
32 def delete(self):
33 """
34 Delete this snapshot.
35 """
36 self.manager.delete(self)
37
38
39class SnapshotManager(base.ManagerWithFind):
40 """
41 Manage :class:`Snapshot` resources.
42 """
43 resource_class = Snapshot
44
45 def create(self, volume_id, force=False, display_name=None,
46 display_description=None):
47
48 """
49 Create a snapshot of the given volume.
50
51 :param volume_id: The ID of the volume to snapshot.
52 :param force: If force is True, create a snapshot even if the volume is
53 attached to an instance. Default is False.
54 :param display_name: Name of the snapshot
55 :param display_description: Description of the snapshot
56 :rtype: :class:`Snapshot`
57 """
58 body = {'snapshot': {'volume_id': volume_id,
59 'force': force,
60 'display_name': display_name,
61 'display_description': display_description}}
62 return self._create('/snapshots', body, 'snapshot')
63
64 def get(self, snapshot_id):
65 """
66 Get a snapshot.
67
68 :param snapshot_id: The ID of the snapshot to get.
69 :rtype: :class:`Snapshot`
70 """
71 return self._get("/snapshots/%s" % snapshot_id, "snapshot")
72
73 def list(self, detailed=True):
74 """
75 Get a list of all snapshots.
76
77 :rtype: list of :class:`Snapshot`
78 """
79 if detailed is True:
80 return self._list("/snapshots/detail", "snapshots")
81 else:
82 return self._list("/snapshots", "snapshots")
83
84 def delete(self, snapshot):
85 """
86 Delete a snapshot.
87
88 :param snapshot: The :class:`Snapshot` to delete.
89 """
90 self._delete("/snapshots/%s" % base.getid(snapshot))