From: garciadeblas Date: Wed, 16 May 2018 15:21:59 +0000 (+0200) Subject: new --force option for xxx-delete commands in sol005 client X-Git-Tag: v4.0.0~6 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=6d10e04620f3985e23dcce03d366f5734ba72a7c;p=osm%2Fosmclient.git new --force option for xxx-delete commands in sol005 client Change-Id: Ib593840025e2e7cdf91a9c181deb9dc67f895b49 Signed-off-by: garciadeblas --- diff --git a/osmclient/scripts/osm.py b/osmclient/scripts/osm.py index 1fc824e..570ad8c 100755 --- a/osmclient/scripts/osm.py +++ b/osmclient/scripts/osm.py @@ -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) diff --git a/osmclient/sol005/ns.py b/osmclient/sol005/ns.py index ebb779c..9ce1fcd 100644 --- a/osmclient/sol005/ns.py +++ b/osmclient/sol005/ns.py @@ -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) diff --git a/osmclient/sol005/nsd.py b/osmclient/sol005/nsd.py index 055d2e5..ef9e5ab 100644 --- a/osmclient/sol005/nsd.py +++ b/osmclient/sol005/nsd.py @@ -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) diff --git a/osmclient/sol005/sdncontroller.py b/osmclient/sol005/sdncontroller.py index 7833fbd..b11eb06 100644 --- a/osmclient/sol005/sdncontroller.py +++ b/osmclient/sol005/sdncontroller.py @@ -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) diff --git a/osmclient/sol005/vim.py b/osmclient/sol005/vim.py index dca8444..ec1ccad 100644 --- a/osmclient/sol005/vim.py +++ b/osmclient/sol005/vim.py @@ -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) diff --git a/osmclient/sol005/vnfd.py b/osmclient/sol005/vnfd.py index dd12096..c903f93 100644 --- a/osmclient/sol005/vnfd.py +++ b/osmclient/sol005/vnfd.py @@ -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)