Statistics
| Branch: | Tag: | Revision:

root / kamaki / clients / network / __init__.py @ 058ee9a8

History | View | Annotate | Download (2.1 kB)

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