root / kamaki / clients / compute_rest_api.py @ 494fb220
History | View | Annotate | Download (7.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 | 606fe15f | Stavros Sachtouris | def servers_post(self, |
74 | 606fe15f | Stavros Sachtouris | server_id='', command='', json_data=None, success=202, **kwargs): |
75 | 606fe15f | Stavros Sachtouris | """POST base_url/servers[/server_id]/[command] request
|
76 | 606fe15f | Stavros Sachtouris |
|
77 | 606fe15f | Stavros Sachtouris | :param server_id: integer (as int or str)
|
78 | 606fe15f | Stavros Sachtouris |
|
79 | 606fe15f | Stavros Sachtouris | :param command: 'ips', 'stats', or ''
|
80 | 606fe15f | Stavros Sachtouris |
|
81 | 606fe15f | Stavros Sachtouris | :param json_data: a json-formated dict that will be send as data
|
82 | 606fe15f | Stavros Sachtouris |
|
83 | 606fe15f | Stavros Sachtouris | :param success: success code or list or tupple of accepted success
|
84 | 606fe15f | Stavros Sachtouris | codes. if server response code is not in this list, a ClientError
|
85 | 606fe15f | Stavros Sachtouris | raises
|
86 | 606fe15f | Stavros Sachtouris |
|
87 | 606fe15f | Stavros Sachtouris | :returns: request response
|
88 | 606fe15f | Stavros Sachtouris | """
|
89 | 606fe15f | Stavros Sachtouris | data = json_data |
90 | 606fe15f | Stavros Sachtouris | if json_data is not None: |
91 | 606fe15f | Stavros Sachtouris | data = json.dumps(json_data) |
92 | 606fe15f | Stavros Sachtouris | self.set_header('Content-Type', 'application/json') |
93 | 606fe15f | Stavros Sachtouris | self.set_header('Content-Length', len(data)) |
94 | 606fe15f | Stavros Sachtouris | |
95 | 606fe15f | Stavros Sachtouris | path = path4url('servers', server_id, command)
|
96 | 606fe15f | Stavros Sachtouris | return self.post(path, data=data, success=success, **kwargs) |
97 | 606fe15f | Stavros Sachtouris | |
98 | 606fe15f | Stavros Sachtouris | def servers_put(self, |
99 | 606fe15f | Stavros Sachtouris | server_id='', command='', json_data=None, success=204, **kwargs): |
100 | 606fe15f | Stavros Sachtouris | """PUT base_url/servers[/server_id]/[command] request
|
101 | 606fe15f | Stavros Sachtouris |
|
102 | 606fe15f | Stavros Sachtouris | :param server_id: integer (as int or str)
|
103 | 606fe15f | Stavros Sachtouris |
|
104 | 606fe15f | Stavros Sachtouris | :param command: 'ips', 'stats', or ''
|
105 | 606fe15f | Stavros Sachtouris |
|
106 | 606fe15f | Stavros Sachtouris | :param json_data: a json-formated dict that will be send as data
|
107 | 606fe15f | Stavros Sachtouris |
|
108 | 606fe15f | Stavros Sachtouris | :param success: success code or list or tupple of accepted success
|
109 | 606fe15f | Stavros Sachtouris | codes. if server response code is not in this list, a ClientError
|
110 | 606fe15f | Stavros Sachtouris | raises
|
111 | 606fe15f | Stavros Sachtouris |
|
112 | 606fe15f | Stavros Sachtouris | :returns: request response
|
113 | 606fe15f | Stavros Sachtouris | """
|
114 | 606fe15f | Stavros Sachtouris | data = json_data |
115 | 606fe15f | Stavros Sachtouris | if json_data is not None: |
116 | 606fe15f | Stavros Sachtouris | data = json.dumps(json_data) |
117 | 606fe15f | Stavros Sachtouris | self.set_header('Content-Type', 'application/json') |
118 | 606fe15f | Stavros Sachtouris | self.set_header('Content-Length', len(data)) |
119 | 606fe15f | Stavros Sachtouris | |
120 | 606fe15f | Stavros Sachtouris | path = path4url('servers', server_id, command)
|
121 | 606fe15f | Stavros Sachtouris | return self.put(path, data=data, success=success, **kwargs) |
122 | a2ef112e | Stavros Sachtouris | |
123 | a2ef112e | Stavros Sachtouris | def flavors_get(self, flavor_id='', command='', success=200, **kwargs): |
124 | a2ef112e | Stavros Sachtouris | """GET base_url[/flavor_id][/command]
|
125 | a2ef112e | Stavros Sachtouris |
|
126 | a2ef112e | Stavros Sachtouris | :param flavor_id: integer (str or int)
|
127 | a2ef112e | Stavros Sachtouris |
|
128 | a2ef112e | Stavros Sachtouris | :param command: flavor service command
|
129 | a2ef112e | Stavros Sachtouris |
|
130 | a2ef112e | Stavros Sachtouris | :param success: success code or list or tupple of accepted success
|
131 | a2ef112e | Stavros Sachtouris | codes. if server response code is not in this list, a ClientError
|
132 | a2ef112e | Stavros Sachtouris | raises
|
133 | a2ef112e | Stavros Sachtouris |
|
134 | a2ef112e | Stavros Sachtouris | :returns: request response
|
135 | a2ef112e | Stavros Sachtouris | """
|
136 | a2ef112e | Stavros Sachtouris | path = path4url('flavors', flavor_id, command)
|
137 | a2ef112e | Stavros Sachtouris | return self.get(path, success=success, **kwargs) |
138 | a2ef112e | Stavros Sachtouris | |
139 | a2ef112e | Stavros Sachtouris | def images_get(self, image_id='', command='', success=200, **kwargs): |
140 | a2ef112e | Stavros Sachtouris | """GET base_url[/image_id][/command]
|
141 | a2ef112e | Stavros Sachtouris |
|
142 | a2ef112e | Stavros Sachtouris | :param image_id: string
|
143 | a2ef112e | Stavros Sachtouris |
|
144 | a2ef112e | Stavros Sachtouris | :param command: image server command
|
145 | a2ef112e | Stavros Sachtouris |
|
146 | a2ef112e | Stavros Sachtouris | :param success: success code or list or tupple of accepted success
|
147 | a2ef112e | Stavros Sachtouris | codes. if server response code is not in this list, a ClientError
|
148 | a2ef112e | Stavros Sachtouris | raises
|
149 | a2ef112e | Stavros Sachtouris |
|
150 | a2ef112e | Stavros Sachtouris | :returns: request response
|
151 | a2ef112e | Stavros Sachtouris | """
|
152 | a2ef112e | Stavros Sachtouris | path = path4url('images', image_id, command)
|
153 | a2ef112e | Stavros Sachtouris | return self.get(path, success=success, **kwargs) |
154 | a2ef112e | Stavros Sachtouris | |
155 | a2ef112e | Stavros Sachtouris | def images_delete(self, image_id='', command='', success=204, **kwargs): |
156 | a2ef112e | Stavros Sachtouris | """DELETE base_url[/image_id][/command]
|
157 | a2ef112e | Stavros Sachtouris |
|
158 | a2ef112e | Stavros Sachtouris | :param image_id: string
|
159 | a2ef112e | Stavros Sachtouris |
|
160 | a2ef112e | Stavros Sachtouris | :param command: image server command
|
161 | a2ef112e | Stavros Sachtouris |
|
162 | a2ef112e | Stavros Sachtouris | :param success: success code or list or tuple of accepted success
|
163 | a2ef112e | Stavros Sachtouris | codes. if server response code is not in this list, a ClientError
|
164 | a2ef112e | Stavros Sachtouris | raises
|
165 | a2ef112e | Stavros Sachtouris |
|
166 | a2ef112e | Stavros Sachtouris | :returns: request response
|
167 | a2ef112e | Stavros Sachtouris | """
|
168 | a2ef112e | Stavros Sachtouris | path = path4url('images', image_id, command)
|
169 | a2ef112e | Stavros Sachtouris | return self.delete(path, success=success, **kwargs) |
170 | a2ef112e | Stavros Sachtouris | |
171 | a2ef112e | Stavros Sachtouris | def images_post(self, |
172 | a2ef112e | Stavros Sachtouris | image_id='', command='', json_data=None, success=201, **kwargs): |
173 | a2ef112e | Stavros Sachtouris | """POST base_url/images[/image_id]/[command] request
|
174 | a2ef112e | Stavros Sachtouris |
|
175 | a2ef112e | Stavros Sachtouris | :param image_id: string
|
176 | a2ef112e | Stavros Sachtouris |
|
177 | a2ef112e | Stavros Sachtouris | :param command: image server command
|
178 | a2ef112e | Stavros Sachtouris |
|
179 | a2ef112e | Stavros Sachtouris | :param json_data: (dict) will be send as data
|
180 | a2ef112e | Stavros Sachtouris |
|
181 | a2ef112e | Stavros Sachtouris | :param success: success code or list or tuple of accepted success
|
182 | a2ef112e | Stavros Sachtouris | codes. if server response code is not in this list, a ClientError
|
183 | a2ef112e | Stavros Sachtouris | raises
|
184 | a2ef112e | Stavros Sachtouris |
|
185 | a2ef112e | Stavros Sachtouris | :returns: request response
|
186 | a2ef112e | Stavros Sachtouris | """
|
187 | a2ef112e | Stavros Sachtouris | data = json_data |
188 | a2ef112e | Stavros Sachtouris | if json_data is not None: |
189 | a2ef112e | Stavros Sachtouris | data = json.dumps(json_data) |
190 | a2ef112e | Stavros Sachtouris | self.set_header('Content-Type', 'application/json') |
191 | a2ef112e | Stavros Sachtouris | self.set_header('Content-Length', len(data)) |
192 | a2ef112e | Stavros Sachtouris | |
193 | a2ef112e | Stavros Sachtouris | path = path4url('images', image_id, command)
|
194 | a2ef112e | Stavros Sachtouris | return self.post(path, data=data, success=success, **kwargs) |
195 | a2ef112e | Stavros Sachtouris | |
196 | a2ef112e | Stavros Sachtouris | def images_put(self, |
197 | a2ef112e | Stavros Sachtouris | image_id='', command='', json_data=None, success=201, **kwargs): |
198 | a2ef112e | Stavros Sachtouris | """PUT base_url/images[/image_id]/[command] request
|
199 | a2ef112e | Stavros Sachtouris |
|
200 | a2ef112e | Stavros Sachtouris | :param image_id: string
|
201 | a2ef112e | Stavros Sachtouris |
|
202 | a2ef112e | Stavros Sachtouris | :param command: image server command
|
203 | a2ef112e | Stavros Sachtouris |
|
204 | a2ef112e | Stavros Sachtouris | :param json_data: (dict) will be send as data
|
205 | a2ef112e | Stavros Sachtouris |
|
206 | a2ef112e | Stavros Sachtouris | :param success: success code or list or tuple of accepted success
|
207 | a2ef112e | Stavros Sachtouris | codes. if server response code is not in this list, a ClientError
|
208 | a2ef112e | Stavros Sachtouris | raises
|
209 | a2ef112e | Stavros Sachtouris |
|
210 | a2ef112e | Stavros Sachtouris | :returns: request response
|
211 | a2ef112e | Stavros Sachtouris | """
|
212 | a2ef112e | Stavros Sachtouris | data = json_data |
213 | a2ef112e | Stavros Sachtouris | if json_data is not None: |
214 | a2ef112e | Stavros Sachtouris | data = json.dumps(json_data) |
215 | a2ef112e | Stavros Sachtouris | self.set_header('Content-Type', 'application/json') |
216 | a2ef112e | Stavros Sachtouris | self.set_header('Content-Length', len(data)) |
217 | a2ef112e | Stavros Sachtouris | |
218 | a2ef112e | Stavros Sachtouris | path = path4url('images', image_id, command)
|
219 | a2ef112e | Stavros Sachtouris | return self.put(path, data=data, success=success, **kwargs) |