1 # Copyright 2012 GRNET S.A. All rights reserved.
3 # Redistribution and use in source and binary forms, with or
4 # without modification, are permitted provided that the following
7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following
11 # 2. Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following
13 # disclaimer in the documentation and/or other materials
14 # provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
29 # The views and conclusions contained in the software and
30 # documentation are those of the authors and should not be
31 # interpreted as representing official policies, either expressed
32 # or implied, of GRNET S.A.
34 from kamaki.clients.compute import ComputeClient
35 from kamaki.clients.utils import path4url
39 class CycladesClientApi(ComputeClient):
40 """GRNet Cyclades REST API Client"""
49 """GET base_url/servers[/server_id][/command] request
51 :param server_id: integer (as int or str)
53 :param command: 'ips', 'stats', or ''
55 :param success: success code or list or tupple of accepted success
56 codes. if server response code is not in this list, a ClientError
59 :param changes_since: (date)
61 :returns: request response
63 path = path4url('servers', server_id, command)
64 self.set_param('changes-since', changes_since, changes_since)
65 return self.get(path, success=success, **kwargs)
73 """GET base_url/networks[/network_id][/command] request
75 :param network_id: integer (str or int)
77 :param command: (str) 'detail' or ''
79 :param success: success code or list or tuple of accepted success
80 codes. if server response code is not in this list, a ClientError
83 :returns: request response
85 path = path4url('networks', network_id, command)
86 return self.get(path, success=success, **kwargs)
94 """DEL ETE base_url/networks[/network_id][/command] request
96 :param network_id: integer (str or int)
98 :param command: (str) 'detail' or ''
100 :param success: success code or list or tuple of accepted success
101 codes. if server response code is not in this list, a ClientError
104 :returns: request response
106 path = path4url('networks', network_id, command)
107 return self.delete(path, success=success, **kwargs)
116 """POST base_url/servers[/server_id]/[command] request
118 :param network_id: integer (str or int)
120 :param command: (str) 'detail' or ''
122 :param json_data: (dict) will be send as data
124 :param success: success code or list or tuple of accepted success
125 codes. if server response code is not in this list, a ClientError
128 :returns: request response
131 if json_data is not None:
132 data = json.dumps(json_data)
133 self.set_header('Content-Type', 'application/json')
134 self.set_header('Content-Length', len(data))
136 path = path4url('networks', network_id, command)
137 return self.post(path, data=data, success=success, **kwargs)
146 """PUT base_url/servers[/server_id]/[command] request
148 :param network_id: integer (str or int)
150 :param command: (str) 'detail' or ''
152 :param json_data: (dict) will be send as data
154 :param success: success code or list or tuple of accepted success
155 codes. if server response code is not in this list, a ClientError
158 :returns: request response
161 if json_data is not None:
162 data = json.dumps(json_data)
163 self.set_header('Content-Type', 'application/json')
164 self.set_header('Content-Length', len(data))
166 path = path4url('networks', network_id, command)
167 return self.put(path, data=data, success=success, **kwargs)