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