Statistics
| Branch: | Tag: | Revision:

root / kamaki / clients / network / rest_api.py @ 1ad949a7

History | View | Annotate | Download (3.9 kB)

1
# Copyright 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 import Client
35
from kamaki.clients.utils import path4url
36
from json import dumps
37

    
38

    
39
class NetworkRestClient(Client):
40

    
41
    def networks_get(self, network_id=None, **kwargs):
42
        if network_id:
43
            return self.get(path4url('networks', network_id), **kwargs)
44
        return self.get(path4url('networks'), **kwargs)
45

    
46
    def networks_post(self, json_data, **kwargs):
47
        return self.post(path4url('networks'), json=json_data, **kwargs)
48

    
49
    def networks_put(self, network_id, json_data, **kwargs):
50
        return self.put(
51
            path4url('networks', network_id), json=json_data, **kwargs)
52

    
53
    def networks_delete(self, network_id, **kwargs):
54
        return self.delete(path4url('networks', network_id), **kwargs)
55

    
56
    def subnets_get(self, subnet_id=None, **kwargs):
57
        if subnet_id:
58
            return self.get(path4url('subnets', subnet_id), **kwargs)
59
        return self.get(path4url('subnets'), **kwargs)
60

    
61
    def subnets_post(self, json_data, **kwargs):
62
        return self.post(path4url('subnets'), json=json_data, **kwargs)
63

    
64
    def subnets_put(self, subnet_id, **kwargs):
65
        return self.put(path4url('subnets', subnet_id), **kwargs)
66

    
67
    def subnets_delete(self, subnet_id, **kwargs):
68
        return self.delete(path4url('subnets', subnet_id), **kwargs)
69

    
70
    def ports_get(self, port_id=None, **kwargs):
71
        if port_id:
72
            return self.get(path4url('ports', port_id), **kwargs)
73
        return self.get(path4url('ports'), **kwargs)
74

    
75
    def ports_post(self, json_data=None, **kwargs):
76
        return self.post(path4url('ports'), json=json_data, **kwargs)
77

    
78
    def ports_put(self, port_id, json_data=None, **kwargs):
79
        return self.put(path4url('ports', port_id), json=json_data, **kwargs)
80

    
81
    def ports_delete(self, port_id, **kwargs):
82
        return self.delete(path4url('ports', port_id), **kwargs)
83

    
84
    #  floatingips (L3) extentions
85

    
86
    def floatingips_get(self, floatingip_id=None, **kwargs):
87
        return self.get(path4url('floatingips', floatingip_id or ''), **kwargs)
88

    
89
    def floatingips_post(self, json_data, **kwargs):
90
        return self.post(path4url('floatingips'), json=json_data, **kwargs)
91

    
92
    def floatingips_put(self, floatingip_id, json_data, **kwargs):
93
        return self.put(
94
            path4url('floatingips', floatingip_id), json=json_data, **kwargs)
95

    
96
    def floatingips_delete(self, floatingip_id, **kwargs):
97
        return self.delete(path4url('floatingips', floatingip_id), **kwargs)