def create_device_template_pre(self, plugin, context, device_template): device_template_dict = device_template['device_template'] vnfd_yaml = device_template_dict['attributes'].get('vnfd') if vnfd_yaml is None: return vnfd_dict = yaml.load(vnfd_yaml) LOG.debug(_('vnfd_dict: %s'), vnfd_dict) if 'tosca_definitions_version' in vnfd_dict: # Prepend the tacker_defs.yaml import file with the full # path to the file toscautils.updateimports(vnfd_dict) try: tosca = ToscaTemplate(a_file=False, yaml_dict_tpl=vnfd_dict) except Exception as e: LOG.exception(_("tosca-parser error: %s"), str(e)) raise vnfm.ToscaParserFailed(error_msg_details=str(e)) if ('description' not in device_template_dict or device_template_dict['description'] == ''): device_template_dict['description'] = vnfd_dict.get( 'description', '') if (('name' not in device_template_dict or not len(device_template_dict['name'])) and 'metadata' in vnfd_dict): device_template_dict['name'] = vnfd_dict['metadata'].get( 'template_name', '') device_template_dict['mgmt_driver'] = toscautils.get_mgmt_driver( tosca) else: KEY_LIST = (('name', 'template_name'), ('description', 'description')) device_template_dict.update( dict((key, vnfd_dict[vnfd_key]) for (key, vnfd_key) in KEY_LIST if ((key not in device_template_dict or device_template_dict[key] == '') and vnfd_key in vnfd_dict and vnfd_dict[vnfd_key] != ''))) service_types = vnfd_dict.get('service_properties', {}).get('type', []) if service_types: device_template_dict.setdefault('service_types', []).extend( [{'service_type': service_type} for service_type in service_types]) # TODO(anyone) - this code assumes one mgmt_driver per VNFD??? for vdu in vnfd_dict.get('vdus', {}).values(): mgmt_driver = vdu.get('mgmt_driver') if mgmt_driver: device_template_dict['mgmt_driver'] = mgmt_driver LOG.debug(_('device_template %s'), device_template)
def create_device_template_pre(self, plugin, context, device_template): device_template_dict = device_template['device_template'] vnfd_yaml = device_template_dict['attributes'].get('vnfd') if vnfd_yaml is None: return vnfd_dict = yaml.load(vnfd_yaml) LOG.debug(_('vnfd_dict: %s'), vnfd_dict) if 'tosca_definitions_version' in vnfd_dict: # Prepend the tacker_defs.yaml import file with the full # path to the file toscautils.updateimports(vnfd_dict) try: tosca = ToscaTemplate(a_file=False, yaml_dict_tpl=vnfd_dict) except Exception as e: LOG.exception(_("tosca-parser error: %s"), str(e)) raise vnfm.ToscaParserFailed(error_msg_details=str(e)) if ('description' not in device_template_dict or device_template_dict['description'] == ''): device_template_dict['description'] = vnfd_dict.get( 'description', '') if (('name' not in device_template_dict or not len(device_template_dict['name'])) and 'metadata' in vnfd_dict): device_template_dict['name'] = vnfd_dict['metadata'].get( 'template_name', '') device_template_dict['mgmt_driver'] = toscautils.get_mgmt_driver( tosca) else: KEY_LIST = (('name', 'template_name'), ('description', 'description')) device_template_dict.update( dict((key, vnfd_dict[vnfd_key]) for (key, vnfd_key) in KEY_LIST if ((key not in device_template_dict or device_template_dict[key] == '') and vnfd_key in vnfd_dict and vnfd_dict[vnfd_key] != ''))) service_types = vnfd_dict.get('service_properties', {}).get('type', []) if service_types: device_template_dict.setdefault('service_types', []).extend([{ 'service_type': service_type } for service_type in service_types]) # TODO(anyone) - this code assumes one mgmt_driver per VNFD??? for vdu in vnfd_dict.get('vdus', {}).values(): mgmt_driver = vdu.get('mgmt_driver') if mgmt_driver: device_template_dict['mgmt_driver'] = mgmt_driver LOG.debug(_('device_template %s'), device_template)
def test_get_mgmt_driver(self): expected_mgmt_driver = 'openwrt' mgmt_driver = toscautils.get_mgmt_driver(self.tosca) self.assertEqual(expected_mgmt_driver, mgmt_driver)
def test_get_mgmt_driver(self): expected_mgmt_driver = "openwrt" mgmt_driver = toscautils.get_mgmt_driver(self.tosca) self.assertEqual(mgmt_driver, expected_mgmt_driver)
def test_get_mgmt_driver(self): expected_mgmt_driver = 'openwrt' mgmt_driver = toscautils.get_mgmt_driver(self.tosca) self.assertEqual(mgmt_driver, expected_mgmt_driver)