def create_device_template(self, context, device_template): template = device_template['device_template'] LOG.debug(_('template %s'), template) infra_driver = template.get('infra_driver') if not attributes.is_attr_set(infra_driver): LOG.debug(_('hosting device driver must be specified')) raise vnfm.InfraDriverNotSpecified() if infra_driver not in self._device_manager: LOG.debug( _('unknown hosting device driver ' '%(infra_driver)s in %(drivers)s'), { 'infra_driver': infra_driver, 'drivers': cfg.CONF.tacker.infra_driver }) raise vnfm.InvalidInfraDriver(infra_driver=infra_driver) service_types = template.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 self._device_manager.invoke(infra_driver, 'create_device_template_pre', plugin=self, context=context, device_template=device_template) return super(VNFMPlugin, self).create_device_template(context, device_template)
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') 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: self._report_deprecated_yaml_str() 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: self._report_deprecated_yaml_str() 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_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) print("",vnf_dict['attributes']) if 'service_monitoring_policy' in vnf_dict['attributes']: self.add_vnf_to_svcmonitor(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_vnf(self, context, vnf): start_time = time.time() vnf_info = vnf['vnf'] name = vnf_info['name'] if self._get_by_name(context, vnfm_db.VNF, name): raise exceptions.DuplicateResourceName(resource='VNF', name=name) 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: self._report_deprecated_yaml_str() 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: self._report_deprecated_yaml_str() 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_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 vnf_dict['status'] is not constants.ERROR: self.add_vnf_to_monitor(vnf_dict, infra_driver) self.config_vnf(context, vnf_dict) self.spawn_n(create_vnf_wait) end_time = time.time() LOG.debug(_("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")) LOG.debug(_("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")) LOG.debug(_("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")) LOG.debug(_("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")) LOG.debug(_("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")) LOG.debug(_("VNF Create Total Time : %s"), end_time-start_time) LOG.debug(_("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")) LOG.debug(_("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")) LOG.debug(_("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")) LOG.debug(_("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")) LOG.debug(_("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")) 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) elif isinstance(template, str): self._report_deprecated_yaml_str() if "tosca_definitions_version" not in template: versionutils.report_deprecated_feature(LOG, 'VNFD legacy vnfds' ' are deprecated since Mitaka release and will be removed in' ' Ocata release. Please use NFV TOSCA vnfds.') LOG.debug(_('vnfd %s'), vnfd_data) infra_driver = vnfd_data.get('infra_driver') if not attributes.is_attr_set(infra_driver): LOG.debug(_('hosting vnf driver must be specified')) raise vnfm.InfraDriverNotSpecified() if infra_driver not in self._vnf_manager: LOG.debug(_('unknown hosting vnf driver ' '%(infra_driver)s in %(drivers)s'), {'infra_driver': infra_driver, 'drivers': cfg.CONF.tacker.infra_driver}) raise vnfm.InvalidInfraDriver(infra_driver=infra_driver) 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 self._vnf_manager.invoke( infra_driver, 'create_vnfd_pre', plugin=self, context=context, vnfd=vnfd) return super(VNFMPlugin, self).create_vnfd( context, vnfd)