root / kamaki / clients / compute / rest_api.py @ c6ebe715
History | View | Annotate | Download (14.3 kB)
1 | e3f01d64 | Stavros Sachtouris | # Copyright 2012-2013 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | 2bfb3db3 | Stavros Sachtouris | #
|
3 | 2bfb3db3 | Stavros Sachtouris | # Redistribution and use in source and binary forms, with or
|
4 | 2bfb3db3 | Stavros Sachtouris | # without modification, are permitted provided that the following
|
5 | 2bfb3db3 | Stavros Sachtouris | # conditions are met:
|
6 | 2bfb3db3 | Stavros Sachtouris | #
|
7 | 2bfb3db3 | Stavros Sachtouris | # 1. Redistributions of source code must retain the above
|
8 | 2bfb3db3 | Stavros Sachtouris | # copyright notice, this list of conditions and the following
|
9 | 2bfb3db3 | Stavros Sachtouris | # disclaimer.
|
10 | 2bfb3db3 | Stavros Sachtouris | #
|
11 | 2bfb3db3 | Stavros Sachtouris | # 2. Redistributions in binary form must reproduce the above
|
12 | 2bfb3db3 | Stavros Sachtouris | # copyright notice, this list of conditions and the following
|
13 | 2bfb3db3 | Stavros Sachtouris | # disclaimer in the documentation and/or other materials
|
14 | 2bfb3db3 | Stavros Sachtouris | # provided with the distribution.
|
15 | 2bfb3db3 | Stavros Sachtouris | #
|
16 | 2bfb3db3 | Stavros Sachtouris | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | 2bfb3db3 | Stavros Sachtouris | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | 2bfb3db3 | Stavros Sachtouris | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | 2bfb3db3 | Stavros Sachtouris | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | 2bfb3db3 | Stavros Sachtouris | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | 2bfb3db3 | Stavros Sachtouris | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | 2bfb3db3 | Stavros Sachtouris | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | 2bfb3db3 | Stavros Sachtouris | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | 2bfb3db3 | Stavros Sachtouris | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | 2bfb3db3 | Stavros Sachtouris | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | 2bfb3db3 | Stavros Sachtouris | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | 2bfb3db3 | Stavros Sachtouris | # POSSIBILITY OF SUCH DAMAGE.
|
28 | 2bfb3db3 | Stavros Sachtouris | #
|
29 | 2bfb3db3 | Stavros Sachtouris | # The views and conclusions contained in the software and
|
30 | 2bfb3db3 | Stavros Sachtouris | # documentation are those of the authors and should not be
|
31 | 2bfb3db3 | Stavros Sachtouris | # interpreted as representing official policies, either expressed
|
32 | 2bfb3db3 | Stavros Sachtouris | # or implied, of GRNET S.A.
|
33 | 2bfb3db3 | Stavros Sachtouris | |
34 | 2bfb3db3 | Stavros Sachtouris | from kamaki.clients import Client |
35 | 2bfb3db3 | Stavros Sachtouris | from kamaki.clients.utils import path4url |
36 | 2bfb3db3 | Stavros Sachtouris | import json |
37 | 2bfb3db3 | Stavros Sachtouris | |
38 | 2bfb3db3 | Stavros Sachtouris | |
39 | 55faa0bc | Stavros Sachtouris | class ComputeRestClient(Client): |
40 | 2bfb3db3 | Stavros Sachtouris | |
41 | fda88be1 | Stavros Sachtouris | # NON-cyclades
|
42 | fda88be1 | Stavros Sachtouris | def limits_get(self, success=200, **kwargs): |
43 | fda88be1 | Stavros Sachtouris | """GET base_url/limits
|
44 | fda88be1 | Stavros Sachtouris |
|
45 | fda88be1 | Stavros Sachtouris | :param success: success code or list or tupple of accepted success
|
46 | fda88be1 | Stavros Sachtouris | codes. if server response code is not in this list, a ClientError
|
47 | fda88be1 | Stavros Sachtouris | raises
|
48 | fda88be1 | Stavros Sachtouris |
|
49 | fda88be1 | Stavros Sachtouris | :returns: request response
|
50 | fda88be1 | Stavros Sachtouris | """
|
51 | fda88be1 | Stavros Sachtouris | path = path4url('limits')
|
52 | fda88be1 | Stavros Sachtouris | return self.get(path, success=success, **kwargs) |
53 | fda88be1 | Stavros Sachtouris | |
54 | fda88be1 | Stavros Sachtouris | def servers_get( |
55 | fda88be1 | Stavros Sachtouris | self,
|
56 | fda88be1 | Stavros Sachtouris | server_id='', detail=False, |
57 | fda88be1 | Stavros Sachtouris | changes_since=None,
|
58 | fda88be1 | Stavros Sachtouris | image=None,
|
59 | fda88be1 | Stavros Sachtouris | flavor=None,
|
60 | fda88be1 | Stavros Sachtouris | name=None,
|
61 | fda88be1 | Stavros Sachtouris | marker=None,
|
62 | fda88be1 | Stavros Sachtouris | limit=None,
|
63 | fda88be1 | Stavros Sachtouris | status=None,
|
64 | fda88be1 | Stavros Sachtouris | host=None,
|
65 | fda88be1 | Stavros Sachtouris | success=200,
|
66 | fda88be1 | Stavros Sachtouris | **kwargs): |
67 | cedde35d | Stavros Sachtouris | """GET base_url/servers/['detail' | <server_id>]
|
68 | fda88be1 | Stavros Sachtouris |
|
69 | fda88be1 | Stavros Sachtouris | :param server_id: (int or int str) ignored if detail
|
70 | fda88be1 | Stavros Sachtouris |
|
71 | fda88be1 | Stavros Sachtouris | :param detail: (boolean)
|
72 | fda88be1 | Stavros Sachtouris |
|
73 | fda88be1 | Stavros Sachtouris | :param changes-since: A time/date stamp for when the server last
|
74 | fda88be1 | Stavros Sachtouris | changed status
|
75 | fda88be1 | Stavros Sachtouris |
|
76 | fda88be1 | Stavros Sachtouris | :param image: Name of the image in URL format
|
77 | fda88be1 | Stavros Sachtouris |
|
78 | fda88be1 | Stavros Sachtouris | :param flavor: Name of the flavor in URL format
|
79 | fda88be1 | Stavros Sachtouris |
|
80 | fda88be1 | Stavros Sachtouris | :param name: Name of the server as a string
|
81 | fda88be1 | Stavros Sachtouris |
|
82 | fda88be1 | Stavros Sachtouris | :param marker: UUID of the server at which you want to set a marker
|
83 | fda88be1 | Stavros Sachtouris |
|
84 | fda88be1 | Stavros Sachtouris | :param limit: (int) limit of values to return
|
85 | fda88be1 | Stavros Sachtouris |
|
86 | fda88be1 | Stavros Sachtouris | :param status: Status of the server (e.g. filter on "ACTIVE")
|
87 | fda88be1 | Stavros Sachtouris |
|
88 | fda88be1 | Stavros Sachtouris | :param host: Name of the host as a string
|
89 | fda88be1 | Stavros Sachtouris |
|
90 | fda88be1 | Stavros Sachtouris | :returns: request response
|
91 | fda88be1 | Stavros Sachtouris | """
|
92 | fda88be1 | Stavros Sachtouris | if not server_id: |
93 | fda88be1 | Stavros Sachtouris | self.set_param('changes-since', changes_since, iff=changes_since) |
94 | fda88be1 | Stavros Sachtouris | self.set_param('image', image, iff=image) |
95 | fda88be1 | Stavros Sachtouris | self.set_param('flavor', flavor, iff=flavor) |
96 | fda88be1 | Stavros Sachtouris | self.set_param('name', name, iff=name) |
97 | fda88be1 | Stavros Sachtouris | self.set_param('marker', marker, iff=marker) |
98 | fda88be1 | Stavros Sachtouris | self.set_param('limit', limit, iff=limit) |
99 | fda88be1 | Stavros Sachtouris | self.set_param('status', status, iff=status) |
100 | fda88be1 | Stavros Sachtouris | self.set_param('host', host, iff=host) |
101 | fda88be1 | Stavros Sachtouris | |
102 | e51c7d5b | Stavros Sachtouris | path = path4url('servers', 'detail' if detail else (server_id or '')) |
103 | fda88be1 | Stavros Sachtouris | return self.get(path, success=success, **kwargs) |
104 | fda88be1 | Stavros Sachtouris | |
105 | fda88be1 | Stavros Sachtouris | def servers_post( |
106 | fda88be1 | Stavros Sachtouris | self,
|
107 | fda88be1 | Stavros Sachtouris | security_group=None,
|
108 | fda88be1 | Stavros Sachtouris | user_data=None,
|
109 | fda88be1 | Stavros Sachtouris | availability_zone=None,
|
110 | fda88be1 | Stavros Sachtouris | json_data=None,
|
111 | fda88be1 | Stavros Sachtouris | success=202,
|
112 | fda88be1 | Stavros Sachtouris | **kwargs): |
113 | fda88be1 | Stavros Sachtouris | """POST base_url/servers
|
114 | fda88be1 | Stavros Sachtouris |
|
115 | fda88be1 | Stavros Sachtouris | :param json_data: a json-formated dict that will be send as data
|
116 | fda88be1 | Stavros Sachtouris |
|
117 | fda88be1 | Stavros Sachtouris | :param security_group: (str)
|
118 | fda88be1 | Stavros Sachtouris |
|
119 | fda88be1 | Stavros Sachtouris | :param user_data: Use to pass configuration information or scripts upon
|
120 | fda88be1 | Stavros Sachtouris | launch. Must be Base64 encoded.
|
121 | fda88be1 | Stavros Sachtouris |
|
122 | fda88be1 | Stavros Sachtouris | :param availability_zone: (str)
|
123 | fda88be1 | Stavros Sachtouris |
|
124 | fda88be1 | Stavros Sachtouris | :returns: request response
|
125 | fda88be1 | Stavros Sachtouris | """
|
126 | fda88be1 | Stavros Sachtouris | |
127 | 4a88f05b | Stavros Sachtouris | self.set_param('security_group', security_group, iff=security_group) |
128 | 4a88f05b | Stavros Sachtouris | self.set_param('user_data', user_data, iff=user_data) |
129 | fda88be1 | Stavros Sachtouris | self.set_param(
|
130 | 4a88f05b | Stavros Sachtouris | 'availability_zone', availability_zone, iff=availability_zone)
|
131 | fda88be1 | Stavros Sachtouris | |
132 | fda88be1 | Stavros Sachtouris | if json_data:
|
133 | fda88be1 | Stavros Sachtouris | json_data = json.dumps(json_data) |
134 | fda88be1 | Stavros Sachtouris | self.set_header('Content-Type', 'application/json') |
135 | fda88be1 | Stavros Sachtouris | self.set_header('Content-Length', len(json_data)) |
136 | fda88be1 | Stavros Sachtouris | |
137 | fda88be1 | Stavros Sachtouris | path = path4url('servers')
|
138 | fda88be1 | Stavros Sachtouris | return self.post(path, data=json_data, success=success, **kwargs) |
139 | fda88be1 | Stavros Sachtouris | |
140 | 65a8b1da | Stavros Sachtouris | def servers_put( |
141 | 65a8b1da | Stavros Sachtouris | self,
|
142 | 65a8b1da | Stavros Sachtouris | server_id, server_name=None, json_data=None, success=204, |
143 | 65a8b1da | Stavros Sachtouris | **kwargs): |
144 | fda88be1 | Stavros Sachtouris | """PUT base_url/servers/<server_id>
|
145 | fda88be1 | Stavros Sachtouris |
|
146 | fda88be1 | Stavros Sachtouris | :param json_data: a json-formated dict that will be send as data
|
147 | fda88be1 | Stavros Sachtouris |
|
148 | fda88be1 | Stavros Sachtouris | :param success: success code (iterable of) codes
|
149 | fda88be1 | Stavros Sachtouris |
|
150 | fda88be1 | Stavros Sachtouris | :raises ClientError: if returned code not in success list
|
151 | fda88be1 | Stavros Sachtouris |
|
152 | fda88be1 | Stavros Sachtouris | :returns: request response
|
153 | fda88be1 | Stavros Sachtouris | """
|
154 | 65a8b1da | Stavros Sachtouris | self.set_param('server', server_name, iff=server_name) |
155 | 65a8b1da | Stavros Sachtouris | |
156 | fda88be1 | Stavros Sachtouris | if json_data:
|
157 | fda88be1 | Stavros Sachtouris | json_data = json.dumps(json_data) |
158 | fda88be1 | Stavros Sachtouris | self.set_header('Content-Type', 'application/json') |
159 | fda88be1 | Stavros Sachtouris | self.set_header('Content-Length', len(json_data)) |
160 | fda88be1 | Stavros Sachtouris | path = path4url('servers', server_id)
|
161 | fda88be1 | Stavros Sachtouris | return self.put(path, data=json_data, success=success, **kwargs) |
162 | fda88be1 | Stavros Sachtouris | |
163 | fda88be1 | Stavros Sachtouris | def servers_delete(self, server_id, success=204, **kwargs): |
164 | fda88be1 | Stavros Sachtouris | """DEL ETE base_url/servers/<server_id>
|
165 | fda88be1 | Stavros Sachtouris |
|
166 | fda88be1 | Stavros Sachtouris | :param json_data: a json-formated dict that will be send as data
|
167 | fda88be1 | Stavros Sachtouris |
|
168 | fda88be1 | Stavros Sachtouris | :param success: success code (iterable of) codes
|
169 | fda88be1 | Stavros Sachtouris |
|
170 | fda88be1 | Stavros Sachtouris | :raises ClientError: if returned code not in success list
|
171 | fda88be1 | Stavros Sachtouris |
|
172 | fda88be1 | Stavros Sachtouris | :returns: request response
|
173 | fda88be1 | Stavros Sachtouris | """
|
174 | fda88be1 | Stavros Sachtouris | path = path4url('servers', server_id)
|
175 | fda88be1 | Stavros Sachtouris | return self.delete(path, success=success, **kwargs) |
176 | fda88be1 | Stavros Sachtouris | |
177 | 65a8b1da | Stavros Sachtouris | def servers_metadata_get(self, server_id, key=None, success=200, **kwargs): |
178 | 65a8b1da | Stavros Sachtouris | """GET base_url/servers/<server_id>/metadata[/key]
|
179 | 65a8b1da | Stavros Sachtouris |
|
180 | 65a8b1da | Stavros Sachtouris | :returns: request response
|
181 | 65a8b1da | Stavros Sachtouris | """
|
182 | 65a8b1da | Stavros Sachtouris | path = path4url('servers', server_id, 'metadata', key or '') |
183 | 65a8b1da | Stavros Sachtouris | return self.get(path, success=success, **kwargs) |
184 | 65a8b1da | Stavros Sachtouris | |
185 | 65a8b1da | Stavros Sachtouris | def servers_metadata_post( |
186 | 65a8b1da | Stavros Sachtouris | self, server_id, json_data=None, success=202, **kwargs): |
187 | 65a8b1da | Stavros Sachtouris | """POST base_url/servers/<server_id>/metadata
|
188 | 65a8b1da | Stavros Sachtouris |
|
189 | 65a8b1da | Stavros Sachtouris | :returns: request response
|
190 | 65a8b1da | Stavros Sachtouris | """
|
191 | 65a8b1da | Stavros Sachtouris | if json_data:
|
192 | 65a8b1da | Stavros Sachtouris | json_data = json.dumps(json_data) |
193 | 65a8b1da | Stavros Sachtouris | self.set_header('Content-Type', 'application/json') |
194 | 65a8b1da | Stavros Sachtouris | self.set_header('Content-Length', len(json_data)) |
195 | 65a8b1da | Stavros Sachtouris | path = path4url('servers', server_id, 'metadata') |
196 | 65a8b1da | Stavros Sachtouris | return self.post(path, data=json_data, success=success, **kwargs) |
197 | 65a8b1da | Stavros Sachtouris | |
198 | 65a8b1da | Stavros Sachtouris | def servers_metadata_put( |
199 | 65a8b1da | Stavros Sachtouris | self, server_id, key=None, json_data=None, success=204, **kwargs): |
200 | 65a8b1da | Stavros Sachtouris | """PUT base_url/servers/<server_id>/metadata[/key]
|
201 | 65a8b1da | Stavros Sachtouris |
|
202 | 65a8b1da | Stavros Sachtouris | :returns: request response
|
203 | 65a8b1da | Stavros Sachtouris | """
|
204 | 65a8b1da | Stavros Sachtouris | if json_data:
|
205 | 65a8b1da | Stavros Sachtouris | json_data = json.dumps(json_data) |
206 | 65a8b1da | Stavros Sachtouris | self.set_header('Content-Type', 'application/json') |
207 | 65a8b1da | Stavros Sachtouris | self.set_header('Content-Length', len(json_data)) |
208 | 65a8b1da | Stavros Sachtouris | path = path4url('servers', server_id, 'metadata', key or '') |
209 | 65a8b1da | Stavros Sachtouris | return self.put(path, data=json_data, success=success, **kwargs) |
210 | 65a8b1da | Stavros Sachtouris | |
211 | 65a8b1da | Stavros Sachtouris | def servers_metadata_delete(self, server_id, key, success=204, **kwargs): |
212 | 65a8b1da | Stavros Sachtouris | """DEL ETE base_url/servers/<server_id>/metadata[/key]
|
213 | 65a8b1da | Stavros Sachtouris |
|
214 | 65a8b1da | Stavros Sachtouris | :returns: request response
|
215 | 65a8b1da | Stavros Sachtouris | """
|
216 | 65a8b1da | Stavros Sachtouris | path = path4url('servers', server_id, 'metadata', key) |
217 | 65a8b1da | Stavros Sachtouris | return self.delete(path, success=success, **kwargs) |
218 | 65a8b1da | Stavros Sachtouris | |
219 | 4a88f05b | Stavros Sachtouris | def servers_action_post( |
220 | ef2e6c9f | Stavros Sachtouris | self, server_id, json_data=None, success=202, **kwargs): |
221 | ef2e6c9f | Stavros Sachtouris | """POST base_url/servers/<server_id>/action
|
222 | ef2e6c9f | Stavros Sachtouris |
|
223 | ef2e6c9f | Stavros Sachtouris | :returns: request response
|
224 | ef2e6c9f | Stavros Sachtouris | """
|
225 | ef2e6c9f | Stavros Sachtouris | if json_data:
|
226 | ef2e6c9f | Stavros Sachtouris | json_data = json.dumps(json_data) |
227 | ef2e6c9f | Stavros Sachtouris | self.set_header('Content-Type', 'application/json') |
228 | ef2e6c9f | Stavros Sachtouris | self.set_header('Content-Length', len(json_data)) |
229 | ef2e6c9f | Stavros Sachtouris | path = path4url('servers', server_id, 'action') |
230 | ef2e6c9f | Stavros Sachtouris | return self.post(path, data=json_data, success=success, **kwargs) |
231 | ef2e6c9f | Stavros Sachtouris | |
232 | e51c7d5b | Stavros Sachtouris | def servers_ips_get( |
233 | e51c7d5b | Stavros Sachtouris | self, server_id,
|
234 | e51c7d5b | Stavros Sachtouris | network_id=None, changes_since=None, success=(304, 200), |
235 | e51c7d5b | Stavros Sachtouris | **kwargs): |
236 | e51c7d5b | Stavros Sachtouris | """GET base_url/servers/<server_id>/ips[/network_id]
|
237 | 2bfb3db3 | Stavros Sachtouris |
|
238 | e51c7d5b | Stavros Sachtouris | :param changes_since: time/date stamp in UNIX/epoch time. Checks for
|
239 | e51c7d5b | Stavros Sachtouris | changes since a previous request.
|
240 | 2bfb3db3 | Stavros Sachtouris |
|
241 | 2bfb3db3 | Stavros Sachtouris | :returns: request response
|
242 | e51c7d5b | Stavros Sachtouris | """
|
243 | e51c7d5b | Stavros Sachtouris | self.set_param('changes-since', changes_since, iff=changes_since) |
244 | e51c7d5b | Stavros Sachtouris | path = path4url('servers', server_id, 'ips', network_id or '') |
245 | e51c7d5b | Stavros Sachtouris | return self.get(path, success=success, **kwargs) |
246 | 2bfb3db3 | Stavros Sachtouris | |
247 | e51c7d5b | Stavros Sachtouris | def images_get( |
248 | 2bfb3db3 | Stavros Sachtouris | self,
|
249 | e51c7d5b | Stavros Sachtouris | image_id='',
|
250 | e51c7d5b | Stavros Sachtouris | detail=False,
|
251 | e51c7d5b | Stavros Sachtouris | changes_since=None,
|
252 | e51c7d5b | Stavros Sachtouris | server_name=None,
|
253 | e51c7d5b | Stavros Sachtouris | name=None,
|
254 | e51c7d5b | Stavros Sachtouris | status=None,
|
255 | e51c7d5b | Stavros Sachtouris | marker=None,
|
256 | e51c7d5b | Stavros Sachtouris | limit=None,
|
257 | e51c7d5b | Stavros Sachtouris | type=None,
|
258 | e51c7d5b | Stavros Sachtouris | success=200,
|
259 | 2bfb3db3 | Stavros Sachtouris | **kwargs): |
260 | e51c7d5b | Stavros Sachtouris | """GET base_url[/image_id][/command]
|
261 | 2bfb3db3 | Stavros Sachtouris |
|
262 | e51c7d5b | Stavros Sachtouris | :param image_id: (str) ignored if detail
|
263 | 2bfb3db3 | Stavros Sachtouris |
|
264 | e51c7d5b | Stavros Sachtouris | :param detail: (bool)
|
265 | 2bfb3db3 | Stavros Sachtouris |
|
266 | e51c7d5b | Stavros Sachtouris | --- Parameters ---
|
267 | e51c7d5b | Stavros Sachtouris | :param changes_since: when the image last changed status
|
268 | 2bfb3db3 | Stavros Sachtouris |
|
269 | e51c7d5b | Stavros Sachtouris | :param server_name: Name of the server in URL format
|
270 | 2bfb3db3 | Stavros Sachtouris |
|
271 | e51c7d5b | Stavros Sachtouris | :param name: Name of the image
|
272 | 2bfb3db3 | Stavros Sachtouris |
|
273 | e51c7d5b | Stavros Sachtouris | :param status: Status of the image (e.g. filter on "ACTIVE")
|
274 | 2bfb3db3 | Stavros Sachtouris |
|
275 | e51c7d5b | Stavros Sachtouris | :param marker: UUID of the image at which you want to set a marker
|
276 | 2bfb3db3 | Stavros Sachtouris |
|
277 | e51c7d5b | Stavros Sachtouris | :param limit: Integer value for the limit of values to return
|
278 | 2bfb3db3 | Stavros Sachtouris |
|
279 | e51c7d5b | Stavros Sachtouris | :param type: Type of image (e.g. BASE, SERVER, or ALL)
|
280 | 2bfb3db3 | Stavros Sachtouris |
|
281 | 2bfb3db3 | Stavros Sachtouris | :returns: request response
|
282 | 2bfb3db3 | Stavros Sachtouris | """
|
283 | e51c7d5b | Stavros Sachtouris | if not image_id: |
284 | e51c7d5b | Stavros Sachtouris | self.set_param('changes-since', changes_since, iff=changes_since) |
285 | e51c7d5b | Stavros Sachtouris | self.set_param('name', name, iff=name) |
286 | e51c7d5b | Stavros Sachtouris | self.set_param('status', status, iff=status) |
287 | e51c7d5b | Stavros Sachtouris | self.set_param('marker', marker, iff=marker) |
288 | e51c7d5b | Stavros Sachtouris | self.set_param('limit', limit, iff=limit) |
289 | e51c7d5b | Stavros Sachtouris | self.set_param('type', type, iff=type) |
290 | e51c7d5b | Stavros Sachtouris | self.set_param('server', server_name, iff=server_name) |
291 | 2bfb3db3 | Stavros Sachtouris | |
292 | e51c7d5b | Stavros Sachtouris | path = path4url('images', 'detail' if detail else (image_id or '')) |
293 | e51c7d5b | Stavros Sachtouris | return self.get(path, success=success, **kwargs) |
294 | 2bfb3db3 | Stavros Sachtouris | |
295 | e51c7d5b | Stavros Sachtouris | def images_delete(self, image_id='', success=204, **kwargs): |
296 | e51c7d5b | Stavros Sachtouris | """DEL ETE base_url/images/<image_id>
|
297 | 2bfb3db3 | Stavros Sachtouris |
|
298 | e51c7d5b | Stavros Sachtouris | :returns: request response
|
299 | e51c7d5b | Stavros Sachtouris | """
|
300 | e51c7d5b | Stavros Sachtouris | path = path4url('images', image_id)
|
301 | e51c7d5b | Stavros Sachtouris | return self.delete(path, success=success, **kwargs) |
302 | 2bfb3db3 | Stavros Sachtouris | |
303 | e51c7d5b | Stavros Sachtouris | def images_metadata_get(self, image_id, key=None, success=200, **kwargs): |
304 | e51c7d5b | Stavros Sachtouris | """GET base_url/<image_id>/metadata[/key]
|
305 | 2bfb3db3 | Stavros Sachtouris |
|
306 | 2bfb3db3 | Stavros Sachtouris | :returns: request response
|
307 | 2bfb3db3 | Stavros Sachtouris | """
|
308 | e51c7d5b | Stavros Sachtouris | path = path4url('images', image_id, 'metadata', key or '') |
309 | 2bfb3db3 | Stavros Sachtouris | return self.get(path, success=success, **kwargs) |
310 | 2bfb3db3 | Stavros Sachtouris | |
311 | e51c7d5b | Stavros Sachtouris | def images_metadata_post( |
312 | e51c7d5b | Stavros Sachtouris | self, image_id, json_data=None, success=201, **kwargs): |
313 | e51c7d5b | Stavros Sachtouris | """POST base_url/images/<image_id>/metadata
|
314 | 2bfb3db3 | Stavros Sachtouris |
|
315 | 2bfb3db3 | Stavros Sachtouris | :returns: request response
|
316 | 2bfb3db3 | Stavros Sachtouris | """
|
317 | e51c7d5b | Stavros Sachtouris | if json_data is not None: |
318 | e51c7d5b | Stavros Sachtouris | json_data = json.dumps(json_data) |
319 | e51c7d5b | Stavros Sachtouris | self.set_header('Content-Type', 'application/json') |
320 | e51c7d5b | Stavros Sachtouris | self.set_header('Content-Length', len(json_data)) |
321 | 2bfb3db3 | Stavros Sachtouris | |
322 | e51c7d5b | Stavros Sachtouris | path = path4url('images', image_id, 'metadata') |
323 | e51c7d5b | Stavros Sachtouris | return self.post(path, data=json_data, success=success, **kwargs) |
324 | 2bfb3db3 | Stavros Sachtouris | |
325 | e51c7d5b | Stavros Sachtouris | def images_metadata_put( |
326 | e51c7d5b | Stavros Sachtouris | self, image_id, key=None, json_data=None, success=201, **kwargs): |
327 | e51c7d5b | Stavros Sachtouris | """PUT base_url/images/<image_id>/metadata
|
328 | 2bfb3db3 | Stavros Sachtouris |
|
329 | 2bfb3db3 | Stavros Sachtouris | :returns: request response
|
330 | 2bfb3db3 | Stavros Sachtouris | """
|
331 | 2bfb3db3 | Stavros Sachtouris | if json_data is not None: |
332 | e51c7d5b | Stavros Sachtouris | json_data = json.dumps(json_data) |
333 | 2bfb3db3 | Stavros Sachtouris | self.set_header('Content-Type', 'application/json') |
334 | e51c7d5b | Stavros Sachtouris | self.set_header('Content-Length', len(json_data)) |
335 | e51c7d5b | Stavros Sachtouris | |
336 | e51c7d5b | Stavros Sachtouris | path = path4url('images', image_id, 'metadata') |
337 | e51c7d5b | Stavros Sachtouris | return self.put(path, data=json_data, success=success, **kwargs) |
338 | 2bfb3db3 | Stavros Sachtouris | |
339 | e51c7d5b | Stavros Sachtouris | def images_metadata_delete(self, image_id, key, success=204, **kwargs): |
340 | e51c7d5b | Stavros Sachtouris | """DEL ETE base_url/images/<image_id>/metadata/key
|
341 | 2bfb3db3 | Stavros Sachtouris |
|
342 | e51c7d5b | Stavros Sachtouris | :returns: request response
|
343 | e51c7d5b | Stavros Sachtouris | """
|
344 | e51c7d5b | Stavros Sachtouris | path = path4url('images', image_id, 'metadata', key) |
345 | d08962f0 | Stavros Sachtouris | return self.delete(path, success=success, **kwargs) |
346 | e51c7d5b | Stavros Sachtouris | |
347 | e51c7d5b | Stavros Sachtouris | def flavors_get( |
348 | 2bfb3db3 | Stavros Sachtouris | self,
|
349 | e51c7d5b | Stavros Sachtouris | flavor_id='',
|
350 | e51c7d5b | Stavros Sachtouris | detail=False,
|
351 | e51c7d5b | Stavros Sachtouris | changes_since=None,
|
352 | e51c7d5b | Stavros Sachtouris | minDisk=None,
|
353 | e51c7d5b | Stavros Sachtouris | minRam=None,
|
354 | e51c7d5b | Stavros Sachtouris | marker=None,
|
355 | e51c7d5b | Stavros Sachtouris | limit=None,
|
356 | e51c7d5b | Stavros Sachtouris | success=200,
|
357 | 2bfb3db3 | Stavros Sachtouris | **kwargs): |
358 | e51c7d5b | Stavros Sachtouris | """GET base_url[/flavor_id][/command]
|
359 | 2bfb3db3 | Stavros Sachtouris |
|
360 | e51c7d5b | Stavros Sachtouris | :param flavor_id: ignored if detail
|
361 | 2bfb3db3 | Stavros Sachtouris |
|
362 | e51c7d5b | Stavros Sachtouris | :param detail: (bool)
|
363 | 2bfb3db3 | Stavros Sachtouris |
|
364 | e51c7d5b | Stavros Sachtouris | --- Parameters ---
|
365 | 2bfb3db3 | Stavros Sachtouris |
|
366 | e51c7d5b | Stavros Sachtouris | :param changes_since: when the flavor last changed
|
367 | e51c7d5b | Stavros Sachtouris |
|
368 | e51c7d5b | Stavros Sachtouris | :param minDisk: minimum disk space in GB filter
|
369 | e51c7d5b | Stavros Sachtouris |
|
370 | e51c7d5b | Stavros Sachtouris | :param minRam: minimum RAM filter
|
371 | e51c7d5b | Stavros Sachtouris |
|
372 | e51c7d5b | Stavros Sachtouris | :param marker: UUID of the flavor at which to set a marker
|
373 | e51c7d5b | Stavros Sachtouris |
|
374 | e51c7d5b | Stavros Sachtouris | :param limit: limit the number of returned values
|
375 | 2bfb3db3 | Stavros Sachtouris |
|
376 | 2bfb3db3 | Stavros Sachtouris | :returns: request response
|
377 | 2bfb3db3 | Stavros Sachtouris | """
|
378 | e51c7d5b | Stavros Sachtouris | if not flavor_id: |
379 | e51c7d5b | Stavros Sachtouris | self.set_param('changes-since', changes_since, iff=changes_since) |
380 | e51c7d5b | Stavros Sachtouris | self.set_param('minDisk', minDisk, iff=minDisk) |
381 | e51c7d5b | Stavros Sachtouris | self.set_param('minRam', minRam, iff=minRam) |
382 | e51c7d5b | Stavros Sachtouris | self.set_param('marker', marker, iff=marker) |
383 | e51c7d5b | Stavros Sachtouris | self.set_param('limit', limit, iff=limit) |
384 | 2bfb3db3 | Stavros Sachtouris | |
385 | e51c7d5b | Stavros Sachtouris | path = path4url('flavors', 'detail' if detail else (flavor_id or '')) |
386 | e51c7d5b | Stavros Sachtouris | return self.get(path, success=success, **kwargs) |
387 | 0a62912d | Stavros Sachtouris | |
388 | 4a88f05b | Stavros Sachtouris | def floating_ip_pools_get(self, success=200, **kwargs): |
389 | d08962f0 | Stavros Sachtouris | path = path4url('os-floating-ip-pools')
|
390 | 0a62912d | Stavros Sachtouris | return self.get(path, success=success, **kwargs) |
391 | 77d1b504 | Stavros Sachtouris | |
392 | 4a88f05b | Stavros Sachtouris | def floating_ips_get(self, ip='', success=200, **kwargs): |
393 | d08962f0 | Stavros Sachtouris | path = path4url('os-floating-ips', ip or '') |
394 | 77d1b504 | Stavros Sachtouris | return self.get(path, success=success, **kwargs) |
395 | 77d1b504 | Stavros Sachtouris | |
396 | 2e6e03da | Stavros Sachtouris | def floating_ips_post(self, json_data, ip='', success=200, **kwargs): |
397 | d08962f0 | Stavros Sachtouris | path = path4url('os-floating-ips', ip or '') |
398 | 77d1b504 | Stavros Sachtouris | if json_data is not None: |
399 | 77d1b504 | Stavros Sachtouris | json_data = json.dumps(json_data) |
400 | 77d1b504 | Stavros Sachtouris | self.set_header('Content-Type', 'application/json') |
401 | 77d1b504 | Stavros Sachtouris | self.set_header('Content-Length', len(json_data)) |
402 | 77d1b504 | Stavros Sachtouris | return self.post(path, data=json_data, success=success, **kwargs) |
403 | 77d1b504 | Stavros Sachtouris | |
404 | 4a88f05b | Stavros Sachtouris | def floating_ips_delete(self, ip='', success=204, **kwargs): |
405 | d08962f0 | Stavros Sachtouris | path = path4url('os-floating-ips', ip or '') |
406 | 77d1b504 | Stavros Sachtouris | return self.delete(path, success=success, **kwargs) |