From 2af8a8a76815dfbeafc7a45ba0ae6350c0b60e8d Mon Sep 17 00:00:00 2001 From: laurapanzariello Date: Fri, 18 May 2018 11:00:05 -0300 Subject: [PATCH 1/5] Delete interface using v3 --- networkapiclient/ApiInterface.py | 102 +++++++++++++++---------------- 1 file changed, 49 insertions(+), 53 deletions(-) diff --git a/networkapiclient/ApiInterface.py b/networkapiclient/ApiInterface.py index a78fbbe..639cd42 100644 --- a/networkapiclient/ApiInterface.py +++ b/networkapiclient/ApiInterface.py @@ -19,75 +19,71 @@ 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 - """ - - url = build_uri_with_ids('api/v3/interface/%s/', ids) - - return super(ApiInterfaceRequest, self).get(self.prepare_url(url, kwargs)) \ No newline at end of file + return super(ApiInterfaceRequest, self).delete(self.prepare_url(url, kwargs)) From 05023ade7e4f08a2668ed30e69d678a0ae1ed32d Mon Sep 17 00:00:00 2001 From: laurapanzariello Date: Fri, 18 May 2018 11:27:42 -0300 Subject: [PATCH 2/5] update version --- networkapiclient/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/networkapiclient/__init__.py b/networkapiclient/__init__.py index c3e2d1b..f2a33bc 100644 --- a/networkapiclient/__init__.py +++ b/networkapiclient/__init__.py @@ -16,5 +16,5 @@ MAJOR_VERSION = '0' MINOR_VERSION = '8' -PATCH_VERSION = '5' +PATCH_VERSION = '6' VERSION = '.'.join((MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION,)) From 49472b2f1af735871abf3ae7ad1d84a9e9daa883 Mon Sep 17 00:00:00 2001 From: laurapanzariello Date: Tue, 22 May 2018 14:41:25 -0300 Subject: [PATCH 3/5] create interface using v3 and get interface types using v3 --- networkapiclient/ApiInterface.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/networkapiclient/ApiInterface.py b/networkapiclient/ApiInterface.py index 639cd42..11b75c3 100644 --- a/networkapiclient/ApiInterface.py +++ b/networkapiclient/ApiInterface.py @@ -87,3 +87,27 @@ def remove(self, ids, **kwargs): url = build_uri_with_ids('api/v3/interface/%s/', ids) return super(ApiInterfaceRequest, self).delete(self.prepare_url(url, kwargs)) + + def create(self, interface): + """ + Method to add an interface. + :param interface: List containing interface's desired to be created on database. + :return: Id. + """ + + 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)) From eaf84b9208446b59bdc77d67d49e8f3a13281702 Mon Sep 17 00:00:00 2001 From: laurapanzariello Date: Tue, 22 May 2018 14:43:50 -0300 Subject: [PATCH 4/5] update version --- networkapiclient/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/networkapiclient/__init__.py b/networkapiclient/__init__.py index f2a33bc..55136ad 100644 --- a/networkapiclient/__init__.py +++ b/networkapiclient/__init__.py @@ -16,5 +16,5 @@ MAJOR_VERSION = '0' MINOR_VERSION = '8' -PATCH_VERSION = '6' +PATCH_VERSION = '7' VERSION = '.'.join((MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION,)) From 0aa98b4207ca1db4e2a6f2887936e517aadb83e9 Mon Sep 17 00:00:00 2001 From: laurapanzariello Date: Tue, 29 May 2018 14:53:28 -0300 Subject: [PATCH 5/5] create put method to ApiInterface --- networkapiclient/ApiGenericClient.py | 15 +++++++++------ networkapiclient/ApiInterface.py | 13 ++++++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/networkapiclient/ApiGenericClient.py b/networkapiclient/ApiGenericClient.py index 73dae98..0b9efbc 100644 --- a/networkapiclient/ApiGenericClient.py +++ b/networkapiclient/ApiGenericClient.py @@ -61,6 +61,8 @@ def get(self, uri): @raise NetworkAPIClientError: Client failed to access the API. """ + request = None + try: request = requests.get( @@ -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): """ diff --git a/networkapiclient/ApiInterface.py b/networkapiclient/ApiInterface.py index 11b75c3..13494b8 100644 --- a/networkapiclient/ApiInterface.py +++ b/networkapiclient/ApiInterface.py @@ -102,7 +102,7 @@ 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 + :return: Dict containing interfaces.git """ url = 'api/v3/interfacetype/' @@ -111,3 +111,14 @@ def get_interface_type(self, ids=None, **kwargs): 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) \ No newline at end of file