updated: Python scripts to generate eNB's templates for container images
Signed-off-by: Mohammed Ismail <mohammed.ismail@eurecom.fr>
This commit is contained in:
committed by
Raphael Defosseux
parent
abf2693b38
commit
a9a334f294
@@ -1,68 +1,86 @@
|
||||
# * this work for additional information regarding copyright ownership.
|
||||
# * The OpenAirInterface Software Alliance licenses this file to You under
|
||||
# * the OAI Public License, Version 1.1 (the "License"); you may not use this file
|
||||
# * except in compliance with the License.
|
||||
# * You may obtain a copy of the License at
|
||||
# *
|
||||
# * http://www.openairinterface.org/?page_id=698
|
||||
# *
|
||||
# * Unless required by applicable law or agreed to in writing, software
|
||||
# * distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# * See the License for the specific language governing permissions and
|
||||
# * limitations under the License.
|
||||
# *-------------------------------------------------------------------------------
|
||||
# * For more information about the OpenAirInterface (OAI) Software Alliance:
|
||||
# * contact@openairinterface.org
|
||||
# */
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
#-----------------------------------------------------------
|
||||
# Import
|
||||
#-----------------------------------------------------------
|
||||
import re
|
||||
import json
|
||||
import yaml
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
dir = os.listdir('/home/mohammed/Documents/conf_files/')
|
||||
def main():
|
||||
#read yaml input parameters
|
||||
f = open(f'{sys.argv[1]}',)
|
||||
data = yaml.full_load(f)
|
||||
dir = os.listdir(f'{data[0]["paths"]["source_dir"]}')
|
||||
|
||||
#read json config file
|
||||
f = open('parameters.json',)
|
||||
data = json.load(f)
|
||||
for config in data:
|
||||
|
||||
filePrefix = config["filePrefix"]
|
||||
print(filePrefix)
|
||||
for inputfile in dir:
|
||||
if inputfile.find(filePrefix) >=0:
|
||||
if filePrefix == "cu":
|
||||
outputfile1 = 'config/cu.fdd.config'
|
||||
elif filePrefix == "du":
|
||||
outputfile1 = 'config/du.fdd.config'
|
||||
elif filePrefix == "du":
|
||||
outputfile1 = 'config/du.fdd.config'
|
||||
elif filePrefix == "rru.fdd":
|
||||
outputfile1 = 'config/rru.fdd.config'
|
||||
elif filePrefix == "rru.tdd":
|
||||
outputfile1 = 'config/rru.tdd.config'
|
||||
elif filePrefix == "enb.band7.tm1.25PRB.usrpb210":
|
||||
outputfile1 = 'config/enb.fdd.config'
|
||||
elif filePrefix == "enb.band40.tm1.25PRB.FairScheduler.usrpb210":
|
||||
outputfile1 = 'config/enb.tdd.config'
|
||||
# elif filePrefix == "rcc.band7.tm1.nfapi":
|
||||
# outputfile1 = 'config/rcc.if4p5.enb.fdd.config'
|
||||
# elif filePrefix == "rcc.band7.tm1.nfapi":
|
||||
# outputfile1 = 'config/rcc.if4p5.enb.tdd.config'
|
||||
#identify configs, read and replace corresponding values
|
||||
for config in data[1]["configurations"]:
|
||||
filePrefix = config["filePrefix"]
|
||||
outputfilename = config["outputfilename"]
|
||||
for inputfile in dir:
|
||||
if inputfile.find(filePrefix) >=0:
|
||||
prefix_outputfile = {"cu": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
|
||||
"du": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
|
||||
"rru.fdd": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
|
||||
"rru.tdd": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
|
||||
"enb.band7.tm1.25PRB.usrpb210": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
|
||||
"enb.band40.tm1.25PRB.FairScheduler.usrpb210": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}'
|
||||
"rcc.band7.tm1.nfapi": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}'
|
||||
}
|
||||
if filePrefix in prefix_outputfile:
|
||||
outputfile1 = prefix_outputfile[filePrefix]
|
||||
|
||||
directory = 'config/'
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
|
||||
with open("/home/mohammed/Documents/conf_files/%s" % (inputfile), mode='r') as inputfile, \
|
||||
open(outputfile1, mode='w') as outputfile:
|
||||
for line in inputfile:
|
||||
count = 0
|
||||
for key in config["config"]:
|
||||
if line.find(key["key"]) >= 0:
|
||||
count += 1
|
||||
if re.search(r'preference', line):
|
||||
templine = line
|
||||
elif re.search(r'plmn_list', line):
|
||||
templine = re.sub(r'[0-9]+', '""', line)
|
||||
templine = re.sub(r'\"\"', key["env"]["mcc"], templine, 1)
|
||||
templine = re.sub(r'\"\"', key["env"]["mnc"], templine, 1)
|
||||
templine = re.sub(r'\"\"', key["env"]["mnc_length"], templine, 1)
|
||||
elif re.search('downlink_frequency', line):
|
||||
templine = re.sub(r'[0-9]+', key["env"], line)
|
||||
elif re.search('uplink_frequency_offset', line):
|
||||
templine = re.sub(r'[0-9]+', key["env"], line)
|
||||
|
||||
elif re.search(r'"(.*?)"', line):
|
||||
templine = re.sub(r'(?<=")[^"]*(?=")', key["env"], line) # for quotes
|
||||
elif re.search(r'[0-9]', line):
|
||||
templine = re.sub(r'\d+', key["env"], line)
|
||||
outputfile.write(templine)
|
||||
|
||||
if count == 0:
|
||||
outputfile.write(line)
|
||||
#read file and replace with ...
|
||||
directory = f'{data[0]["paths"]["dest_dir"]}'
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
|
||||
with open(f'{data[0]["paths"]["source_dir"]}{inputfile}', mode='r') as inputfile, \
|
||||
open(outputfile1, mode='w') as outputfile:
|
||||
for line in inputfile:
|
||||
count = 0
|
||||
for key in config["config"]:
|
||||
if line.find(key["key"]) >= 0:
|
||||
count += 1
|
||||
if re.search(r'preference', line):
|
||||
templine = line
|
||||
elif re.search(r'plmn_list', line):
|
||||
templine = re.sub(r'[0-9]+', '""', line)
|
||||
templine = re.sub(r'\"\"', key["env"]["mcc"], templine, 1)
|
||||
templine = re.sub(r'\"\"', key["env"]["mnc"], templine, 1)
|
||||
templine = re.sub(r'\"\"', key["env"]["mnc_length"], templine, 1)
|
||||
elif re.search('downlink_frequency', line):
|
||||
templine = re.sub(r'[0-9]+', key["env"], line)
|
||||
elif re.search('uplink_frequency_offset', line):
|
||||
templine = re.sub(r'[0-9]+', key["env"], line)
|
||||
|
||||
elif re.search(r'"(.*?)"', line):
|
||||
templine = re.sub(r'(?<=")[^"]*(?=")', key["env"], line)
|
||||
elif re.search(r'[0-9]', line):
|
||||
templine = re.sub(r'\d+', key["env"], line)
|
||||
outputfile.write(templine)
|
||||
|
||||
if count == 0:
|
||||
outputfile.write(line)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user