Adds support force delete for NS.

This patch adds '--force' parameter to NS delete command, to delete NS
forcefully.

blueprint force-delete-resources

Change-Id: I7d8eb7ae63f9e43da37701e3e8312e650ea5bd3c
This commit is contained in:
dharmendra 2018-12-21 09:01:45 +00:00
parent 47996394b3
commit 1e280fb1fe
3 changed files with 31 additions and 3 deletions

View File

@ -156,18 +156,32 @@ class DeleteNS(command.Command):
nargs="+",
help=_("NS(s) to delete (name or ID)")
)
parser.add_argument(
'--force',
default=False,
action='store_true',
help=_('Force delete Network Service')
)
return parser
def args2body(self, parsed_args):
if parsed_args.force:
body = {_NS: {'attributes': {'force': True}}}
else:
body = dict()
return body
def take_action(self, parsed_args):
client = self.app.client_manager.tackerclient
failure = False
deleted_ids = []
failed_items = {}
body = self.args2body(parsed_args)
for resource_id in parsed_args.ns:
try:
obj = tackerV10.find_resourceid_by_name_or_id(
client, _NS, resource_id)
client.delete_ns(obj)
client.delete_ns(obj, body)
deleted_ids.append(resource_id)
except Exception as e:
failure = True

View File

@ -123,3 +123,17 @@ class DeleteNS(tackerV10.DeleteCommand):
resource = _NS
deleted_msg = {'ns': 'delete initiated'}
def add_known_arguments(self, parser):
parser.add_argument(
'--force',
default=False,
action='store_true',
help=_('Force delete Network Service'))
def args2body(self, parsed_args):
if parsed_args.force:
body = {self.resource: {'attributes': {'force': True}}}
else:
body = dict()
return body

View File

@ -665,8 +665,8 @@ class Client(ClientBase):
return self.post(self.nss_path, body=body)
@APIParamsCall
def delete_ns(self, ns):
return self.delete(self.ns_path % ns)
def delete_ns(self, ns, body=None):
return self.delete(self.ns_path % ns, body=body)
@APIParamsCall
def create_cluster(self, body=None):