def update_vnf(self, context, vnf_id, vnf): vnf_attributes = vnf['vnf']['attributes'] if vnf_attributes.get('config'): config = vnf_attributes['config'] if isinstance(config, dict): # TODO(sripriya) remove this yaml dump once db supports storing # json format of yaml files in a separate column instead of # key value string pairs in vnf attributes table vnf_attributes['config'] = yaml.safe_dump(config) else: raise vnfm.InvalidAPIAttributeType(atype=type(config)) if vnf_attributes.get('param_values'): param = vnf_attributes['param_values'] if isinstance(param, dict): # TODO(sripriya) remove this yaml dump once db supports storing # json format of yaml files in a separate column instead of # key value string pairs in vnf attributes table vnf_attributes['param_values'] = yaml.safe_dump(param) else: raise vnfm.InvalidAPIAttributeType(atype=type(param)) vnf_dict = self._update_vnf_pre(context, vnf_id, constants.PENDING_UPDATE) driver_name, vim_auth = self._get_infra_driver(context, vnf_dict) instance_id = self._instance_id(vnf_dict) try: self.mgmt_update_pre(context, vnf_dict) self._vnf_manager.invoke(driver_name, 'update', plugin=self, context=context, vnf_id=instance_id, vnf_dict=vnf_dict, vnf=vnf, auth_attr=vim_auth) except vnfm.VNFUpdateInvalidInput: with excutils.save_and_reraise_exception(): vnf_dict['status'] = constants.ACTIVE self._update_vnf_post(context, vnf_id, constants.ACTIVE, vnf_dict, constants.PENDING_UPDATE, constants.RES_EVT_UPDATE) except Exception as e: with excutils.save_and_reraise_exception(): vnf_dict['status'] = constants.ERROR self._vnf_monitor.delete_hosting_vnf(vnf_id) self.set_vnf_error_status_reason(context, vnf_dict['id'], six.text_type(e)) self.mgmt_update_post(context, vnf_dict) self._update_vnf_post(context, vnf_id, constants.ERROR, vnf_dict, constants.PENDING_UPDATE, constants.RES_EVT_UPDATE) self.spawn_n(self._update_vnf_wait, context, vnf_dict, vim_auth, driver_name) return vnf_dict
def create_vnf(self, context, vnf): vnf_info = vnf['vnf'] name = vnf_info['name'] # if vnfd_template specified, create vnfd from template # create template dictionary structure same as needed in create_vnfd() if vnf_info.get('vnfd_template'): vnfd_name = utils.generate_resource_name(name, 'inline') vnfd = {'vnfd': {'attributes': {'vnfd': vnf_info['vnfd_template']}, 'name': vnfd_name, 'template_source': 'inline', 'service_types': [{'service_type': 'vnfd'}]}} vnf_info['vnfd_id'] = self.create_vnfd(context, vnfd).get('id') infra_driver, vim_auth = self._get_infra_driver(context, vnf_info) if infra_driver not in self._vnf_manager: LOG.debug('unknown vim driver ' '%(infra_driver)s in %(drivers)s', {'infra_driver': infra_driver, 'drivers': cfg.CONF.tacker.infra_driver}) raise vnfm.InvalidInfraDriver(vim_name=infra_driver) vnf_attributes = vnf_info['attributes'] if vnf_attributes.get('param_values'): param = vnf_attributes['param_values'] if isinstance(param, dict): # TODO(sripriya) remove this yaml dump once db supports storing # json format of yaml files in a separate column instead of # key value string pairs in vnf attributes table vnf_attributes['param_values'] = yaml.safe_dump(param) else: raise vnfm.InvalidAPIAttributeType(atype=type(param)) if vnf_attributes.get('config'): config = vnf_attributes['config'] if isinstance(config, dict): # TODO(sripriya) remove this yaml dump once db supports storing # json format of yaml files in a separate column instead of # key value string pairs in vnf attributes table vnf_attributes['config'] = yaml.safe_dump(config) else: raise vnfm.InvalidAPIAttributeType(atype=type(config)) vnf_dict = self._create_vnf(context, vnf_info, vim_auth, infra_driver) def create_vnf_wait(): self._create_vnf_wait(context, vnf_dict, vim_auth, infra_driver) if 'app_monitoring_policy' in vnf_dict['attributes']: self.add_vnf_to_appmonitor(context, vnf_dict) if vnf_dict['status'] is not constants.ERROR: self.add_vnf_to_monitor(context, vnf_dict) self.config_vnf(context, vnf_dict) self.spawn_n(create_vnf_wait) return vnf_dict
def create_vnfd(self, context, vnfd): vnfd_data = vnfd['vnfd'] template = vnfd_data['attributes'].get('vnfd') if isinstance(template, dict): # TODO(sripriya) remove this yaml dump once db supports storing # json format of yaml files in a separate column instead of # key value string pairs in vnf attributes table vnfd_data['attributes']['vnfd'] = yaml.safe_dump(template) else: raise vnfm.InvalidAPIAttributeType(atype=type(template)) if "tosca_definitions_version" not in template: raise exceptions.Invalid('Not a valid template: ' 'tosca_definitions_version is missing.') LOG.debug('vnfd %s', vnfd_data) service_types = vnfd_data.get('service_types') if not attributes.is_attr_set(service_types): LOG.debug('service type must be specified') raise vnfm.ServiceTypesNotSpecified() for service_type in service_types: # TODO(yamahata): # framework doesn't know what services are valid for now. # so doesn't check it here yet. pass if 'template_source' in vnfd_data: template_source = vnfd_data.get('template_source') else: template_source = 'onboarded' vnfd['vnfd']['template_source'] = template_source self._parse_template_input(vnfd) return super(VNFMPlugin, self).create_vnfd(context, vnfd)