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