root / kamaki / clients / cyclades / rest_api.py @ e51c7d5b
History | View | Annotate | Download (5.9 kB)
1 |
# Copyright 2012-2013 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 CycladesRestClient(ComputeClient): |
40 |
"""Synnefo Cyclades REST API Client"""
|
41 |
|
42 |
def servers_stats_get(self, server_id, success=200, **kwargs): |
43 |
"""GET base_url/servers/<server_id>/stats"""
|
44 |
path = path4url('servers', server_id, 'stats') |
45 |
return self.get(path, success=success, **kwargs) |
46 |
|
47 |
def networks_get( |
48 |
self,
|
49 |
network_id='',
|
50 |
command='',
|
51 |
success=(200, 203), |
52 |
**kwargs): |
53 |
"""GET base_url/networks[/network_id][/command] request
|
54 |
|
55 |
:param network_id: integer (str or int)
|
56 |
|
57 |
:param command: (str) 'detail' or ''
|
58 |
|
59 |
:param success: success code or list or tuple of accepted success
|
60 |
codes. if server response code is not in this list, a ClientError
|
61 |
raises
|
62 |
|
63 |
:returns: request response
|
64 |
"""
|
65 |
path = path4url('networks', network_id, command)
|
66 |
return self.get(path, success=success, **kwargs) |
67 |
|
68 |
def networks_delete( |
69 |
self,
|
70 |
network_id='',
|
71 |
command='',
|
72 |
success=204,
|
73 |
**kwargs): |
74 |
"""DEL ETE base_url/networks[/network_id][/command] request
|
75 |
|
76 |
:param network_id: integer (str or int)
|
77 |
|
78 |
:param command: (str) 'detail' or ''
|
79 |
|
80 |
:param success: success code or list or tuple of accepted success
|
81 |
codes. if server response code is not in this list, a ClientError
|
82 |
raises
|
83 |
|
84 |
:returns: request response
|
85 |
"""
|
86 |
path = path4url('networks', network_id, command)
|
87 |
return self.delete(path, success=success, **kwargs) |
88 |
|
89 |
def networks_post( |
90 |
self,
|
91 |
network_id='',
|
92 |
command='',
|
93 |
json_data=None,
|
94 |
success=202,
|
95 |
**kwargs): |
96 |
"""POST base_url/servers[/server_id]/[command] request
|
97 |
|
98 |
:param network_id: integer (str or int)
|
99 |
|
100 |
:param command: (str) 'detail' or ''
|
101 |
|
102 |
:param json_data: (dict) will be send as data
|
103 |
|
104 |
:param success: success code or list or tuple of accepted success
|
105 |
codes. if server response code is not in this list, a ClientError
|
106 |
raises
|
107 |
|
108 |
:returns: request response
|
109 |
"""
|
110 |
data = json_data |
111 |
if json_data is not None: |
112 |
data = json.dumps(json_data) |
113 |
self.set_header('Content-Type', 'application/json') |
114 |
self.set_header('Content-Length', len(data)) |
115 |
|
116 |
path = path4url('networks', network_id, command)
|
117 |
return self.post(path, data=data, success=success, **kwargs) |
118 |
|
119 |
def networks_put( |
120 |
self,
|
121 |
network_id='',
|
122 |
command='',
|
123 |
json_data=None,
|
124 |
success=204,
|
125 |
**kwargs): |
126 |
"""PUT base_url/servers[/server_id]/[command] request
|
127 |
|
128 |
:param network_id: integer (str or int)
|
129 |
|
130 |
:param command: (str) 'detail' or ''
|
131 |
|
132 |
:param json_data: (dict) will be send as data
|
133 |
|
134 |
:param success: success code or list or tuple of accepted success
|
135 |
codes. if server response code is not in this list, a ClientError
|
136 |
raises
|
137 |
|
138 |
:returns: request response
|
139 |
"""
|
140 |
data = json_data |
141 |
if json_data is not None: |
142 |
data = json.dumps(json_data) |
143 |
self.set_header('Content-Type', 'application/json') |
144 |
self.set_header('Content-Length', len(data)) |
145 |
|
146 |
path = path4url('networks', network_id, command)
|
147 |
return self.put(path, data=data, success=success, **kwargs) |
148 |
|
149 |
def floating_ip_pools_get(self, success=200, **kwargs): |
150 |
path = path4url('os-floating-ip-pools')
|
151 |
return self.get(path, success=success, **kwargs) |
152 |
|
153 |
def floating_ips_get(self, fip_id='', success=200, **kwargs): |
154 |
path = path4url('os-floating-ips', fip_id)
|
155 |
return self.get(path, success=success, **kwargs) |
156 |
|
157 |
def floating_ips_post(self, json_data, fip_id='', success=201, **kwargs): |
158 |
path = path4url('os-floating-ips', fip_id)
|
159 |
if json_data is not None: |
160 |
json_data = json.dumps(json_data) |
161 |
self.set_header('Content-Type', 'application/json') |
162 |
self.set_header('Content-Length', len(json_data)) |
163 |
return self.post(path, data=json_data, success=success, **kwargs) |
164 |
|
165 |
def floating_ips_delete(self, fip_id, success=200, **kwargs): |
166 |
path = path4url('os-floating-ips', fip_id)
|
167 |
return self.delete(path, success=success, **kwargs) |