Statistics
| Branch: | Tag: | Revision:

root / kamaki / clients / cyclades_rest_api.py @ 43ee6ae1

History | View | Annotate | Download (4.6 kB)

1 29685b9b Stavros Sachtouris
# Copyright 2012 GRNET S.A. All rights reserved.
2 29685b9b Stavros Sachtouris
#
3 29685b9b Stavros Sachtouris
# Redistribution and use in source and binary forms, with or
4 29685b9b Stavros Sachtouris
# without modification, are permitted provided that the following
5 29685b9b Stavros Sachtouris
# conditions are met:
6 29685b9b Stavros Sachtouris
#
7 29685b9b Stavros Sachtouris
#   1. Redistributions of source code must retain the above
8 29685b9b Stavros Sachtouris
#      copyright notice, this list of conditions and the following
9 29685b9b Stavros Sachtouris
#      disclaimer.
10 29685b9b Stavros Sachtouris
#
11 29685b9b Stavros Sachtouris
#   2. Redistributions in binary form must reproduce the above
12 29685b9b Stavros Sachtouris
#      copyright notice, this list of conditions and the following
13 29685b9b Stavros Sachtouris
#      disclaimer in the documentation and/or other materials
14 29685b9b Stavros Sachtouris
#      provided with the distribution.
15 29685b9b Stavros Sachtouris
#
16 29685b9b Stavros Sachtouris
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 29685b9b Stavros Sachtouris
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 29685b9b Stavros Sachtouris
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 29685b9b Stavros Sachtouris
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 29685b9b Stavros Sachtouris
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 29685b9b Stavros Sachtouris
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 29685b9b Stavros Sachtouris
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 29685b9b Stavros Sachtouris
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 29685b9b Stavros Sachtouris
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 29685b9b Stavros Sachtouris
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 29685b9b Stavros Sachtouris
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 29685b9b Stavros Sachtouris
# POSSIBILITY OF SUCH DAMAGE.
28 29685b9b Stavros Sachtouris
#
29 29685b9b Stavros Sachtouris
# The views and conclusions contained in the software and
30 29685b9b Stavros Sachtouris
# documentation are those of the authors and should not be
31 29685b9b Stavros Sachtouris
# interpreted as representing official policies, either expressed
32 29685b9b Stavros Sachtouris
# or implied, of GRNET S.A.
33 29685b9b Stavros Sachtouris
34 29685b9b Stavros Sachtouris
from kamaki.clients.compute import ComputeClient
35 29685b9b Stavros Sachtouris
from kamaki.clients.utils import path4url
36 29685b9b Stavros Sachtouris
import json
37 29685b9b Stavros Sachtouris
38 29685b9b Stavros Sachtouris
39 29685b9b Stavros Sachtouris
class CycladesClientApi(ComputeClient):
40 29685b9b Stavros Sachtouris
    """GRNet Cyclades REST API Client"""
41 29685b9b Stavros Sachtouris
42 29685b9b Stavros Sachtouris
    def networks_get(self,
43 29685b9b Stavros Sachtouris
        network_id='', command='', success=(200, 203), **kwargs):
44 29685b9b Stavros Sachtouris
        """GET base_url/networks[/network_id][/command] request
45 29685b9b Stavros Sachtouris

46 29685b9b Stavros Sachtouris
        :param network_id: integer (str or int)
47 29685b9b Stavros Sachtouris

48 29685b9b Stavros Sachtouris
        :param command: (str) 'detail' or ''
49 29685b9b Stavros Sachtouris

50 29685b9b Stavros Sachtouris
        :param success: success code or list or tuple of accepted success
51 29685b9b Stavros Sachtouris
            codes. if server response code is not in this list, a ClientError
52 29685b9b Stavros Sachtouris
            raises
53 29685b9b Stavros Sachtouris

54 29685b9b Stavros Sachtouris
        :returns: request response
55 29685b9b Stavros Sachtouris
        """
56 29685b9b Stavros Sachtouris
        path = path4url('networks', network_id, command)
57 29685b9b Stavros Sachtouris
        return self.get(path, success=success, **kwargs)
58 29685b9b Stavros Sachtouris
59 29685b9b Stavros Sachtouris
    def networks_delete(self,
60 29685b9b Stavros Sachtouris
        network_id='', command='', success=204, **kwargs):
61 29685b9b Stavros Sachtouris
        """DEL ETE base_url/networks[/network_id][/command] request
62 29685b9b Stavros Sachtouris

63 29685b9b Stavros Sachtouris
        :param network_id: integer (str or int)
64 29685b9b Stavros Sachtouris

65 29685b9b Stavros Sachtouris
        :param command: (str) 'detail' or ''
66 29685b9b Stavros Sachtouris

67 29685b9b Stavros Sachtouris
        :param success: success code or list or tuple of accepted success
68 29685b9b Stavros Sachtouris
            codes. if server response code is not in this list, a ClientError
69 29685b9b Stavros Sachtouris
            raises
70 29685b9b Stavros Sachtouris

71 29685b9b Stavros Sachtouris
        :returns: request response
72 29685b9b Stavros Sachtouris
        """
73 29685b9b Stavros Sachtouris
        path = path4url('networks', network_id, command)
74 29685b9b Stavros Sachtouris
        return self.delete(path, success=success, **kwargs)
75 29685b9b Stavros Sachtouris
76 29685b9b Stavros Sachtouris
    def networks_post(self,
77 29685b9b Stavros Sachtouris
        network_id='', command='', json_data=None, success=202, **kwargs):
78 29685b9b Stavros Sachtouris
        """POST base_url/servers[/server_id]/[command] request
79 29685b9b Stavros Sachtouris

80 29685b9b Stavros Sachtouris
        :param network_id: integer (str or int)
81 29685b9b Stavros Sachtouris

82 29685b9b Stavros Sachtouris
        :param command: (str) 'detail' or ''
83 29685b9b Stavros Sachtouris

84 29685b9b Stavros Sachtouris
        :param json_data: (dict) will be send as data
85 29685b9b Stavros Sachtouris

86 29685b9b Stavros Sachtouris
        :param success: success code or list or tuple of accepted success
87 29685b9b Stavros Sachtouris
            codes. if server response code is not in this list, a ClientError
88 29685b9b Stavros Sachtouris
            raises
89 29685b9b Stavros Sachtouris

90 29685b9b Stavros Sachtouris
        :returns: request response
91 29685b9b Stavros Sachtouris
        """
92 29685b9b Stavros Sachtouris
        data = json_data
93 29685b9b Stavros Sachtouris
        if json_data is not None:
94 29685b9b Stavros Sachtouris
            data = json.dumps(json_data)
95 29685b9b Stavros Sachtouris
            self.set_header('Content-Type', 'application/json')
96 29685b9b Stavros Sachtouris
            self.set_header('Content-Length', len(data))
97 29685b9b Stavros Sachtouris
98 29685b9b Stavros Sachtouris
        path = path4url('networks', network_id, command)
99 29685b9b Stavros Sachtouris
        return self.post(path, data=data, success=success, **kwargs)
100 29685b9b Stavros Sachtouris
101 29685b9b Stavros Sachtouris
    def networks_put(self,
102 29685b9b Stavros Sachtouris
        network_id='', command='', json_data=None, success=204, **kwargs):
103 29685b9b Stavros Sachtouris
        """PUT base_url/servers[/server_id]/[command] request
104 29685b9b Stavros Sachtouris

105 29685b9b Stavros Sachtouris
        :param network_id: integer (str or int)
106 29685b9b Stavros Sachtouris

107 29685b9b Stavros Sachtouris
        :param command: (str) 'detail' or ''
108 29685b9b Stavros Sachtouris

109 29685b9b Stavros Sachtouris
        :param json_data: (dict) will be send as data
110 29685b9b Stavros Sachtouris

111 29685b9b Stavros Sachtouris
        :param success: success code or list or tuple of accepted success
112 29685b9b Stavros Sachtouris
            codes. if server response code is not in this list, a ClientError
113 29685b9b Stavros Sachtouris
            raises
114 29685b9b Stavros Sachtouris

115 29685b9b Stavros Sachtouris
        :returns: request response
116 29685b9b Stavros Sachtouris
        """
117 29685b9b Stavros Sachtouris
        data = json_data
118 29685b9b Stavros Sachtouris
        if json_data is not None:
119 29685b9b Stavros Sachtouris
            data = json.dumps(json_data)
120 29685b9b Stavros Sachtouris
            self.set_header('Content-Type', 'application/json')
121 29685b9b Stavros Sachtouris
            self.set_header('Content-Length', len(data))
122 29685b9b Stavros Sachtouris
123 29685b9b Stavros Sachtouris
        path = path4url('networks', network_id, command)
124 29685b9b Stavros Sachtouris
        return self.put(path, data=data, success=success, **kwargs)