From e82f56d898df84271b4bb55e7b702e3e5b148a82 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Thu, 3 May 2018 18:46:46 +0200 Subject: [PATCH] return http_code,data tuple in DELETE operations for sol005 client Change-Id: I2fd4b6bbf03d2c87edb2133da29ea9fae3ccecd9 Signed-off-by: garciadeblas --- osmclient/sol005/http.py | 8 ++------ osmclient/sol005/ns.py | 8 +++++--- osmclient/sol005/nsd.py | 8 +++++--- osmclient/sol005/sdncontroller.py | 14 +++++++++----- osmclient/sol005/vim.py | 7 +++++-- osmclient/sol005/vnfd.py | 8 +++++--- 6 files changed, 31 insertions(+), 22 deletions(-) diff --git a/osmclient/sol005/http.py b/osmclient/sol005/http.py index c89e91b..20593b8 100644 --- a/osmclient/sol005/http.py +++ b/osmclient/sol005/http.py @@ -50,13 +50,9 @@ class Http(http.Http): curl_cmd.close() # TODO 202 accepted should be returned somehow if data.getvalue(): - return json.loads(data.getvalue().decode()) - elif http_code == 404: - return "NOT FOUND" - elif http_code >= 300: - return "Failed" + return http_code, json.loads(data.getvalue().decode()) else: - return + return http_code, None def send_cmd(self, endpoint='', postfields_dict=None, formfile=None, filename=None, diff --git a/osmclient/sol005/ns.py b/osmclient/sol005/ns.py index 4b55cc2..590cdb1 100644 --- a/osmclient/sol005/ns.py +++ b/osmclient/sol005/ns.py @@ -75,9 +75,11 @@ class Ns(object): def delete(self, name): ns = self.get(name) - resp = self._http.delete_cmd('{}/{}'.format(self._apiBase,ns['_id'])) - # print 'RESP: {}'.format(resp) - if resp is None: + http_code, resp = self._http.delete_cmd('{}/{}'.format(self._apiBase,ns['_id'])) + #print 'RESP: {}'.format(resp) + if http_code == 202: + print 'Deletion in progress' + elif http_code == 204: print 'Deleted' else: raise ClientException("failed to delete ns {}: {}".format(name, resp)) diff --git a/osmclient/sol005/nsd.py b/osmclient/sol005/nsd.py index 3288e95..dac0adc 100644 --- a/osmclient/sol005/nsd.py +++ b/osmclient/sol005/nsd.py @@ -91,9 +91,11 @@ class Nsd(object): def delete(self, name): nsd = self.get(name) - resp = self._http.delete_cmd('{}/{}'.format(self._apiBase, nsd['_id'])) - #print 'RESP: '.format(resp) - if resp is None: + http_code, resp = self._http.delete_cmd('{}/{}'.format(self._apiBase, nsd['_id'])) + #print 'RESP: {}'.format(resp) + if http_code == 202: + print 'Deletion in progress' + elif http_code == 204: print 'Deleted' else: raise ClientException("failed to delete nsd {}: {}".format(name, resp)) diff --git a/osmclient/sol005/sdncontroller.py b/osmclient/sol005/sdncontroller.py index bc1f962..a7b9a47 100644 --- a/osmclient/sol005/sdncontroller.py +++ b/osmclient/sol005/sdncontroller.py @@ -47,12 +47,16 @@ class SdnController(object): def delete(self, name): sdn_controller = self.get(name) - resp = self._http.delete_cmd('{}/{}'.format(self._apiBase,sdn_controller['_id'])) - #print 'RESP: '.format(resp) - if 'result' not in resp: - raise ClientException("failed to delete vim {} - {}".format(name, resp)) - else: + http_code, resp = self._http.delete_cmd('{}/{}'.format(self._apiBase,sdn_controller['_id'])) + #print 'RESP: {}'.format(resp) + if http_code == 202: + print 'Deletion in progress' + elif http_code == 204: + print 'Deleted' + elif 'result' in resp: print 'Deleted' + else: + raise ClientException("failed to delete vim {} - {}".format(name, resp)) def list(self, filter=None): """Returns a list of SDN controllers diff --git a/osmclient/sol005/vim.py b/osmclient/sol005/vim.py index 8a0b11a..0dcc4ad 100644 --- a/osmclient/sol005/vim.py +++ b/osmclient/sol005/vim.py @@ -88,8 +88,11 @@ class Vim(object): vim_id = vim_name if not utils.validate_uuid4(vim_name): vim_id = self.get_id(vim_name) - resp = self._http.delete_cmd('{}/{}'.format(self._apiBase,vim_id)) - if resp is None: + http_code, resp = self._http.delete_cmd('{}/{}'.format(self._apiBase,vim_id)) + #print 'RESP: {}'.format(resp) + if http_code == 202: + print 'Deletion in progress' + elif http_code == 204: print 'Deleted' else: raise ClientException("failed to delete vim {} - {}".format(vim_name, resp)) diff --git a/osmclient/sol005/vnfd.py b/osmclient/sol005/vnfd.py index bc77a8d..28ded17 100644 --- a/osmclient/sol005/vnfd.py +++ b/osmclient/sol005/vnfd.py @@ -90,9 +90,11 @@ class Vnfd(object): def delete(self, name): vnfd = self.get(name) - resp = self._http.delete_cmd('{}/{}'.format(self._apiBase,vnfd['_id'])) - #print 'RESP: '.format(resp) - if resp is None: + http_code, resp = self._http.delete_cmd('{}/{}'.format(self._apiBase,vnfd['_id'])) + #print 'RESP: {}'.format(resp) + if http_code == 202: + print 'Deletion in progress' + elif http_code == 204: print 'Deleted' else: raise ClientException("failed to delete vnfd {}: {}".format(name, resp)) -- 2.25.1