From 8587d0dd3e3e6bc73654d7fcbb587bf77e9fc29e Mon Sep 17 00:00:00 2001 From: Vishwanath Jayaraman Date: Wed, 12 Aug 2015 17:55:24 -0500 Subject: [PATCH] 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 --- tacker/extensions/servicevm.py | 12 ++++++++++ tacker/vm/drivers/heat/heat.py | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/tacker/extensions/servicevm.py b/tacker/extensions/servicevm.py index 8576fc815..8dc9086b9 100644 --- a/tacker/extensions/servicevm.py +++ b/tacker/extensions/servicevm.py @@ -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 diff --git a/tacker/vm/drivers/heat/heat.py b/tacker/vm/drivers/heat/heat.py index 20e79d3c4..f67dc6127 100644 --- a/tacker/vm/drivers/heat/heat.py +++ b/tacker/vm/drivers/heat/heat.py @@ -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: