new --force option for xxx-delete commands in sol005 client 57/6157/1
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Wed, 16 May 2018 15:21:59 +0000 (17:21 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Wed, 16 May 2018 15:21:59 +0000 (17:21 +0200)
Change-Id: Ib593840025e2e7cdf91a9c181deb9dc67f895b49
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osmclient/scripts/osm.py
osmclient/sol005/ns.py
osmclient/sol005/nsd.py
osmclient/sol005/sdncontroller.py
osmclient/sol005/vim.py
osmclient/sol005/vnfd.py

index 1fc824e..570ad8c 100755 (executable)
@@ -687,9 +687,13 @@ def vnfd_update2(ctx, name, content):
 # DELETE operations
 ####################
 
-def nsd_delete(ctx, name):
+def nsd_delete(ctx, name, force):
     try:
-        ctx.obj.nsd.delete(name)
+        if not force:
+            ctx.obj.nsd.delete(name)
+        else:
+            check_client_version(ctx.obj, '--force')
+            ctx.obj.nsd.delete(name, force)
     except ClientException as inst:
         print(inst.message)
         exit(1)
@@ -697,29 +701,35 @@ def nsd_delete(ctx, name):
 
 @cli.command(name='nsd-delete', short_help='deletes a NSD/NSpkg')
 @click.argument('name')
+@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
 @click.pass_context
-def nsd_delete1(ctx, name):
+def nsd_delete1(ctx, name, force):
     '''deletes a NSD/NSpkg
 
     NAME: name or ID of the NSD/NSpkg to be deleted
     '''
-    nsd_delete(ctx, name)
+    nsd_delete(ctx, name, force)
 
 
 @cli.command(name='nspkg-delete', short_help='deletes a NSD/NSpkg')
 @click.argument('name')
+@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
 @click.pass_context
-def nsd_delete2(ctx, name):
+def nsd_delete2(ctx, name, force):
     '''deletes a NSD/NSpkg
 
     NAME: name or ID of the NSD/NSpkg to be deleted
     '''
-    nsd_delete(ctx, name)
+    nsd_delete(ctx, name, force)
 
 
-def vnfd_delete(ctx, name):
+def vnfd_delete(ctx, name, force):
     try:
-        ctx.obj.vnfd.delete(name)
+        if not force:
+            ctx.obj.vnfd.delete(name)
+        else:
+            check_client_version(ctx.obj, '--force')
+            ctx.obj.vnfd.delete(name, force)
     except ClientException as inst:
         print(inst.message)
         exit(1)
@@ -727,36 +737,43 @@ def vnfd_delete(ctx, name):
 
 @cli.command(name='vnfd-delete', short_help='deletes a VNFD/VNFpkg')
 @click.argument('name')
+@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
 @click.pass_context
-def vnfd_delete1(ctx, name):
+def vnfd_delete1(ctx, name, force):
     '''deletes a VNFD/VNFpkg
 
     NAME: name or ID of the VNFD/VNFpkg to be deleted
     '''
-    vnfd_delete(ctx, name)
+    vnfd_delete(ctx, name, force)
 
 
 @cli.command(name='vnfpkg-delete', short_help='deletes a VNFD/VNFpkg')
 @click.argument('name')
+@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
 @click.pass_context
-def vnfd_delete2(ctx, name):
+def vnfd_delete2(ctx, name, force):
     '''deletes a VNFD/VNFpkg
 
     NAME: name or ID of the VNFD/VNFpkg to be deleted
     '''
-    vnfd_delete(ctx, name)
+    vnfd_delete(ctx, name, force)
 
 
 @cli.command(name='ns-delete', short_help='deletes a NS instance')
 @click.argument('name')
+@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
 @click.pass_context
-def ns_delete(ctx, name):
+def ns_delete(ctx, name, force):
     '''deletes a NS instance
 
     NAME: name or ID of the NS instance to be deleted
     '''
     try:
-        ctx.obj.ns.delete(name)
+        if not force:
+            ctx.obj.ns.delete(name)
+        else:
+            check_client_version(ctx.obj, '--force')
+            ctx.obj.ns.delete(name, force)
     except ClientException as inst:
         print(inst.message)
         exit(1)
@@ -865,14 +882,19 @@ def vim_update(ctx,
 
 @cli.command(name='vim-delete')
 @click.argument('name')
+@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
 @click.pass_context
-def vim_delete(ctx, name):
+def vim_delete(ctx, name, force):
     '''deletes a VIM account
 
     NAME: name or ID of the VIM account to be deleted
     '''
     try:
-        ctx.obj.vim.delete(name)
+        if not force:
+            ctx.obj.vim.delete(name)
+        else:
+            check_client_version(ctx.obj, '--force')
+            ctx.obj.vim.delete(name, force)
     except ClientException as inst:
         print(inst.message)
         exit(1)
@@ -1047,15 +1069,16 @@ def sdnc_update(ctx,
 
 @cli.command(name='sdnc-delete')
 @click.argument('name')
+@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
 @click.pass_context
-def sdnc_delete(ctx, name):
+def sdnc_delete(ctx, name, force):
     '''deletes an SDN controller
 
     NAME: name or ID of the SDN controller to be deleted
     '''
     try:
         check_client_version(ctx.obj, ctx.command.name)
-        ctx.obj.sdnc.delete(name)
+        ctx.obj.sdnc.delete(name, force)
     except ClientException as inst:
         print(inst.message)
         exit(1)
index ebb779c..9ce1fcd 100644 (file)
@@ -74,9 +74,13 @@ class Ns(object):
             return resp
         raise NotFound("ns {} not found".format(name))
 
-    def delete(self, name):
+    def delete(self, name, force=False):
         ns = self.get(name)
-        http_code, resp = self._http.delete_cmd('{}/{}'.format(self._apiBase,ns['_id']))
+        querystring = ''
+        if force:
+            querystring = '?FORCE=True'
+        http_code, resp = self._http.delete_cmd('{}/{}{}'.format(self._apiBase,
+                                         ns['_id'], querystring))
         if resp:
             resp = json.loads(resp)
         #print 'RESP: {}'.format(resp)
index 055d2e5..ef9e5ab 100644 (file)
@@ -90,9 +90,13 @@ class Nsd(object):
     def get_artifact(self, name, artifact, filename):
         self.get_thing(name, 'artifacts/{}'.format(artifact), filename)
 
-    def delete(self, name):
+    def delete(self, name, force=False):
         nsd = self.get(name)
-        http_code, resp = self._http.delete_cmd('{}/{}'.format(self._apiBase, nsd['_id']))
+        querystring = ''
+        if force:
+            querystring = '?FORCE=True'
+        http_code, resp = self._http.delete_cmd('{}/{}{}'.format(self._apiBase,
+                                         nsd['_id'], querystring))
         if resp:
             resp = json.loads(resp)
         #print 'RESP: {}'.format(resp)
index 7833fbd..b11eb06 100644 (file)
@@ -59,9 +59,13 @@ class SdnController(object):
         else:
             print resp['id']
 
-    def delete(self, name):
+    def delete(self, name, force=False):
         sdn_controller = self.get(name)
-        http_code, resp = self._http.delete_cmd('{}/{}'.format(self._apiBase,sdn_controller['_id']))
+        querystring = ''
+        if force:
+            querystring = '?FORCE=True'
+        http_code, resp = self._http.delete_cmd('{}/{}{}'.format(self._apiBase,
+                                         sdn_controller['_id'], querystring))
         if resp:
             resp = json.loads(resp)
         #print 'RESP: {}'.format(resp)
index dca8444..ec1ccad 100644 (file)
@@ -90,11 +90,15 @@ class Vim(object):
                 return vim['uuid']
         raise NotFound("vim {} not found".format(name))
 
-    def delete(self, vim_name):
+    def delete(self, vim_name, force=False):
         vim_id = vim_name
         if not utils.validate_uuid4(vim_name):
             vim_id = self.get_id(vim_name)
-        http_code, resp = self._http.delete_cmd('{}/{}'.format(self._apiBase,vim_id))
+        querystring = ''
+        if force:
+            querystring = '?FORCE=True'
+        http_code, resp = self._http.delete_cmd('{}/{}{}'.format(self._apiBase,
+                                         vim_id, querystring))
         if resp:
             resp = json.loads(resp)
         #print 'RESP: {}'.format(resp)
index dd12096..c903f93 100644 (file)
@@ -89,9 +89,13 @@ class Vnfd(object):
     def get_artifact(self, name, artifact, filename):
         self.get_thing(name, 'artifacts/{}'.format(artifact), filename)
 
-    def delete(self, name):
+    def delete(self, name, force=False):
         vnfd = self.get(name)
-        http_code, resp = self._http.delete_cmd('{}/{}'.format(self._apiBase,vnfd['_id']))
+        querystring = ''
+        if force:
+            querystring = '?FORCE=True'
+        http_code, resp = self._http.delete_cmd('{}/{}{}'.format(self._apiBase,
+                                         vnfd['_id'], querystring))
         if resp:
             resp = json.loads(resp)
         #print 'RESP: {}'.format(resp)