Parameterization support added for VNFD templates
This commit adds code to support onboarding a VNFD template that supports parameterized input. At VNF deploy time, this feature allows to specify a yaml file with values to be substituted for the parameters specified in the VNFD template. Change-Id: I72b6e8da8826a3c80c1a73aa37f912fc9ec3e291 Closes-bug: #1484227
This commit is contained in:
parent
0b422aa7ad
commit
8587d0dd3e
|
@ -97,6 +97,18 @@ class ServiceInstanceNotFound(exceptions.NotFound):
|
|||
message = _('service instance %(service_instance_id)s could not be found')
|
||||
|
||||
|
||||
class ParamYAMLNotWellFormed(exceptions.InvalidInput):
|
||||
message = _("Parameter YAML not well formed - %(error_msg_details)")
|
||||
|
||||
|
||||
class InputValuesMissing(exceptions.InvalidInput):
|
||||
message = _("Input values missing for 'get_input")
|
||||
|
||||
|
||||
class ParamYAMLInputMissing(exceptions.InvalidInput):
|
||||
message = _("Parameter YAML input missing")
|
||||
|
||||
|
||||
def _validate_service_type_list(data, valid_values=None):
|
||||
if not isinstance(data, list):
|
||||
msg = _("invalid data format for service list: '%s'") % data
|
||||
|
|
|
@ -32,6 +32,7 @@ from oslo_config import cfg
|
|||
|
||||
from tacker.common import exceptions
|
||||
from tacker.common import log
|
||||
from tacker.extensions import servicevm
|
||||
from tacker.openstack.common import jsonutils
|
||||
from tacker.openstack.common import log as logging
|
||||
from tacker.vm.drivers import abstract_driver
|
||||
|
@ -105,6 +106,30 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver):
|
|||
device_template_dict['mgmt_driver'] = mgmt_driver
|
||||
LOG.debug(_('device_template %s'), device_template)
|
||||
|
||||
@log.log
|
||||
def _update_params(self, original, paramvalues, match=False):
|
||||
for key, value in original.iteritems():
|
||||
if not isinstance(value, dict):
|
||||
pass
|
||||
elif isinstance(value, dict):
|
||||
if not match:
|
||||
if key in paramvalues and 'param' in paramvalues[key]:
|
||||
self._update_params(value, paramvalues[key]['param'],
|
||||
True)
|
||||
elif key in paramvalues:
|
||||
self._update_params(value, paramvalues[key], False)
|
||||
else:
|
||||
LOG.debug('Key missing Value: %s', key)
|
||||
raise servicevm.InputValuesMissing()
|
||||
elif 'get_input' in value:
|
||||
if value['get_input'] in paramvalues:
|
||||
original[key] = paramvalues[value['get_input']]
|
||||
else:
|
||||
LOG.debug('Key missing Value: %s', key)
|
||||
raise servicevm.InputValuesMissing()
|
||||
else:
|
||||
self._update_params(value, paramvalues, True)
|
||||
|
||||
@log.log
|
||||
def create(self, plugin, context, device):
|
||||
LOG.debug(_('device %s'), device)
|
||||
|
@ -139,6 +164,22 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver):
|
|||
|
||||
vnfd_dict = yaml.load(vnfd_yaml)
|
||||
LOG.debug('vnfd_dict %s', vnfd_dict)
|
||||
|
||||
if 'get_input' in vnfd_yaml:
|
||||
param_vattrs_yaml = dev_attrs.pop('param_values', None)
|
||||
if param_vattrs_yaml:
|
||||
try:
|
||||
param_vattrs_dict = yaml.load(param_vattrs_yaml)
|
||||
LOG.debug('param_vattrs_yaml', param_vattrs_dict)
|
||||
except Exception as e:
|
||||
LOG.debug("Not Well Formed: %s", str(e))
|
||||
raise servicevm.ParamYAMLNotWellFormed(
|
||||
error_msg_details=str(e))
|
||||
else:
|
||||
self._update_params(vnfd_dict, param_vattrs_dict)
|
||||
else:
|
||||
raise servicevm.ParamYAMLInputMissing()
|
||||
|
||||
KEY_LIST = (('description', 'description'),
|
||||
)
|
||||
for (key, vnfd_key) in KEY_LIST:
|
||||
|
|
Loading…
Reference in New Issue