Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ederson.brilhante committed May 29, 2018
2 parents f1da44e + 0aa98b4 commit 2eaea74
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 58 deletions.
15 changes: 9 additions & 6 deletions networkapiclient/ApiGenericClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def get(self, uri):
@raise NetworkAPIClientError: Client failed to access the API.
"""
request = None

try:

request = requests.get(
Expand All @@ -79,12 +81,13 @@ def get(self, uri):
raise NetworkAPIClientError(error.get('detail', ''))
finally:
self.logger.info('URI: %s', uri)
self.logger.info('Status Code: %s',
request.status_code if request else '')
self.logger.info('X-Request-Id: %s',
request.headers.get('x-request-id'))
self.logger.info('X-Request-Context: %s',
request.headers.get('x-request-context'))
if request:
self.logger.info('Status Code: %s',
request.status_code if request else '')
self.logger.info('X-Request-Id: %s',
request.headers.get('x-request-id'))
self.logger.info('X-Request-Context: %s',
request.headers.get('x-request-context'))

def post(self, uri, data=None, files=None):
"""
Expand Down
133 changes: 82 additions & 51 deletions networkapiclient/ApiInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,75 +19,106 @@


class ApiInterfaceRequest(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.
"""
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(ApiInterfaceRequest, self).__init__(
networkapi_url,
user,
password,
user_ldap
)
super(ApiInterfaceRequest, self).__init__(
networkapi_url,
user,
password,
user_ldap
)

def deploy_interface_config_sync(self, interface_id):
"""
"""
def deploy_interface_config_sync(self, interface_id):
"""
"""

uri = "api/interface/%s/deploy_config_sync/" % (interface_id)
uri = "api/interface/%s/deploy_config_sync/" % interface_id

data = dict()
data = dict()

return self.put(uri, data)
return self.put(uri, data)

def deploy_channel_config_sync(self, channel_id):
"""
"""
def deploy_channel_config_sync(self, channel_id):
"""
"""

uri = "api/interface/channel/%s/deploy_config_sync/" % (channel_id)
uri = "api/interface/channel/%s/deploy_config_sync/" % channel_id

data = dict()
data = dict()

return self.put(uri, data)
return self.put(uri, data)

def remove_connection(self, interface1, interface2):
"""Remove a connection between two interfaces"""
def remove_connection(self, interface1, interface2):
"""Remove a connection between two interfaces"""

uri = "api/interface/disconnect/%s/%s/" % (interface1, interface2)
uri = "api/interface/disconnect/%s/%s/" % (interface1, interface2)

return self.delete(uri)
return self.delete(uri)

def search(self, **kwargs):
"""
Method to search interfaces based on extends search.
:return: Dict containing interfaces.
"""

def search(self, **kwargs):
"""
Method to search interfaces based on extends search.
return super(ApiInterfaceRequest, self).get(self.prepare_url('api/v3/interface/', kwargs))

:param search: Dict containing QuerySets to find interfaces.
: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 ('details') or basic ('basic').
:return: Dict containing equipments
"""
def get(self, ids, **kwargs):
"""
Method to get interfaces by their ids.
:param ids: List containing identifiers of interfaces.
:return: Dict containing interfaces.
"""

return super(ApiInterfaceRequest, self).get(self.prepare_url('api/v3/interface/', kwargs))
url = build_uri_with_ids('api/v3/interface/%s/', ids)

return super(ApiInterfaceRequest, self).get(self.prepare_url(url, kwargs))

def get(self, ids, **kwargs):
"""
Method to get environments by their ids
def remove(self, ids, **kwargs):
"""
Method to delete interface by id.
:param ids: List containing identifiers of interfaces.
"""
url = build_uri_with_ids('api/v3/interface/%s/', ids)

:param ids: List containing identifiers of environments
: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
"""
return super(ApiInterfaceRequest, self).delete(self.prepare_url(url, kwargs))

url = build_uri_with_ids('api/v3/interface/%s/', ids)
def create(self, interface):
"""
Method to add an interface.
:param interface: List containing interface's desired to be created on database.
:return: Id.
"""

return super(ApiInterfaceRequest, self).get(self.prepare_url(url, kwargs))
data = {'interfaces': interface}
return super(ApiInterfaceRequest, self).post('api/v3/interface/', data)

def get_interface_type(self, ids=None, **kwargs):
"""
Method to get interfaces by their ids.
:param ids: List containing identifiers of interfaces.
:return: Dict containing interfaces.git
"""

url = 'api/v3/interfacetype/'

if ids:
url = build_uri_with_ids(url, ids)

return super(ApiInterfaceRequest, self).get(self.prepare_url(url, kwargs))

def update(self, interfaces=None):
"""
Method to update interface.
:param ids: List containing interface's desired to be updated on database.
:return: None.
"""

data = {'interfaces': interfaces}

return super(ApiInterfaceRequest, self).put('api/v3/interface/', data)
2 changes: 1 addition & 1 deletion networkapiclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@

MAJOR_VERSION = '0'
MINOR_VERSION = '8'
PATCH_VERSION = '8'
PATCH_VERSION = '9'
VERSION = '.'.join((MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION,))

0 comments on commit 2eaea74

Please sign in to comment.