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 a78fbbe..13494b8 100644 --- a/networkapiclient/ApiInterface.py +++ b/networkapiclient/ApiInterface.py @@ -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)) \ No newline at end of file + 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) \ No newline at end of file diff --git a/networkapiclient/__init__.py b/networkapiclient/__init__.py index e4d4bd9..7fc6caf 100644 --- a/networkapiclient/__init__.py +++ b/networkapiclient/__init__.py @@ -16,5 +16,5 @@ MAJOR_VERSION = '0' MINOR_VERSION = '8' -PATCH_VERSION = '8' +PATCH_VERSION = '9' VERSION = '.'.join((MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION,))