Support VNF creation from inline VNF template

Allows creating VNF from the VNFD template directly without the need of
VNFD being stored in Tacker VNFD catalog.

Change-Id: I719237dd04dd7fe13fb7e7964402d7074679b2d6
Implements: blueprint vnf-inline-template
This commit is contained in:
janki 2016-12-23 19:44:39 +05:30
parent b91c8a745e
commit f66a4e0ccc
8 changed files with 60 additions and 12 deletions

View File

@ -0,0 +1,3 @@
---
features:
- Support to create VNF with direct VNFD template input from CLI.

View File

@ -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',

View File

@ -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()

View File

@ -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):

View File

@ -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('--')

View File

@ -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'

View File

@ -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)

View File

@ -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