summaryrefslogtreecommitdiff
path: root/novaclient/v2/images.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/images.py')
-rw-r--r--novaclient/v2/images.py101
1 files changed, 101 insertions, 0 deletions
diff --git a/novaclient/v2/images.py b/novaclient/v2/images.py
new file mode 100644
index 0000000..2d413a6
--- /dev/null
+++ b/novaclient/v2/images.py
@@ -0,0 +1,101 @@
1# Copyright 2010 Jacob Kaplan-Moss
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15"""
16Image interface.
17"""
18
19from six.moves.urllib import parse
20
21from novaclient import base
22
23
24class Image(base.Resource):
25 """
26 An image is a collection of files used to create or rebuild a server.
27 """
28 HUMAN_ID = True
29
30 def __repr__(self):
31 return "<Image: %s>" % self.name
32
33 def delete(self):
34 """
35 Delete this image.
36 """
37 self.manager.delete(self)
38
39
40class ImageManager(base.ManagerWithFind):
41 """
42 Manage :class:`Image` resources.
43 """
44 resource_class = Image
45
46 def get(self, image):
47 """
48 Get an image.
49
50 :param image: The ID of the image to get.
51 :rtype: :class:`Image`
52 """
53 return self._get("/images/%s" % base.getid(image), "image")
54
55 def list(self, detailed=True, limit=None):
56 """
57 Get a list of all images.
58
59 :rtype: list of :class:`Image`
60 :param limit: maximum number of images to return.
61 """
62 params = {}
63 detail = ''
64 if detailed:
65 detail = '/detail'
66 if limit:
67 params['limit'] = int(limit)
68 query = '?%s' % parse.urlencode(params) if params else ''
69 return self._list('/images%s%s' % (detail, query), 'images')
70
71 def delete(self, image):
72 """
73 Delete an image.
74
75 It should go without saying that you can't delete an image
76 that you didn't create.
77
78 :param image: The :class:`Image` (or its ID) to delete.
79 """
80 self._delete("/images/%s" % base.getid(image))
81
82 def set_meta(self, image, metadata):
83 """
84 Set an images metadata
85
86 :param image: The :class:`Image` to add metadata to
87 :param metadata: A dict of metadata to add to the image
88 """
89 body = {'metadata': metadata}
90 return self._create("/images/%s/metadata" % base.getid(image),
91 body, "metadata")
92
93 def delete_meta(self, image, keys):
94 """
95 Delete metadata from an image
96
97 :param image: The :class:`Image` to delete metadata
98 :param keys: A list of metadata keys to delete from the image
99 """
100 for k in keys:
101 self._delete("/images/%s/metadata/%s" % (base.getid(image), k))