Merge "Adds support force delete resources"
This commit is contained in:
commit
f4839f308a
@ -189,18 +189,32 @@ class DeleteVNF(command.Command):
|
|||||||
metavar="<VNF>",
|
metavar="<VNF>",
|
||||||
nargs="+",
|
nargs="+",
|
||||||
help=_("VNF(s) to delete (name or ID)"))
|
help=_("VNF(s) to delete (name or ID)"))
|
||||||
|
parser.add_argument(
|
||||||
|
'--force',
|
||||||
|
default=False,
|
||||||
|
action='store_true',
|
||||||
|
help=_('Force delete VNF instance'))
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
def args2body(self, parsed_args):
|
||||||
|
body = dict()
|
||||||
|
if parsed_args.force:
|
||||||
|
body[_VNF] = dict()
|
||||||
|
body[_VNF]['attributes'] = dict()
|
||||||
|
body[_VNF]['attributes']['force'] = True
|
||||||
|
return body
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
client = self.app.client_manager.tackerclient
|
client = self.app.client_manager.tackerclient
|
||||||
failure = False
|
failure = False
|
||||||
deleted_ids = []
|
deleted_ids = []
|
||||||
failed_items = {}
|
failed_items = {}
|
||||||
|
body = self.args2body(parsed_args)
|
||||||
for resource_id in parsed_args.vnf:
|
for resource_id in parsed_args.vnf:
|
||||||
try:
|
try:
|
||||||
obj = tackerV10.find_resourceid_by_name_or_id(
|
obj = tackerV10.find_resourceid_by_name_or_id(
|
||||||
client, _VNF, resource_id)
|
client, _VNF, resource_id)
|
||||||
client.delete_vnf(obj)
|
client.delete_vnf(obj, body)
|
||||||
deleted_ids.append(resource_id)
|
deleted_ids.append(resource_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
failure = True
|
failure = True
|
||||||
|
@ -520,6 +520,7 @@ class DeleteCommand(TackerCommand):
|
|||||||
'ids', nargs='+',
|
'ids', nargs='+',
|
||||||
metavar=self.resource.upper(),
|
metavar=self.resource.upper(),
|
||||||
help=help_str % self.resource)
|
help=help_str % self.resource)
|
||||||
|
self.add_known_arguments(parser)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def run(self, parsed_args):
|
def run(self, parsed_args):
|
||||||
@ -530,6 +531,8 @@ class DeleteCommand(TackerCommand):
|
|||||||
tacker_client.format = parsed_args.request_format
|
tacker_client.format = parsed_args.request_format
|
||||||
obj_deleter = getattr(tacker_client,
|
obj_deleter = getattr(tacker_client,
|
||||||
"delete_%s" % self.resource)
|
"delete_%s" % self.resource)
|
||||||
|
body = self.args2body(parsed_args)
|
||||||
|
|
||||||
for resource_id in parsed_args.ids:
|
for resource_id in parsed_args.ids:
|
||||||
try:
|
try:
|
||||||
if self.allow_names:
|
if self.allow_names:
|
||||||
@ -537,7 +540,10 @@ class DeleteCommand(TackerCommand):
|
|||||||
tacker_client, self.resource, resource_id)
|
tacker_client, self.resource, resource_id)
|
||||||
else:
|
else:
|
||||||
_id = resource_id
|
_id = resource_id
|
||||||
obj_deleter(_id)
|
if body:
|
||||||
|
obj_deleter(_id, body)
|
||||||
|
else:
|
||||||
|
obj_deleter(_id)
|
||||||
deleted_ids.append(resource_id)
|
deleted_ids.append(resource_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
failure = True
|
failure = True
|
||||||
|
@ -179,8 +179,23 @@ class DeleteVNF(tackerV10.DeleteCommand):
|
|||||||
"""Delete given VNF(s)."""
|
"""Delete given VNF(s)."""
|
||||||
|
|
||||||
resource = _VNF
|
resource = _VNF
|
||||||
|
remove_output_fields = ["attributes"]
|
||||||
deleted_msg = {'vnf': 'delete initiated'}
|
deleted_msg = {'vnf': 'delete initiated'}
|
||||||
|
|
||||||
|
def add_known_arguments(self, parser):
|
||||||
|
parser.add_argument(
|
||||||
|
'--force',
|
||||||
|
default=False,
|
||||||
|
action='store_true',
|
||||||
|
help=_('Force delete VNF instance'))
|
||||||
|
|
||||||
|
def args2body(self, parsed_args):
|
||||||
|
body = dict()
|
||||||
|
if parsed_args.force:
|
||||||
|
body[self.resource] = dict()
|
||||||
|
body[self.resource]['attributes'] = {'force': True}
|
||||||
|
return body
|
||||||
|
|
||||||
|
|
||||||
class ListVNFResources(tackerV10.ListCommand):
|
class ListVNFResources(tackerV10.ListCommand):
|
||||||
"""List resources of a VNF like VDU, CP, etc."""
|
"""List resources of a VNF like VDU, CP, etc."""
|
||||||
|
@ -611,10 +611,18 @@ class CLITestV10Base(testtools.TestCase):
|
|||||||
args.extend(['--request-format', self.format])
|
args.extend(['--request-format', self.format])
|
||||||
cmd_parser = cmd.get_parser("delete_" + resource)
|
cmd_parser = cmd.get_parser("delete_" + resource)
|
||||||
shell.run_command(cmd, cmd_parser, args)
|
shell.run_command(cmd, cmd_parser, args)
|
||||||
mock_req.assert_called_once_with(
|
if '--force' in args:
|
||||||
end_url(path % myid, format=self.format), 'DELETE',
|
body_str = '{"' + resource + \
|
||||||
body=None,
|
'": {"attributes": {"force": true}}}'
|
||||||
headers=test_utils.ContainsKeyValue('X-Auth-Token', TOKEN))
|
mock_req.assert_called_once_with(
|
||||||
|
end_url(path % myid, format=self.format), 'DELETE',
|
||||||
|
body=body_str,
|
||||||
|
headers=test_utils.ContainsKeyValue('X-Auth-Token', TOKEN))
|
||||||
|
else:
|
||||||
|
mock_req.assert_called_once_with(
|
||||||
|
end_url(path % myid, format=self.format), 'DELETE',
|
||||||
|
body=None,
|
||||||
|
headers=test_utils.ContainsKeyValue('X-Auth-Token', TOKEN))
|
||||||
mock_get.assert_called_once_with()
|
mock_get.assert_called_once_with()
|
||||||
_str = self.fake_stdout.make_string()
|
_str = self.fake_stdout.make_string()
|
||||||
msg = 'All specified %(resource)s(s) %(msg)s successfully\n' % {
|
msg = 'All specified %(resource)s(s) %(msg)s successfully\n' % {
|
||||||
|
@ -187,12 +187,18 @@ class CLITestV10VmVNFJSON(test_cli10.CLITestV10Base):
|
|||||||
[my_id, '--%s' % key, value],
|
[my_id, '--%s' % key, value],
|
||||||
{key: value})
|
{key: value})
|
||||||
|
|
||||||
def test_delete_vnf(self):
|
def test_delete_vnf_without_force(self):
|
||||||
cmd = vnf.DeleteVNF(test_cli10.MyApp(sys.stdout), None)
|
cmd = vnf.DeleteVNF(test_cli10.MyApp(sys.stdout), None)
|
||||||
my_id = 'my-id'
|
my_id = 'my-id'
|
||||||
args = [my_id]
|
args = [my_id]
|
||||||
self._test_delete_resource(self._RESOURCE, cmd, my_id, args)
|
self._test_delete_resource(self._RESOURCE, cmd, my_id, args)
|
||||||
|
|
||||||
|
def test_delete_vnf_with_force(self):
|
||||||
|
cmd = vnf.DeleteVNF(test_cli10.MyApp(sys.stdout), None)
|
||||||
|
my_id = 'my-id'
|
||||||
|
args = [my_id, '--force']
|
||||||
|
self._test_delete_resource(self._RESOURCE, cmd, my_id, args)
|
||||||
|
|
||||||
def test_list_vnf_resources(self):
|
def test_list_vnf_resources(self):
|
||||||
cmd = vnf.ListVNFResources(test_cli10.MyApp(sys.stdout), None)
|
cmd = vnf.ListVNFResources(test_cli10.MyApp(sys.stdout), None)
|
||||||
base_args = [self.test_id]
|
base_args = [self.test_id]
|
||||||
|
@ -438,8 +438,8 @@ class Client(ClientBase):
|
|||||||
return self.post(self.vnfs_path, body=body)
|
return self.post(self.vnfs_path, body=body)
|
||||||
|
|
||||||
@APIParamsCall
|
@APIParamsCall
|
||||||
def delete_vnf(self, vnf):
|
def delete_vnf(self, vnf, body=None):
|
||||||
return self.delete(self.vnf_path % vnf)
|
return self.delete(self.vnf_path % vnf, body=body)
|
||||||
|
|
||||||
@APIParamsCall
|
@APIParamsCall
|
||||||
def update_vnf(self, vnf, body):
|
def update_vnf(self, vnf, body):
|
||||||
|
Loading…
Reference in New Issue
Block a user