예제 #1
0
    def compose(self, vnfd_list, src_dir, template_info):
        self.descriptor = RwNsdYang.YangData_Nsd_NsdCatalog()
        self.id = str(uuid.uuid1())
        nsd = self.descriptor.nsd.add()
        nsd.id = self.id
        nsd.name = self.name
        nsd.short_name = self.name
        nsd.vendor = 'RIFT.io'
        nsd.description = '%s NS' % (self.name)
        nsd.version = '1.0'
        nsd.logo = 'riftio.png'

        i = 1
        for key, vnfd in vnfd_list.items():
            constituent_vnfd = nsd.constituent_vnfd.add()
            constituent_vnfd.member_vnf_index = int(
                template_info[key]['vnf_index'])
            constituent_vnfd.vnfd_id_ref = vnfd.id
            i = i + 1

            # Add Configuration defaults
            # self.default_config(constituent_vnfd, vnfd, src_dir, template_info[key])

        self.nsd = nsd
        print(nsd)
예제 #2
0
def read_from_file(module_list, infile, input_format, descr_type):
      model = RwYang.Model.create_libncx()
      for module in module_list:
          model.load_module(module)
 
      descr = None
      if descr_type == "nsd": 
        descr = RwNsdYang.YangData_Nsd_NsdCatalog_Nsd()
      else:
        descr = VnfdYang.YangData_Vnfd_VnfdCatalog_Vnfd()

      if input_format == 'json':
          json_str = open(infile).read()
          descr.from_json(model, json_str)
 
      elif input_format.strip() == 'xml':
          tree = etree.parse(infile)
          root = tree.getroot()
          xmlstr = etree.tostring(root, encoding="unicode")
          descr.from_xml_v2(model, xmlstr)
      else:
          raise("Invalid input format for the descriptor")
 
      return descr
예제 #3
0
    def openmano2rift(self, vnf_list):
        self.descriptor = RwNsdYang.YangData_Nsd_NsdCatalog()
        openmano_nsd = self.openmano.dictionary
        self.name = openmano_nsd['name']
        nsd = self.descriptor.nsd.add()
        nsd.id = str(uuid.uuid1())
        nsd.name = self.name
        nsd.short_name = self.name
        nsd.description = openmano_nsd['description']

        nodes = openmano_nsd['topology']['nodes']
        connections = openmano_nsd['topology']['connections']

        def create_consituent_vnfds():
            vnf_member_index_dict = {}

            vnfd_idx_gen = itertools.count(1)
            for key in nodes:
                node = nodes[key]
                if node['type'] != 'VNF':
                    continue

                vnfd_idx = next(vnfd_idx_gen)
                constituent_vnfd = nsd.constituent_vnfd.add()
                constituent_vnfd.member_vnf_index = vnfd_idx
                constituent_vnfd.vnfd_id_ref = self.get_vnfd_id(vnf_list, node['VNF model'])
                vnf_member_index_dict[key] = vnfd_idx

            return vnf_member_index_dict

        def create_connections(vnf_member_index_dict):
            keys = connections.keys()
            for key in keys:
                # TODO: Need clarification from TEF
                # skip the mgmtnet in OpenMANO descriptor
                if key == 'mgmtnet':
                    continue
                conn = connections[key]
                vld = nsd.vld.add()
                vld.from_dict(dict(
                    id=str(uuid.uuid1()),
                    name=key,
                    short_name=key,
                    type_yang='ELAN',
                    ))

                nodes = conn['nodes']
                for node, node_keys in [(node, node.keys()) for node in nodes]:
                    for node_key in node_keys:
                        topo_node = openmano_nsd['topology']['nodes'][node_key]
                        if topo_node['type'] == 'VNF':
                            cpref = vld.vnfd_connection_point_ref.add()
                            cpref.from_dict(dict(
                                member_vnf_index_ref=vnf_member_index_dict[node_key],
                                vnfd_id_ref=self.get_vnfd_id(vnf_list, topo_node['VNF model']),
                                #vnfd_id_ref=topo_node['VNF model'],
                                vnfd_connection_point_ref=node[node_key],
                                ))
                            if key != 'control-net':
                                vld.provider_network.physical_network = 'physnet_sriov'
                                vld.provider_network.overlay_type = 'VLAN'

        vnf_member_index_dict = create_consituent_vnfds()
        create_connections(vnf_member_index_dict)
예제 #4
0
#!/usr/bin/env python3
import os
import gi
import rift.mano.config_data.config
gi.require_version('RwNsdYang', '1.0')
gi.require_version('RwDts', '1.0')
from gi.repository import RwNsdYang, RwYang

model = RwYang.model_create_libncx()
model.load_schema_ypbc(RwNsdYang.get_schema())

for filename in os.listdir("."):
    if not filename.endswith(".yaml"):
        continue

    with open(filename) as hdl:
        yaml_str = hdl.read()

    try:
        nsd = RwNsdYang.YangData_Nsd_NsdCatalog_Nsd.from_yaml(model, yaml_str)
        print("Deserialized %s" % filename)

        config_str = rift.mano.config_data.config.ConfigPrimitiveConvertor().extract_nsd_config(nsd)
        print("config data: \n%s\n" % config_str)

    except Exception:
        print("Failed to deserialize: %s" % filename)
        raise
예제 #5
0
    def output_to_yang(self, use_gi=False, indent=4):
        self.log.debug(_('Converting translated output to yang model.'))

        nsd_cat = None
        nsd_id = str(uuid.uuid1())
        vnfds = []

        if use_gi:
            try:
                nsd_cat = RwNsdYang.YangData_Nsd_NsdCatalog()
                nsd = nsd_cat.nsd.add()
                nsd.id = nsd_id
                nsd.name = self.metadata['name']
                nsd.description = self.description
                nsd.vendor = self.metadata['vendor']
                nsd.short_name = self.metadata['name']
                nsd.version = self.metadata['version']
                if 'logo' in self.metadata:
                    nsd.logo = self.metadata['logo']
            except Exception as e:
                self.log.warning(_("Unable to use YANG GI to generate "
                                   "descriptors, falling back to alternate "
                                   "method: {}").format(e))
                self.log.exception(e)
                use_gi = False

        if not use_gi:
            nsd = {
                'id': nsd_id,
                'name': self.metadata['name'],
                'description': self.description,
                'vendor': self.metadata['vendor'],
                'short-name': self.metadata['name'],
                'version': self.metadata['version'],
            }

        for resource in self.resources:
            # Do the vlds first
            if resource.type == 'vld':
                resource.generate_yang_model(nsd, vnfds, use_gi=use_gi)

        vnf_type_duplicate = []
        vnfd_resources = []
        vnfd_duplicate_resource_list = []
        for resource in self.resources:
            if resource.type == 'vnfd':
                vnfd_resources.append(resource)

        vnfd_resources.sort(key=lambda x: x.member_vnf_id, reverse=False)
        vnf_type_to_vnf_id = {}
        for resource in vnfd_resources:
            if resource.vnf_type not in vnf_type_duplicate:
                resource.generate_yang_model(nsd, vnfds, use_gi=use_gi)
                vnf_type_to_vnf_id[resource.vnf_type] = resource.id
                vnf_type_duplicate.append(resource.vnf_type)
            else:
                vnfd_duplicate_resource_list.append(resource)

        for resource in vnfd_duplicate_resource_list:
            resource.generate_nsd_constiuent(nsd, vnf_type_to_vnf_id[resource.vnf_type])

        for resource in self.resources:
            # Do the other nodes
            if resource.type != 'vnfd' and resource.type != 'vld':
                resource.generate_yang_model(nsd, vnfds, use_gi=use_gi)

        for group in self.groups:
            group.generate_yang_model(nsd, vnfds, use_gi=use_gi)

        for policy in self.policies:
            policy.generate_yang_model(nsd, vnfds, use_gi=use_gi)

        # Add input params to nsd
        if use_gi:
            for param in self.parameters:
                nsd.input_parameter_xpath.append(
                 NsdYang.YangData_RwProject_Project_NsdCatalog_Nsd_InputParameterXpath(
                    xpath=param.get_xpath(),
                    )
                )
        else:
            nsd['input-parameter-xpath'] = []
            for param in self.parameters:
                nsd['input-parameter-xpath'].append(
                    {'xpath': param.get_xpath()})

        # Get list of supporting files referred in template
        # Returned format is {desc_id: [{type: type, name: filename}]}
        # TODO (pjoseph): Currently only images and scripts are retrieved.
        # Need to add support to get script names, charms, etc.
        other_files = {}
        for resource in self.resources:
            resource.get_supporting_files(other_files, desc_id=nsd_id)

        for policy in self.policies:
            policy.get_supporting_files(other_files, desc_id=nsd_id)

        self.log.debug(_("List of other files: {}".format(other_files)))

        # Do the final processing and convert each descriptor to yaml string
        tpl = {}

        # Add the NSD
        if use_gi:
            nsd_pf = self.get_yaml(['nsd', 'rw-nsd'], nsd_cat)
            nsd_id = nsd_cat.nsd[0].id
            nsd_name = nsd_cat.nsd[0].name
        else:
            nsd_id = nsd['id']
            nsd_name = nsd['name']

            # In case of non gi proecssing,
            # - convert all values to string
            # - enclose in a catalog dict
            # - prefix all keys with nsd or vnfd
            # - Convert to YAML string
            nsd_pf = yaml.dump(
                self.prefix_dict(
                    self.add_cat(dict_convert_values_to_str(nsd),
                                 self.NSD),
                    self.NSD),
                default_flow_style=False)

        nsd_out = {
            self.NAME: nsd_name,
            self.ID: nsd_id,
            self.YANG: nsd_pf,
        }

        if nsd_id in other_files:
            nsd_out[self.FILES] = other_files[nsd_id]

        tpl[self.NSD] = [nsd_out]

        # Add the VNFDs
        tpl[self.VNFD] = []

        for vnfd in vnfds:
            if use_gi:
                vnfd_pf = self.get_yaml(['vnfd', 'rw-vnfd'], vnfd)
                vnfd_id = vnfd.vnfd[0].id
                vnfd_name = vnfd.vnfd[0].name

            else:
                vnfd_id = vnfd['id']
                vnfd_name = vnfd['name']

                # In case of non gi proecssing,
                # - convert all values to string
                # - enclose in a catalog dict
                # - prefix all keys with nsd or vnfd
                # - Convert to YAML string
                vnfd_pf = yaml.dump(
                    self.prefix_dict(
                        self.add_cat(dict_convert_values_to_str(vnfd),
                                     self.VNFD),
                        self.VNFD),
                    default_flow_style=False)

            vnfd_out = {
                self.NAME: vnfd_name,
                self.ID: vnfd_id,
                self.YANG: vnfd_pf,
            }


            if vnfd_id in other_files:
                vnfd_out[self.FILES] = other_files[vnfd_id]

            tpl[self.VNFD].append(vnfd_out)

        self.log.debug(_("NSD: {0}").format(tpl[self.NSD]))
        self.log.debug(_("VNFDs:"))
        for vnfd in tpl[self.VNFD]:
            self.log.debug(_("{0}").format(vnfd))

        return tpl
예제 #6
0
 def from_yaml_file_hdl(cls, hdl):
     hdl.seek(0)
     descriptor = RwNsdYang.YangData_Nsd_NsdCatalog_Nsd()
     descriptor.from_yaml(RiftNSD.model, hdl.read())
     return cls(descriptor)