X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=common%2Fpython%2Frift%2Fmano%2Ftosca_translator%2Frwmano%2Ftosca%2Ftosca_nfv_vnf.py;h=e4e045e3f7aa8dbf1184b6a297eb6770f5cd6b3a;hb=a32315535a0d3ed57f671de78d2df0b5de11db68;hp=3e529671a103e732429d95d3f70f73539e578472;hpb=8dfa9a16fb8cda714cb460db1044515f8be6ef49;p=osm%2FSO.git diff --git a/common/python/rift/mano/tosca_translator/rwmano/tosca/tosca_nfv_vnf.py b/common/python/rift/mano/tosca_translator/rwmano/tosca/tosca_nfv_vnf.py index 3e529671..e4e045e3 100644 --- a/common/python/rift/mano/tosca_translator/rwmano/tosca/tosca_nfv_vnf.py +++ b/common/python/rift/mano/tosca_translator/rwmano/tosca/tosca_nfv_vnf.py @@ -18,6 +18,7 @@ from rift.mano.tosca_translator.common.utils import _ from rift.mano.tosca_translator.common.utils import convert_keys_to_python from rift.mano.tosca_translator.rwmano.syntax.mano_resource import ManoResource +from toscaparser.functions import GetInput from toscaparser.common.exception import ValidationError @@ -45,7 +46,7 @@ class ToscaNfvVnf(ManoResource): 'mgmt-interface'] OPTIONAL_PROPS = ['version', 'vendor', 'http-endpoint', 'monitoring-param', 'connection-point'] - IGNORE_PROPS = ['port'] + IGNORE_PROPS = ['port', 'monitoring_param'] TOSCA_CAPS = ['mgmt_interface', 'http_endpoint', 'monitoring_param_0', 'monitoring_param_1', 'connection_point'] @@ -57,6 +58,10 @@ class ToscaNfvVnf(ManoResource): self._const_vnfd = {} self._vnf_config = {} self._vdus = [] + self._policies = [] + self._cps = [] + self.vnf_type = nodetemplate.type + self._reqs = {} def map_tosca_name_to_mano(self, name): new_name = super().map_tosca_name_to_mano(name) @@ -138,6 +143,8 @@ class ToscaNfvVnf(ManoResource): if 'start_by_default' in vnf_props: self._const_vnfd['start-by-default'] = \ vnf_props.pop('start_by_default') + if 'logo' in self.metadata: + vnf_props['logo'] = self.metadata['logo'] self.log.debug(_("VNF {0} with constituent vnf: {1}"). format(self.name, self._const_vnfd)) @@ -186,45 +193,44 @@ class ToscaNfvVnf(ManoResource): self.log.debug(_("VDU {0} properties: {1}"). format(self.name, self.properties)) - def handle_requirements(self, nodes): + def handle_requirements(self, nodes, policies, vnf_type_to_vdus_map): tosca_reqs = self.get_tosca_reqs() - self.log.debug("VNF {0} requirements: {1}". - format(self.name, tosca_reqs)) - - try: - for req in tosca_reqs: - if 'vdus' in req: - target = req['vdus']['target'] - node = self.get_node_with_name(target, nodes) - if node: - self._vdus.append(node) - node._vnf = self - # Add the VDU id to mgmt-intf - if 'mgmt-interface' in self.properties: - self.properties['mgmt-interface']['vdu-id'] = \ - node.id - if 'vdu' in self.properties['mgmt-interface']: - # Older yang - self.properties['mgmt-interface'].pop('vdu') - else: - err_msg = _("VNF {0}, VDU {1} specified not found"). \ - format(self.name, target) - self.log.error(err_msg) - raise ValidationError(message=err_msg) - - except Exception as e: - err_msg = _("Exception getting VDUs for VNF {0}: {1}"). \ - format(self.name, e) - self.log.error(err_msg) - raise e - - self.log.debug(_("VNF {0} properties: {1}"). - format(self.name, self.properties)) + for req in tosca_reqs: + for key, value in req.items(): + if 'target' in value: + self._reqs[key] = value['target'] + + for policy in policies: + if hasattr(policy, '_vnf_name') and policy._vnf_name == self.name: + self._policies.append(policy) + + + if self.vnf_type in vnf_type_to_vdus_map: + for vdu_node_name in vnf_type_to_vdus_map[self.vnf_type]: + node = self.get_node_with_name(vdu_node_name, nodes) + if node: + self._vdus.append(node) + node._vnf = self + # Add the VDU id to mgmt-intf + if 'mgmt-interface' in self.properties: + self.properties['mgmt-interface']['vdu-id'] = \ + node.id + if 'vdu' in self.properties['mgmt-interface']: + # Older yang + self.properties['mgmt-interface'].pop('vdu') + else: + err_msg = _("VNF {0}, VDU {1} specified not found"). \ + format(self.name, target) + self.log.error(err_msg) + raise ValidationError(message=err_msg) def generate_yang_model_gi(self, nsd, vnfds): vnfd_cat = RwVnfdYang.YangData_Vnfd_VnfdCatalog() vnfd = vnfd_cat.vnfd.add() props = convert_keys_to_python(self.properties) + for key in ToscaNfvVnf.IGNORE_PROPS: + if key in props: + props.pop(key) try: vnfd.from_dict(props) except Exception as e: @@ -237,6 +243,8 @@ class ToscaNfvVnf(ManoResource): # Update the VDU properties for vdu in self._vdus: vdu.generate_yang_submodel_gi(vnfd) + for policy in self._policies: + policy.generate_yang_submodel_gi(vnfd) # Update constituent vnfd in nsd try: