return http_code,data tuple in DELETE operations for sol005 client 66/6066/1
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Thu, 3 May 2018 16:46:46 +0000 (18:46 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Thu, 3 May 2018 16:46:46 +0000 (18:46 +0200)
Change-Id: I2fd4b6bbf03d2c87edb2133da29ea9fae3ccecd9
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osmclient/sol005/http.py
osmclient/sol005/ns.py
osmclient/sol005/nsd.py
osmclient/sol005/sdncontroller.py
osmclient/sol005/vim.py
osmclient/sol005/vnfd.py

index c89e91b..20593b8 100644 (file)
@@ -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,
index 4b55cc2..590cdb1 100644 (file)
@@ -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))
index 3288e95..dac0adc 100644 (file)
@@ -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))
index bc1f962..a7b9a47 100644 (file)
@@ -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
index 8a0b11a..0dcc4ad 100644 (file)
@@ -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))
index bc77a8d..28ded17 100644 (file)
@@ -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))