root / kamaki / clients / compute_rest_api.py @ 2005b18e
History | View | Annotate | Download (8 kB)
1 | 606fe15f | Stavros Sachtouris | # Copyright 2012 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | 606fe15f | Stavros Sachtouris | #
|
3 | 606fe15f | Stavros Sachtouris | # Redistribution and use in source and binary forms, with or
|
4 | 606fe15f | Stavros Sachtouris | # without modification, are permitted provided that the following
|
5 | 606fe15f | Stavros Sachtouris | # conditions are met:
|
6 | 606fe15f | Stavros Sachtouris | #
|
7 | 606fe15f | Stavros Sachtouris | # 1. Redistributions of source code must retain the above
|
8 | 606fe15f | Stavros Sachtouris | # copyright notice, this list of conditions and the following
|
9 | 606fe15f | Stavros Sachtouris | # disclaimer.
|
10 | 606fe15f | Stavros Sachtouris | #
|
11 | 606fe15f | Stavros Sachtouris | # 2. Redistributions in binary form must reproduce the above
|
12 | 606fe15f | Stavros Sachtouris | # copyright notice, this list of conditions and the following
|
13 | 606fe15f | Stavros Sachtouris | # disclaimer in the documentation and/or other materials
|
14 | 606fe15f | Stavros Sachtouris | # provided with the distribution.
|
15 | 606fe15f | Stavros Sachtouris | #
|
16 | 606fe15f | Stavros Sachtouris | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | 606fe15f | Stavros Sachtouris | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | 606fe15f | Stavros Sachtouris | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | 606fe15f | Stavros Sachtouris | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | 606fe15f | Stavros Sachtouris | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | 606fe15f | Stavros Sachtouris | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | 606fe15f | Stavros Sachtouris | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | 606fe15f | Stavros Sachtouris | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | 606fe15f | Stavros Sachtouris | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | 606fe15f | Stavros Sachtouris | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | 606fe15f | Stavros Sachtouris | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | 606fe15f | Stavros Sachtouris | # POSSIBILITY OF SUCH DAMAGE.
|
28 | 606fe15f | Stavros Sachtouris | #
|
29 | 606fe15f | Stavros Sachtouris | # The views and conclusions contained in the software and
|
30 | 606fe15f | Stavros Sachtouris | # documentation are those of the authors and should not be
|
31 | 606fe15f | Stavros Sachtouris | # interpreted as representing official policies, either expressed
|
32 | 606fe15f | Stavros Sachtouris | # or implied, of GRNET S.A.
|
33 | 606fe15f | Stavros Sachtouris | |
34 | 606fe15f | Stavros Sachtouris | from kamaki.clients import Client |
35 | 606fe15f | Stavros Sachtouris | from kamaki.clients.utils import path4url |
36 | 606fe15f | Stavros Sachtouris | import json |
37 | 606fe15f | Stavros Sachtouris | |
38 | 606fe15f | Stavros Sachtouris | |
39 | 606fe15f | Stavros Sachtouris | class ComputeClientApi(Client): |
40 | 606fe15f | Stavros Sachtouris | |
41 | 606fe15f | Stavros Sachtouris | def servers_get(self, server_id='', command='', success=200, **kwargs): |
42 | 606fe15f | Stavros Sachtouris | """GET base_url/servers[/server_id][/command] request
|
43 | 606fe15f | Stavros Sachtouris |
|
44 | 606fe15f | Stavros Sachtouris | :param server_id: integer (as int or str)
|
45 | 606fe15f | Stavros Sachtouris |
|
46 | 606fe15f | Stavros Sachtouris | :param command: 'ips', 'stats', or ''
|
47 | 606fe15f | Stavros Sachtouris |
|
48 | 606fe15f | Stavros Sachtouris | :param success: success code or list or tupple of accepted success
|
49 | 606fe15f | Stavros Sachtouris | codes. if server response code is not in this list, a ClientError
|
50 | 606fe15f | Stavros Sachtouris | raises
|
51 | 606fe15f | Stavros Sachtouris |
|
52 | 606fe15f | Stavros Sachtouris | :returns: request response
|
53 | 606fe15f | Stavros Sachtouris | """
|
54 | 606fe15f | Stavros Sachtouris | path = path4url('servers', server_id, command)
|
55 | 606fe15f | Stavros Sachtouris | return self.get(path, success=success, **kwargs) |
56 | 606fe15f | Stavros Sachtouris | |
57 | 606fe15f | Stavros Sachtouris | def servers_delete(self, server_id='', command='', success=204, **kwargs): |
58 | 606fe15f | Stavros Sachtouris | """DEL ETE base_url/servers[/server_id][/command] request
|
59 | 606fe15f | Stavros Sachtouris |
|
60 | 606fe15f | Stavros Sachtouris | :param server_id: integer (as int or str)
|
61 | 606fe15f | Stavros Sachtouris |
|
62 | 606fe15f | Stavros Sachtouris | :param command: 'ips', 'stats', or ''
|
63 | 606fe15f | Stavros Sachtouris |
|
64 | 606fe15f | Stavros Sachtouris | :param success: success code or list or tupple of accepted success
|
65 | 606fe15f | Stavros Sachtouris | codes. if server response code is not in this list, a ClientError
|
66 | 606fe15f | Stavros Sachtouris | raises
|
67 | 606fe15f | Stavros Sachtouris |
|
68 | 606fe15f | Stavros Sachtouris | :returns: request response
|
69 | 606fe15f | Stavros Sachtouris | """
|
70 | 606fe15f | Stavros Sachtouris | path = path4url('servers', server_id, command)
|
71 | 606fe15f | Stavros Sachtouris | return self.delete(path, success=success, **kwargs) |
72 | 606fe15f | Stavros Sachtouris | |
73 | de73876b | Stavros Sachtouris | def servers_post( |
74 | 24ff0a35 | Stavros Sachtouris | self,
|
75 | 24ff0a35 | Stavros Sachtouris | server_id='',
|
76 | 24ff0a35 | Stavros Sachtouris | command='',
|
77 | 24ff0a35 | Stavros Sachtouris | json_data=None,
|
78 | 24ff0a35 | Stavros Sachtouris | success=202,
|
79 | 24ff0a35 | Stavros Sachtouris | **kwargs): |
80 | 606fe15f | Stavros Sachtouris | """POST base_url/servers[/server_id]/[command] request
|
81 | 606fe15f | Stavros Sachtouris |
|
82 | 606fe15f | Stavros Sachtouris | :param server_id: integer (as int or str)
|
83 | 606fe15f | Stavros Sachtouris |
|
84 | 606fe15f | Stavros Sachtouris | :param command: 'ips', 'stats', or ''
|
85 | 606fe15f | Stavros Sachtouris |
|
86 | 606fe15f | Stavros Sachtouris | :param json_data: a json-formated dict that will be send as data
|
87 | 606fe15f | Stavros Sachtouris |
|
88 | 606fe15f | Stavros Sachtouris | :param success: success code or list or tupple of accepted success
|
89 | 606fe15f | Stavros Sachtouris | codes. if server response code is not in this list, a ClientError
|
90 | 606fe15f | Stavros Sachtouris | raises
|
91 | 606fe15f | Stavros Sachtouris |
|
92 | 606fe15f | Stavros Sachtouris | :returns: request response
|
93 | 606fe15f | Stavros Sachtouris | """
|
94 | 606fe15f | Stavros Sachtouris | data = json_data |
95 | 606fe15f | Stavros Sachtouris | if json_data is not None: |
96 | 606fe15f | Stavros Sachtouris | data = json.dumps(json_data) |
97 | 606fe15f | Stavros Sachtouris | self.set_header('Content-Type', 'application/json') |
98 | 606fe15f | Stavros Sachtouris | self.set_header('Content-Length', len(data)) |
99 | 606fe15f | Stavros Sachtouris | |
100 | 606fe15f | Stavros Sachtouris | path = path4url('servers', server_id, command)
|
101 | 606fe15f | Stavros Sachtouris | return self.post(path, data=data, success=success, **kwargs) |
102 | 606fe15f | Stavros Sachtouris | |
103 | de73876b | Stavros Sachtouris | def servers_put( |
104 | 24ff0a35 | Stavros Sachtouris | self,
|
105 | 24ff0a35 | Stavros Sachtouris | server_id='',
|
106 | 24ff0a35 | Stavros Sachtouris | command='',
|
107 | 24ff0a35 | Stavros Sachtouris | json_data=None,
|
108 | 24ff0a35 | Stavros Sachtouris | success=204,
|
109 | 24ff0a35 | Stavros Sachtouris | **kwargs): |
110 | 606fe15f | Stavros Sachtouris | """PUT base_url/servers[/server_id]/[command] request
|
111 | 606fe15f | Stavros Sachtouris |
|
112 | 606fe15f | Stavros Sachtouris | :param server_id: integer (as int or str)
|
113 | 606fe15f | Stavros Sachtouris |
|
114 | 606fe15f | Stavros Sachtouris | :param command: 'ips', 'stats', or ''
|
115 | 606fe15f | Stavros Sachtouris |
|
116 | 606fe15f | Stavros Sachtouris | :param json_data: a json-formated dict that will be send as data
|
117 | 606fe15f | Stavros Sachtouris |
|
118 | 606fe15f | Stavros Sachtouris | :param success: success code or list or tupple of accepted success
|
119 | 606fe15f | Stavros Sachtouris | codes. if server response code is not in this list, a ClientError
|
120 | 606fe15f | Stavros Sachtouris | raises
|
121 | 606fe15f | Stavros Sachtouris |
|
122 | 606fe15f | Stavros Sachtouris | :returns: request response
|
123 | 606fe15f | Stavros Sachtouris | """
|
124 | 606fe15f | Stavros Sachtouris | data = json_data |
125 | 606fe15f | Stavros Sachtouris | if json_data is not None: |
126 | 606fe15f | Stavros Sachtouris | data = json.dumps(json_data) |
127 | 606fe15f | Stavros Sachtouris | self.set_header('Content-Type', 'application/json') |
128 | 606fe15f | Stavros Sachtouris | self.set_header('Content-Length', len(data)) |
129 | 606fe15f | Stavros Sachtouris | |
130 | 606fe15f | Stavros Sachtouris | path = path4url('servers', server_id, command)
|
131 | 606fe15f | Stavros Sachtouris | return self.put(path, data=data, success=success, **kwargs) |
132 | a2ef112e | Stavros Sachtouris | |
133 | a2ef112e | Stavros Sachtouris | def flavors_get(self, flavor_id='', command='', success=200, **kwargs): |
134 | a2ef112e | Stavros Sachtouris | """GET base_url[/flavor_id][/command]
|
135 | a2ef112e | Stavros Sachtouris |
|
136 | a2ef112e | Stavros Sachtouris | :param flavor_id: integer (str or int)
|
137 | a2ef112e | Stavros Sachtouris |
|
138 | a2ef112e | Stavros Sachtouris | :param command: flavor service command
|
139 | a2ef112e | Stavros Sachtouris |
|
140 | a2ef112e | Stavros Sachtouris | :param success: success code or list or tupple of accepted success
|
141 | a2ef112e | Stavros Sachtouris | codes. if server response code is not in this list, a ClientError
|
142 | a2ef112e | Stavros Sachtouris | raises
|
143 | a2ef112e | Stavros Sachtouris |
|
144 | a2ef112e | Stavros Sachtouris | :returns: request response
|
145 | a2ef112e | Stavros Sachtouris | """
|
146 | a2ef112e | Stavros Sachtouris | path = path4url('flavors', flavor_id, command)
|
147 | a2ef112e | Stavros Sachtouris | return self.get(path, success=success, **kwargs) |
148 | a2ef112e | Stavros Sachtouris | |
149 | a2ef112e | Stavros Sachtouris | def images_get(self, image_id='', command='', success=200, **kwargs): |
150 | a2ef112e | Stavros Sachtouris | """GET base_url[/image_id][/command]
|
151 | a2ef112e | Stavros Sachtouris |
|
152 | a2ef112e | Stavros Sachtouris | :param image_id: string
|
153 | a2ef112e | Stavros Sachtouris |
|
154 | a2ef112e | Stavros Sachtouris | :param command: image server command
|
155 | a2ef112e | Stavros Sachtouris |
|
156 | a2ef112e | Stavros Sachtouris | :param success: success code or list or tupple of accepted success
|
157 | a2ef112e | Stavros Sachtouris | codes. if server response code is not in this list, a ClientError
|
158 | a2ef112e | Stavros Sachtouris | raises
|
159 | a2ef112e | Stavros Sachtouris |
|
160 | a2ef112e | Stavros Sachtouris | :returns: request response
|
161 | a2ef112e | Stavros Sachtouris | """
|
162 | a2ef112e | Stavros Sachtouris | path = path4url('images', image_id, command)
|
163 | a2ef112e | Stavros Sachtouris | return self.get(path, success=success, **kwargs) |
164 | a2ef112e | Stavros Sachtouris | |
165 | a2ef112e | Stavros Sachtouris | def images_delete(self, image_id='', command='', success=204, **kwargs): |
166 | a2ef112e | Stavros Sachtouris | """DELETE base_url[/image_id][/command]
|
167 | a2ef112e | Stavros Sachtouris |
|
168 | a2ef112e | Stavros Sachtouris | :param image_id: string
|
169 | a2ef112e | Stavros Sachtouris |
|
170 | a2ef112e | Stavros Sachtouris | :param command: image server command
|
171 | a2ef112e | Stavros Sachtouris |
|
172 | a2ef112e | Stavros Sachtouris | :param success: success code or list or tuple of accepted success
|
173 | a2ef112e | Stavros Sachtouris | codes. if server response code is not in this list, a ClientError
|
174 | a2ef112e | Stavros Sachtouris | raises
|
175 | a2ef112e | Stavros Sachtouris |
|
176 | a2ef112e | Stavros Sachtouris | :returns: request response
|
177 | a2ef112e | Stavros Sachtouris | """
|
178 | a2ef112e | Stavros Sachtouris | path = path4url('images', image_id, command)
|
179 | a2ef112e | Stavros Sachtouris | return self.delete(path, success=success, **kwargs) |
180 | a2ef112e | Stavros Sachtouris | |
181 | de73876b | Stavros Sachtouris | def images_post( |
182 | 24ff0a35 | Stavros Sachtouris | self,
|
183 | 24ff0a35 | Stavros Sachtouris | image_id='',
|
184 | 24ff0a35 | Stavros Sachtouris | command='',
|
185 | 24ff0a35 | Stavros Sachtouris | json_data=None,
|
186 | 24ff0a35 | Stavros Sachtouris | success=201,
|
187 | 24ff0a35 | Stavros Sachtouris | **kwargs): |
188 | a2ef112e | Stavros Sachtouris | """POST base_url/images[/image_id]/[command] request
|
189 | a2ef112e | Stavros Sachtouris |
|
190 | a2ef112e | Stavros Sachtouris | :param image_id: string
|
191 | a2ef112e | Stavros Sachtouris |
|
192 | a2ef112e | Stavros Sachtouris | :param command: image server command
|
193 | a2ef112e | Stavros Sachtouris |
|
194 | a2ef112e | Stavros Sachtouris | :param json_data: (dict) will be send as data
|
195 | a2ef112e | Stavros Sachtouris |
|
196 | a2ef112e | Stavros Sachtouris | :param success: success code or list or tuple of accepted success
|
197 | a2ef112e | Stavros Sachtouris | codes. if server response code is not in this list, a ClientError
|
198 | a2ef112e | Stavros Sachtouris | raises
|
199 | a2ef112e | Stavros Sachtouris |
|
200 | a2ef112e | Stavros Sachtouris | :returns: request response
|
201 | a2ef112e | Stavros Sachtouris | """
|
202 | a2ef112e | Stavros Sachtouris | data = json_data |
203 | a2ef112e | Stavros Sachtouris | if json_data is not None: |
204 | a2ef112e | Stavros Sachtouris | data = json.dumps(json_data) |
205 | a2ef112e | Stavros Sachtouris | self.set_header('Content-Type', 'application/json') |
206 | a2ef112e | Stavros Sachtouris | self.set_header('Content-Length', len(data)) |
207 | a2ef112e | Stavros Sachtouris | |
208 | a2ef112e | Stavros Sachtouris | path = path4url('images', image_id, command)
|
209 | a2ef112e | Stavros Sachtouris | return self.post(path, data=data, success=success, **kwargs) |
210 | a2ef112e | Stavros Sachtouris | |
211 | de73876b | Stavros Sachtouris | def images_put( |
212 | 24ff0a35 | Stavros Sachtouris | self,
|
213 | 24ff0a35 | Stavros Sachtouris | image_id='',
|
214 | 24ff0a35 | Stavros Sachtouris | command='',
|
215 | 24ff0a35 | Stavros Sachtouris | json_data=None,
|
216 | 24ff0a35 | Stavros Sachtouris | success=201,
|
217 | 24ff0a35 | Stavros Sachtouris | **kwargs): |
218 | a2ef112e | Stavros Sachtouris | """PUT base_url/images[/image_id]/[command] request
|
219 | a2ef112e | Stavros Sachtouris |
|
220 | a2ef112e | Stavros Sachtouris | :param image_id: string
|
221 | a2ef112e | Stavros Sachtouris |
|
222 | a2ef112e | Stavros Sachtouris | :param command: image server command
|
223 | a2ef112e | Stavros Sachtouris |
|
224 | a2ef112e | Stavros Sachtouris | :param json_data: (dict) will be send as data
|
225 | a2ef112e | Stavros Sachtouris |
|
226 | a2ef112e | Stavros Sachtouris | :param success: success code or list or tuple of accepted success
|
227 | a2ef112e | Stavros Sachtouris | codes. if server response code is not in this list, a ClientError
|
228 | a2ef112e | Stavros Sachtouris | raises
|
229 | a2ef112e | Stavros Sachtouris |
|
230 | a2ef112e | Stavros Sachtouris | :returns: request response
|
231 | a2ef112e | Stavros Sachtouris | """
|
232 | a2ef112e | Stavros Sachtouris | data = json_data |
233 | a2ef112e | Stavros Sachtouris | if json_data is not None: |
234 | a2ef112e | Stavros Sachtouris | data = json.dumps(json_data) |
235 | a2ef112e | Stavros Sachtouris | self.set_header('Content-Type', 'application/json') |
236 | a2ef112e | Stavros Sachtouris | self.set_header('Content-Length', len(data)) |
237 | a2ef112e | Stavros Sachtouris | |
238 | a2ef112e | Stavros Sachtouris | path = path4url('images', image_id, command)
|
239 | a2ef112e | Stavros Sachtouris | return self.put(path, data=data, success=success, **kwargs) |