| 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 images in Compute API v2
18 """
19
20 from yakumo import base
21 from yakumo import mapper
22 from yakumo import utils
23
24
25 ATTRIBUTE_MAPPING = [
26 ('id', 'id', mapper.Noop),
27 ('name', 'name', mapper.Noop),
28 ('size', 'OS-EXT-IMG-SIZE:size', mapper.Noop),
29 ('min_ram', 'minRam', mapper.Noop),
30 ('min_disk', 'minDisk', mapper.Noop),
31 ('metadata', 'metadata', mapper.Noop),
32 ('status', 'status', mapper.Noop),
33 ('created_at', 'created', mapper.Noop),
34 ('updated_at', 'updated', mapper.Noop),
35 ]
36
37
39 """Resource class for images in Compute API v2"""
40
42 """Get extra specs for a flavor
43
44 @return: Metadata
45 @rtype: dir
46 """
47 ret = self._http.get(self._url_resource_path, self._id, 'metadata')
48 return ret.get('metadata', {})
49
51 """
52 Create metadata for a image
53
54 @keyword metadata: Metadata with key=value
55 @type metadata: dict
56 @rtype: None
57 """
58 metadata = {k: str(v) for k, v in metadata.items()}
59 self._http.post(self._url_resource_path, self._id, 'metadata',
60 data=dict(metadata=metadata))
61 self.reload()
62
64 """
65 Delete one metadata from an image
66
67 @param keys: keys of metadata to remove
68 @type keys: [str]
69 @rtype: None
70 """
71 for key in keys:
72 self._http.delete(self._url_resource_path, self._id, 'metadata',
73 key)
74 self.reload()
75
76
78 """Manager class for images in Compute API v2"""
79
80 resource_class = Resource
81 service_type = 'compute'
82 _attr_mapping = ATTRIBUTE_MAPPING
83 _hidden_methods = ["create", "update"]
84 _json_resource_key = 'image'
85 _json_resources_key = 'images'
86 _url_resource_path = '/images'
87 _url_resource_list_path = '/images/detail'
88
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Sat Mar 4 23:02:26 2017 | http://epydoc.sourceforge.net |