def importprojectdir(cls, dir_project, file_type): """Imports all descriptor files under a given folder this method is specific for Srv6_net_prog project type """ project = {'srv6_net_prog': {}, 'positions': {}} for desc_type in project: cur_type_path = os.path.join(dir_project, desc_type.upper()) log.debug(cur_type_path) if os.path.isdir(cur_type_path): for file in glob.glob( os.path.join(cur_type_path, '*.' + file_type)): if file_type == 'json' and os.path.basename( file) != 'vertices.json': project[desc_type][os.path.basename(file).split('.') [0]] = Util.loadjsonfile(file) elif file_type == 'yaml': project[desc_type][os.path.basename(file).split('.') [0]] = Util.loadyamlfile(file) for vertices_file in glob.glob( os.path.join(dir_project, "SRV6_NET_PROG", '*.json')): if os.path.basename(vertices_file) == 'vertices.json': project['positions']['vertices'] = Util.loadjsonfile( vertices_file) return project
def importprojectdir(cls, dir_project, file_type): """Imports all files from NSD and VNFDs folders under a given folder this method is specific for Etsi project type """ project = {'nsd': {}, 'vnfd': {}, 'positions': {}} # my_util = Util() NSD_PATH = dir_project + '/NSD' VNFD_PATH = dir_project + '/VNFD' #import network service description #in root directory file name nsd.json / nsd.yaml for nsd_filename in glob.glob(os.path.join(NSD_PATH, '*.' + file_type)): log.debug(nsd_filename) nsd_object = Util.loadjsonfile(nsd_filename) project['nsd'][nsd_object['nsdIdentifier']] = nsd_object # import vnf descriptions # each file in root_path/VFND/*.json for vnfd_filename in glob.glob( os.path.join(VNFD_PATH, '*.' + file_type)): log.debug(vnfd_filename) vnfd_object = Util.loadjsonfile(vnfd_filename) project['vnfd'][vnfd_object['vnfdId']] = vnfd_object for vertices_file in glob.glob(os.path.join(dir_project, '*.json')): if os.path.basename(vertices_file) == 'vertices.json': project['positions']['vertices'] = Util.loadjsonfile( vertices_file) return project
def importprojectdir(cls, dir_project, file_type): """Imports all descriptor files under a given folder this method is specific for Superfluidity project type """ project = { 'nsd': {}, 'vnfd': {}, 'click': {}, 'k8s': {}, 'resource': {}, 'positions': {} } nfv_path = dir_project + "/NFV/" etsi_project = EtsiParser.importprojectdir(nfv_path + '/JSON', 'json') #print etsi_project project['nsd'] = etsi_project['nsd'] project['vnfd'] = etsi_project['vnfd'] project['click'] = click_parser.importprojectdir( dir_project + '/CLICK/', 'click')['click'] # FIXME import k8s descriptors project['k8s'] = cls.import_kubernetes_from_dir_project(dir_project) for vertices_file in glob.glob(os.path.join(dir_project, '*.json')): if os.path.basename(vertices_file) == 'vertices.json': project['positions']['vertices'] = Util.loadjsonfile( vertices_file) return project
def get_descriptor_template(cls, type_descriptor): """Returns a descriptor template for a given descriptor type""" try: schema = Util.loadjsonfile(os.path.join(PATH_TO_DESCRIPTORS_TEMPLATES, type_descriptor + DESCRIPTOR_TEMPLATE_SUFFIX)) # print 'type_descriptor : '+type_descriptor return schema except Exception as e: log.exception(e) return False
def importprojectfile(cfg_files): project = {'click': {}} for file in cfg_files: if os.path.basename(str(file.name)) == 'vertices.json': print 'dentrpp ', str(file) project['positions'] = {} project['positions']['vertices'] = Util.loadjsonfile(file) else: project['click'][os.path.splitext(os.path.basename( str(file)))[0]] = file.read() return project
def importprojectdir(cls, dir_project, file_type): """Imports all descriptor files under a given folder this method is specific for Nemo project type """ project = {'intent': {}, 'nodemodel': {}, 'positions': {}} for desc_type in project: cur_type_path = os.path.join(dir_project, desc_type.upper()) log.debug(cur_type_path) if os.path.isdir(cur_type_path): for file in glob.glob( os.path.join(cur_type_path, '*.' + file_type)): if file_type == 'nemo': project[desc_type][os.path.basename(file).split('.') [0]] = Util.openfile(file).read() for vertices_file in glob.glob(os.path.join(dir_project, '*.json')): if os.path.basename(vertices_file) == 'vertices.json': project['positions']['vertices'] = Util.loadjsonfile( vertices_file) return project