diff --git a/releasenotes/notes/vnf-inline-template-25f6a0b66f7407a1.yaml b/releasenotes/notes/vnf-inline-template-25f6a0b66f7407a1.yaml new file mode 100644 index 00000000..286bd527 --- /dev/null +++ b/releasenotes/notes/vnf-inline-template-25f6a0b66f7407a1.yaml @@ -0,0 +1,3 @@ +--- +features: + - Support to create VNF with direct VNFD template input from CLI. diff --git a/tackerclient/tacker/v1_0/__init__.py b/tackerclient/tacker/v1_0/__init__.py index c543d6d0..80f4732e 100644 --- a/tackerclient/tacker/v1_0/__init__.py +++ b/tackerclient/tacker/v1_0/__init__.py @@ -98,7 +98,7 @@ def add_show_list_common_argument(parser): '-D', '--show-details', help=_('Show detailed info'), action='store_true', - default=False, ) + default=False,) parser.add_argument( '--show_details', action='store_true', diff --git a/tackerclient/tacker/v1_0/vnfm/vnf.py b/tackerclient/tacker/v1_0/vnfm/vnf.py index a509c03f..e35331d4 100644 --- a/tackerclient/tacker/v1_0/vnfm/vnf.py +++ b/tackerclient/tacker/v1_0/vnfm/vnf.py @@ -60,6 +60,9 @@ class CreateVNF(tackerV10.CreateCommand): vnfd_group.add_argument( '--vnfd-name', help=_('VNFD Name to use as template to create VNF')) + vnfd_group.add_argument( + '--vnfd-template', + help=_("VNFD file to create VNF")) vim_group = parser.add_mutually_exclusive_group() vim_group.add_argument( '--vim-id', @@ -118,6 +121,12 @@ class CreateVNF(tackerV10.CreateCommand): parsed_args. vnfd_name) parsed_args.vnfd_id = _id + elif parsed_args.vnfd_template: + with open(parsed_args.vnfd_template) as f: + template = f.read() + args['vnfd_template'] = yaml.load( + template, Loader=yaml.SafeLoader) + if parsed_args.param_file: with open(parsed_args.param_file) as f: param_yaml = f.read() diff --git a/tackerclient/tacker/v1_0/vnfm/vnfd.py b/tackerclient/tacker/v1_0/vnfm/vnfd.py index 795d2dc1..2d4d1ee4 100644 --- a/tackerclient/tacker/v1_0/vnfm/vnfd.py +++ b/tackerclient/tacker/v1_0/vnfm/vnfd.py @@ -32,7 +32,24 @@ class ListVNFD(tackerV10.ListCommand): """List VNFD that belong to a given tenant.""" resource = _VNFD - list_columns = ['id', 'name', 'description'] + list_columns = ['id', 'name', 'template_source', 'description'] + + def get_parser(self, prog_name): + parser = super(ListVNFD, self).get_parser(prog_name) + parser.add_argument( + '--template-source', + help=_("List VNFD with specified template source. Available \ + options are 'onboarded' (default), 'inline' or 'all'"), + action='store', + default='onboarded') + return parser + + def args2search_opts(self, parsed_args): + search_opts = super(ListVNFD, self).args2search_opts(parsed_args) + template_source = parsed_args.template_source + if parsed_args.template_source: + search_opts.update({'template_source': template_source}) + return search_opts class ShowVNFD(tackerV10.ShowCommand): diff --git a/tackerclient/tests/unit/test_cli10.py b/tackerclient/tests/unit/test_cli10.py index 5f3993d9..6c28ab19 100644 --- a/tackerclient/tests/unit/test_cli10.py +++ b/tackerclient/tests/unit/test_cli10.py @@ -286,7 +286,8 @@ class CLITestV10Base(testtools.TestCase): def _test_list_resources(self, resources, cmd, detail=False, tags=[], fields_1=[], fields_2=[], page_size=None, sort_key=[], sort_dir=[], response_contents=None, - base_args=None, path=None): + base_args=None, path=None, + template_source=None): if response_contents is None: contents = [{self.id_field: 'myid1', }, {self.id_field: 'myid2', }, ] @@ -305,6 +306,10 @@ class CLITestV10Base(testtools.TestCase): for field in fields_1: args.append('--fields') args.append(field) + if template_source is not None: + args.append("--template-source") + args.append(template_source) + query += 'template_source=' + template_source if tags: args.append('--') diff --git a/tackerclient/tests/unit/vm/test_cli10_vnf.py b/tackerclient/tests/unit/vm/test_cli10_vnf.py index eedad92b..942235ca 100644 --- a/tackerclient/tests/unit/vm/test_cli10_vnf.py +++ b/tackerclient/tests/unit/vm/test_cli10_vnf.py @@ -112,14 +112,14 @@ class CLITestV10VmVNFJSON(test_cli10.CLITestV10Base): 'vnfd_id', 'vim_id', 'description', - 'attributes' + 'attributes', ] position_values = [ name, vnfd_id, vim_id, description, - {} + {}, ] extra_body = {key: value, 'placement_attr': {'region_name': region_name}} @@ -127,7 +127,7 @@ class CLITestV10VmVNFJSON(test_cli10.CLITestV10Base): args, position_names, position_values, extra_body=extra_body) - def test_create_vnf_with_mandatory_params(self): + def test_create_vnf_with_vnfd_id(self): cmd = vnf.CreateVNF(test_cli10.MyApp(sys.stdout), None) name = 'my_name' my_id = 'my-id' diff --git a/tackerclient/tests/unit/vm/test_cli10_vnfd.py b/tackerclient/tests/unit/vm/test_cli10_vnfd.py index 45480e74..261e49fa 100644 --- a/tackerclient/tests/unit/vm/test_cli10_vnfd.py +++ b/tackerclient/tests/unit/vm/test_cli10_vnfd.py @@ -67,11 +67,24 @@ class CLITestV10VmVNFDJSON(test_cli10.CLITestV10Base): def test_list_vnfds(self): cmd = vnfd.ListVNFD(test_cli10.MyApp(sys.stdout), None) - self._test_list_resources(self._RESOURCES, cmd, True) + self._test_list_resources(self._RESOURCES, cmd, True, + template_source='onboarded') + + def test_list_inline_vnfds(self): + cmd = vnfd.ListVNFD(test_cli10.MyApp(sys.stdout), None) + self._test_list_resources(self._RESOURCES, cmd, True, + template_source='inline') + + def test_list_all_vnfds(self): + cmd = vnfd.ListVNFD(test_cli10.MyApp(sys.stdout), None) + self._test_list_resources(self._RESOURCES, cmd, True, + template_source='all') def test_list_vnfds_pagenation(self): cmd = vnfd.ListVNFD(test_cli10.MyApp(sys.stdout), None) - self._test_list_resources(self._RESOURCES, cmd, True) + print(cmd) + self._test_list_resources(self._RESOURCES, cmd, True, + template_source='onboarded') def test_show_vnfd_id(self): cmd = vnfd.ShowVNFD(test_cli10.MyApp(sys.stdout), None) diff --git a/tackerclient/v1_0/client.py b/tackerclient/v1_0/client.py index dc792d36..abdb03f4 100644 --- a/tackerclient/v1_0/client.py +++ b/tackerclient/v1_0/client.py @@ -391,10 +391,11 @@ class Client(ClientBase): retrieve_all, **_params) for vnfd in vnfds_dict['vnfds']: - if 'description' in vnfd.keys() and \ - len(vnfd['description']) > DEFAULT_DESC_LENGTH: - vnfd['description'] = vnfd['description'][:DEFAULT_DESC_LENGTH] - vnfd['description'] += '...' + if vnfd.get('description'): + if len(vnfd['description']) > DEFAULT_DESC_LENGTH: + vnfd['description'] = \ + vnfd['description'][:DEFAULT_DESC_LENGTH] + vnfd['description'] += '...' return vnfds_dict @APIParamsCall