| Home | Trees | Indices | Help |
|---|
|
|
1 # Copyright 2014-2017 by Akira Yoshiyama <akirayoshiyama@gmail.com>.
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 """
17 Resource class and its manager for volume snapshots on Block Storage V2 API
18 """
19
20 from yakumo import base
21 from yakumo.constant import UNDEF
22 from yakumo import mapper
23
24
25 ATTRIBUTE_MAPPING = [
26 ('id', 'id', mapper.Noop),
27 ('name', 'name', mapper.Noop),
28 ('description', 'description', mapper.Noop),
29 ('size', 'size', mapper.Noop),
30 ('status', 'status', mapper.Noop),
31 ('force', 'force', mapper.Noop),
32 ('source', 'volume_id', mapper.Resource('cinder.volume')),
33 ('progress', 'os-extended-snapshot-attributes:progress', mapper.Noop),
34 ('project', 'os-extended-snapshot-attributes:project_id',
35 mapper.Resource('project')),
36 ('metadata', 'metadata', mapper.Noop),
37 ('created_at', 'created_at', mapper.DateTime),
38 ('updated_at', 'updated_at', mapper.DateTime),
39 ]
40
41
43 """resource class for volume snapshots on Block Storage V2 API"""
44
45 _stable_state = ['available', 'error', 'error_deleting']
46
48 """
49 Get metadata of a volume snapshot
50
51 @return: Metadata
52 @rtype: dict
53 """
54 ret = self._http.get(self._url_resource_path, self._id, 'metadata')
55 return ret.get('metadata')
56
58 """
59 Update metadata of a volume snapshot
60
61 @keyword metadata: key=value style.
62 @type metadata: dict
63 @rtype: None
64 """
65 self._http.post(self._url_resource_path, self._id, 'metadata',
66 data={'metadata': metadata})
67 self.reload()
68
70 """
71 Delete metadata of a volume snapshot
72
73 @param key: key of the metadata
74 @type keys: [str]
75 @rtype: None
76 """
77 for key in keys:
78 self._http.delete(self._url_resource_path, self._id,
79 'metadata', key)
80 self.reload()
81
82
84 """manager class for volume snapshots on Block Storage V2 API"""
85
86 resource_class = Resource
87 service_type = 'volume'
88 _attr_mapping = ATTRIBUTE_MAPPING
89 _json_resource_key = 'snapshot'
90 _json_resources_key = 'snapshots'
91 _hidden_methods = ["update"]
92 _url_resource_list_path = '/snapshots/detail'
93 _url_resource_path = '/snapshots'
94
97 """
98 Create a snapshot of a volume
99
100 @keyword name: Snapshot name
101 @type name: str
102 @keyword description: Description
103 @type description: str
104 @keyword metadata: Metadata
105 @type metadata: dict
106 @keyword source: Source volume
107 @type source: yakumo.cinder.v2.volume.Resource
108 @return: Created volume object
109 @rtype: yakumo.cinder.v2.snapshot.Resource
110 """
111 return super(Manager, self).create(name=name,
112 description=description,
113 metadata=metadata,
114 source=source,
115 force=force)
116
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Sat Mar 4 23:02:26 2017 | http://epydoc.sourceforge.net |