Fix pep8 compliance issues everywhere
[kamaki] / kamaki / clients / cyclades_rest_api.py
1 # Copyright 2012 GRNET S.A. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or
4 # without modification, are permitted provided that the following
5 # conditions are met:
6 #
7 #   1. Redistributions of source code must retain the above
8 #      copyright notice, this list of conditions and the following
9 #      disclaimer.
10 #
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.
15 #
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.
28 #
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.
33
34 from kamaki.clients.compute import ComputeClient
35 from kamaki.clients.utils import path4url
36 import json
37
38
39 class CycladesClientApi(ComputeClient):
40     """GRNet Cyclades REST API Client"""
41
42     def servers_get(
43             self,
44             server_id='',
45             command='',
46             success=200,
47             changes_since=None,
48             **kwargs):
49         """GET base_url/servers[/server_id][/command] request
50
51         :param server_id: integer (as int or str)
52
53         :param command: 'ips', 'stats', or ''
54
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
57             raises
58
59         :param changes_since: (date)
60
61         :returns: request response
62         """
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)
66
67     def networks_get(
68             self,
69             network_id='',
70             command='',
71             success=(200, 203),
72             **kwargs):
73         """GET base_url/networks[/network_id][/command] request
74
75         :param network_id: integer (str or int)
76
77         :param command: (str) 'detail' or ''
78
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
81             raises
82
83         :returns: request response
84         """
85         path = path4url('networks', network_id, command)
86         return self.get(path, success=success, **kwargs)
87
88     def networks_delete(
89             self,
90             network_id='',
91             command='',
92             success=204,
93             **kwargs):
94         """DEL ETE base_url/networks[/network_id][/command] request
95
96         :param network_id: integer (str or int)
97
98         :param command: (str) 'detail' or ''
99
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
102             raises
103
104         :returns: request response
105         """
106         path = path4url('networks', network_id, command)
107         return self.delete(path, success=success, **kwargs)
108
109     def networks_post(
110             self,
111             network_id='',
112             command='',
113             json_data=None,
114             success=202,
115             **kwargs):
116         """POST base_url/servers[/server_id]/[command] request
117
118         :param network_id: integer (str or int)
119
120         :param command: (str) 'detail' or ''
121
122         :param json_data: (dict) will be send as data
123
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
126             raises
127
128         :returns: request response
129         """
130         data = json_data
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))
135
136         path = path4url('networks', network_id, command)
137         return self.post(path, data=data, success=success, **kwargs)
138
139     def networks_put(
140             self,
141             network_id='',
142             command='',
143             json_data=None,
144             success=204,
145             **kwargs):
146         """PUT base_url/servers[/server_id]/[command] request
147
148         :param network_id: integer (str or int)
149
150         :param command: (str) 'detail' or ''
151
152         :param json_data: (dict) will be send as data
153
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
156             raises
157
158         :returns: request response
159         """
160         data = json_data
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))
165
166         path = path4url('networks', network_id, command)
167         return self.put(path, data=data, success=success, **kwargs)