Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
edersonbrilhante committed May 31, 2017
2 parents 0f6f866 + 1f0c006 commit 90afa88
Show file tree
Hide file tree
Showing 21 changed files with 3,838 additions and 26 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- id: check-yaml
- id: debug-statements
- id: name-tests-test
args: ['--django']
- id: fix-encoding-pragma
- id: requirements-txt-fixer
- id: double-quote-string-fixer
Expand Down
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:2.7

RUN mkdir /netapiclient
WORKDIR /netapiclient

ADD . /netapiclient/

CMD cd /netapiclient


RUN pip install -r requirements.txt
RUN pip install -r requirements_test.txt
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VERSION=$(shell python -c 'import networkapiclient; print networkapiclient.VERSI
PIP := $(shell which pip)

# GloboNetworkAPI project URL
GNETAPIURL := git@github.com:/globocom/GloboNetworkAPI
GNETAPIURL := https://github.com/globocom/GloboNetworkAPI.git

# Local path to GloboNetworkAPI used in tests
GNETAPI_PATH := networkapi_test_project
Expand Down Expand Up @@ -45,6 +45,24 @@ test:
@nosetests --rednose --nocapture --verbose --with-coverage --cover-erase \
--cover-package=networkapiclient --where tests

unit:
@make clean
@echo "Starting tests..."
@nosetests --rednose --nocapture --verbose --with-coverage --cover-erase \
--cover-package=networkapiclient --where tests/unit

integration:
@make clean
@echo "Starting tests..."
@nosetests --rednose --nocapture --verbose --with-coverage --cover-erase \
--cover-package=networkapiclient --where tests/integration

functional:
@make clean
@echo "Starting tests..."
@nosetests --rednose --nocapture --verbose --with-coverage --cover-erase \
--cover-package=networkapiclient --where tests/functional

setup: requirements.txt
$(PIP) install -r $^

Expand Down
85 changes: 79 additions & 6 deletions networkapiclient/ApiEnvironmentVip.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding:utf-8 -*-
# -*- coding: utf-8 -*-
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
Expand All @@ -13,8 +13,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from networkapiclient.ApiGenericClient import ApiGenericClient
from networkapiclient.utils import build_uri_with_ids


class ApiEnvironmentVip(ApiGenericClient):
Expand All @@ -35,12 +35,13 @@ def __init__(self, networkapi_url, user, password, user_ldap=None):

def get_environment_vip(self, environment_vip_id, fields=None):

uri = "api/v3/environment-vip/%s/" % environment_vip_id
uri = 'api/v3/environment-vip/%s/' % environment_vip_id

if fields:
uri += '?fields={}'.format(','.join(fields))

return self.get(uri)
return super(ApiEnvironmentVip, self).get(
uri)

def environmentvip_step(self, finality='', client='', environmentp44=''):
"""
Expand All @@ -54,6 +55,78 @@ def environmentvip_step(self, finality='', client='', environmentp44=''):
Return environment vip: when request has finality, client and environmentvip
"""

uri = "api/v3/environment-vip/step/?finality=%s&client=%s&environmentp44=%s" % (finality, client, environmentp44)
uri = 'api/v3/environment-vip/step/?finality=%s&client=%s&environmentp44=%s' % (
finality, client, environmentp44)

return super(ApiEnvironmentVip, self).get(
uri)

def search(self, **kwargs):
"""
Method to search environments vip based on extends search.
:param search: Dict containing QuerySets to find environments vip.
:param include: Array containing fields to include on response.
:param exclude: Array containing fields to exclude on response.
:param fields: Array containing fields to override default fields.
:param kind: Determine if result will be detailed ('detail')
or basic ('basic').
:return: Dict containing environments vip
"""

return super(ApiEnvironmentVip, self).get(
self.prepare_url('api/v3/environment-vip/', kwargs))

def get(self, ids, **kwargs):
"""
Method to get environments vip by their ids
:param ids: List containing identifiers of environments vip
:param include: Array containing fields to include on response.
:param exclude: Array containing fields to exclude on response.
:param fields: Array containing fields to override default fields.
:param kind: Determine if result will be detailed ('detail')
or basic ('basic').
:return: Dict containing environments vip
"""
uri = build_uri_with_ids('api/v3/environment-vip/%s/', ids)
return super(ApiEnvironmentVip, self).get(
self.prepare_url(uri, kwargs))

def delete(self, ids):
"""
Method to delete environments vip by their id's.
:param ids: Identifiers of environments vip
:return: None
"""
url = build_uri_with_ids('api/v3/environment-vip/%s/', ids)
return super(ApiEnvironmentVip, self).delete(url)

def update(self, environments):
"""
Method to update environments vip
:param environments vip: List containing environments vip desired
to updated
:return: None
"""

data = {'environments_vip': environments}
environments_ids = [str(env.get('id')) for env in environments]

uri = 'api/v3/environment-vip/%s/' % ';'.join(environments_ids)
return super(ApiEnvironmentVip, self).put(uri, data)

def create(self, environments):
"""
Method to create environments vip
:param environments vip: Dict containing environments vip desired
to be created on database
:return: None
"""

return self.get(uri)
data = {'environments_vip': environments}
uri = 'api/v3/environment-vip/'
return super(ApiEnvironmentVip, self).post(uri, data)
14 changes: 7 additions & 7 deletions networkapiclient/ApiIpv4.py → networkapiclient/ApiIPv4.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from networkapiclient.utils import build_uri_with_ids


class ApiIpv4(ApiGenericClient):
class ApiIPv4(ApiGenericClient):

def __init__(self, networkapi_url, user, password, user_ldap=None):
"""Class constructor receives parameters to connect to the networkAPI.
Expand All @@ -26,7 +26,7 @@ def __init__(self, networkapi_url, user, password, user_ldap=None):
:param password: Password for authentication.
"""

super(ApiIpv4, self).__init__(
super(ApiIPv4, self).__init__(
networkapi_url,
user,
password,
Expand All @@ -45,7 +45,7 @@ def search(self, **kwargs):
:return: Dict containing ipv4's
"""

return super(ApiIpv4, self).get(self.prepare_url('api/v3/ipv4/',
return super(ApiIPv4, self).get(self.prepare_url('api/v3/ipv4/',
kwargs))

def get(self, ids, **kwargs):
Expand All @@ -61,7 +61,7 @@ def get(self, ids, **kwargs):
"""
url = build_uri_with_ids('api/v3/ipv4/%s/', ids)

return super(ApiIpv4, self).get(self.prepare_url(url, kwargs))
return super(ApiIPv4, self).get(self.prepare_url(url, kwargs))

def delete(self, ids):
"""
Expand All @@ -72,7 +72,7 @@ def delete(self, ids):
"""
url = build_uri_with_ids('api/v3/ipv4/%s/', ids)

return super(ApiIpv4, self).delete(url)
return super(ApiIPv4, self).delete(url)

def update(self, ipv4s):
"""
Expand All @@ -85,7 +85,7 @@ def update(self, ipv4s):
data = {'ips': ipv4s}
ipv4s_ids = [str(ipv4.get('id')) for ipv4 in ipv4s]

return super(ApiIpv4, self).put('api/v3/ipv4/%s/' %
return super(ApiIPv4, self).put('api/v3/ipv4/%s/' %
';'.join(ipv4s_ids), data)

def create(self, ipv4s):
Expand All @@ -97,4 +97,4 @@ def create(self, ipv4s):
"""

data = {'ips': ipv4s}
return super(ApiIpv4, self).post('api/v3/ipv4/', data)
return super(ApiIPv4, self).post('api/v3/ipv4/', data)
14 changes: 7 additions & 7 deletions networkapiclient/ApiIpv6.py → networkapiclient/ApiIPv6.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from networkapiclient.utils import build_uri_with_ids


class ApiIpv6(ApiGenericClient):
class ApiIPv6(ApiGenericClient):

def __init__(self, networkapi_url, user, password, user_ldap=None):
"""Class constructor receives parameters to connect to the networkAPI.
Expand All @@ -26,7 +26,7 @@ def __init__(self, networkapi_url, user, password, user_ldap=None):
:param password: Password for authentication.
"""

super(ApiIpv6, self).__init__(
super(ApiIPv6, self).__init__(
networkapi_url,
user,
password,
Expand All @@ -45,7 +45,7 @@ def search(self, **kwargs):
:return: Dict containing ipv6's
"""

return super(ApiIpv6, self).get(self.prepare_url('api/v3/ipv6/',
return super(ApiIPv6, self).get(self.prepare_url('api/v3/ipv6/',
kwargs))

def get(self, ids, **kwargs):
Expand All @@ -60,7 +60,7 @@ def get(self, ids, **kwargs):
:return: Dict containing ipv6's
"""
url = build_uri_with_ids('api/v3/ipv6/%s/', ids)
return super(ApiIpv6, self).get(self.prepare_url(url, kwargs))
return super(ApiIPv6, self).get(self.prepare_url(url, kwargs))

def delete(self, ids):
"""
Expand All @@ -70,7 +70,7 @@ def delete(self, ids):
:return: None
"""
url = build_uri_with_ids('api/v3/ipv6/%s/', ids)
return super(ApiIpv6, self).delete(url)
return super(ApiIPv6, self).delete(url)

def update(self, ipv6s):
"""
Expand All @@ -83,7 +83,7 @@ def update(self, ipv6s):
data = {'ips': ipv6s}
ipv6s_ids = [str(ipv6.get('id')) for ipv6 in ipv6s]

return super(ApiIpv6, self).put('api/v3/ipv6/%s/' %
return super(ApiIPv6, self).put('api/v3/ipv6/%s/' %
';'.join(ipv6s_ids), data)

def create(self, ipv6s):
Expand All @@ -95,4 +95,4 @@ def create(self, ipv6s):
"""

data = {'ips': ipv6s}
return super(ApiIpv6, self).post('api/v3/ipv6/', data)
return super(ApiIPv6, self).post('api/v3/ipv6/', data)
98 changes: 98 additions & 0 deletions networkapiclient/ApiObjectGroupPermission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# -*- coding: utf-8 -*-
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from networkapiclient.ApiGenericClient import ApiGenericClient
from networkapiclient.utils import build_uri_with_ids


class ApiObjectGroupPermission(ApiGenericClient):

def __init__(self, networkapi_url, user, password, user_ldap=None):
"""Class constructor receives parameters to connect to the networkAPI.
:param networkapi_url: URL to access the network API.
:param user: User for authentication.
:param password: Password for authentication.
"""

super(ApiObjectGroupPermission, self).__init__(
networkapi_url,
user,
password,
user_ldap
)

def search(self, **kwargs):
"""
Method to search object group permissions based on extends search.
:param search: Dict containing QuerySets to find object group permissions.
:param include: Array containing fields to include on response.
:param exclude: Array containing fields to exclude on response.
:param fields: Array containing fields to override default fields.
:param kind: Determine if result will be detailed ('detail') or basic ('basic').
:return: Dict containing object group permissions
"""

return super(ApiObjectGroupPermission, self).get(self.prepare_url('api/v3/object-group-perm/',
kwargs))

def get(self, ids, **kwargs):
"""
Method to get object group permissions by their ids
:param ids: List containing identifiers of object group permissions
:param include: Array containing fields to include on response.
:param exclude: Array containing fields to exclude on response.
:param fields: Array containing fields to override default fields.
:param kind: Determine if result will be detailed ('detail') or basic ('basic').
:return: Dict containing object group permissions
"""
url = build_uri_with_ids('api/v3/object-group-perm/%s/', ids)
return super(ApiObjectGroupPermission, self).get(self.prepare_url(url, kwargs))

def delete(self, ids):
"""
Method to delete object group permissions by their ids
:param ids: Identifiers of object group permissions
:return: None
"""
url = build_uri_with_ids('api/v3/object-group-perm/%s/', ids)
return super(ApiObjectGroupPermission, self).delete(url)

def update(self, ogps):
"""
Method to update object group permissions
:param ogps: List containing object group permissions desired to updated
:return: None
"""

data = {'ogps': ogps}
ogps_ids = [str(ogp.get('id')) for ogp in ogps]

return super(ApiObjectGroupPermission, self).put('api/v3/object-group-perm/%s/' %
';'.join(ogps_ids), data)

def create(self, ogps):
"""
Method to create object group permissions
:param ogps: List containing vrf desired to be created on database
:return: None
"""

data = {'ogps': ogps}
return super(ApiObjectGroupPermission, self).post('api/v3/object-group-perm/', data)
Loading

0 comments on commit 90afa88

Please sign in to comment.