Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (4.6 kB)

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 networks_get(self,
43
        network_id='', command='', success=(200, 203), **kwargs):
44
        """GET base_url/networks[/network_id][/command] request
45

46
        :param network_id: integer (str or int)
47

48
        :param command: (str) 'detail' or ''
49

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

54
        :returns: request response
55
        """
56
        path = path4url('networks', network_id, command)
57
        return self.get(path, success=success, **kwargs)
58

    
59
    def networks_delete(self,
60
        network_id='', command='', success=204, **kwargs):
61
        """DEL ETE base_url/networks[/network_id][/command] request
62

63
        :param network_id: integer (str or int)
64

65
        :param command: (str) 'detail' or ''
66

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

71
        :returns: request response
72
        """
73
        path = path4url('networks', network_id, command)
74
        return self.delete(path, success=success, **kwargs)
75

    
76
    def networks_post(self,
77
        network_id='', command='', json_data=None, success=202, **kwargs):
78
        """POST base_url/servers[/server_id]/[command] request
79

80
        :param network_id: integer (str or int)
81

82
        :param command: (str) 'detail' or ''
83

84
        :param json_data: (dict) will be send as data
85

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

90
        :returns: request response
91
        """
92
        data = json_data
93
        if json_data is not None:
94
            data = json.dumps(json_data)
95
            self.set_header('Content-Type', 'application/json')
96
            self.set_header('Content-Length', len(data))
97

    
98
        path = path4url('networks', network_id, command)
99
        return self.post(path, data=data, success=success, **kwargs)
100

    
101
    def networks_put(self,
102
        network_id='', command='', json_data=None, success=204, **kwargs):
103
        """PUT base_url/servers[/server_id]/[command] request
104

105
        :param network_id: integer (str or int)
106

107
        :param command: (str) 'detail' or ''
108

109
        :param json_data: (dict) will be send as data
110

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

115
        :returns: request response
116
        """
117
        data = json_data
118
        if json_data is not None:
119
            data = json.dumps(json_data)
120
            self.set_header('Content-Type', 'application/json')
121
            self.set_header('Content-Length', len(data))
122

    
123
        path = path4url('networks', network_id, command)
124
        return self.put(path, data=data, success=success, **kwargs)