Question 5
This commit is contained in:
@@ -5,41 +5,66 @@ env = Environment(loader=FileSystemLoader("templates"))
|
||||
|
||||
|
||||
def load_json_data_from_file(file_path):
|
||||
pass
|
||||
|
||||
with open(file_path) as json_file:
|
||||
data = json.load(json_file)
|
||||
return data
|
||||
def render_network_config(template_name, data):
|
||||
pass
|
||||
template = env.get_template(template_name)
|
||||
return template.render(data)
|
||||
|
||||
def save_built_config(file_name, data):
|
||||
pass
|
||||
with open(file_name, "w") as f:
|
||||
f.write(data)
|
||||
return file_name
|
||||
|
||||
|
||||
def create_config_cpe_lyon_batA():
|
||||
esw3_data = load_json_data_from_file(file_path='data/vlan_ESW3.json')
|
||||
esw3_config = render_network_config(template_name='vlan_switch.j2', data=esw3_data)
|
||||
ESW1_CPE_LYON_BAT_A_data= load_json_data_from_file(file_path='data/ESW1_CPE_LYON_BAT_A.json')
|
||||
ESW1_CPE_LYON_BAT_A_config = render_network_config(template_name='vlan_switch.j2', data=ESW1_CPE_LYON_BAT_A_data)
|
||||
|
||||
R3_data = load_json_data_from_file(file_path='data/vlan_R03.json')
|
||||
R3_config = render_network_config(template_name='vlan_router.j2', data=R3_data)
|
||||
return R3_config,esw3_config
|
||||
R2_LYON_BAT_A_data = load_json_data_from_file(file_path='data/R2_CPE_LYON_BAT_A.json')
|
||||
R2_LYON_BAT_A_config = render_network_config(template_name='vlan_router.j2', data=R2_LYON_BAT_A_data)
|
||||
|
||||
R1_LYON_BAT_A_data = load_json_data_from_file(file_path='data/R1_CPE_LYON_BAT_A.json')
|
||||
R1_LYON_BAT_A_config = render_network_config(template_name='vlan_router.j2', data=R1_LYON_BAT_A_data)
|
||||
|
||||
return {
|
||||
'esw1': ESW1_CPE_LYON_BAT_A_config,
|
||||
'r1': R1_LYON_BAT_A_config,
|
||||
'r2': R2_LYON_BAT_A_config
|
||||
}
|
||||
|
||||
def create_config_cpe_lyon_batB():
|
||||
pass
|
||||
ESW1_CPE_LYON_BAT_B_data= load_json_data_from_file(file_path='data/ESW1_CPE_LYON_BAT_B.json')
|
||||
ESW1_CPE_LYON_BAT_B_config = render_network_config(template_name='vlan_switch.j2', data=ESW1_CPE_LYON_BAT_B_data)
|
||||
|
||||
R2_LYON_BAT_B_data = load_json_data_from_file(file_path='data/R2_CPE_LYON_BAT_B.json')
|
||||
R2_LYON_BAT_B_config = render_network_config(template_name='vlan_router.j2', data=R2_LYON_BAT_B_data)
|
||||
|
||||
R1_LYON_BAT_B_data = load_json_data_from_file(file_path='data/R1_CPE_LYON_BAT_B.json')
|
||||
R1_LYON_BAT_B_config = render_network_config(template_name='vlan_router.j2', data=R1_LYON_BAT_B_data)
|
||||
|
||||
return {
|
||||
'esw1': ESW1_CPE_LYON_BAT_B_config,
|
||||
'r1': R1_LYON_BAT_B_config,
|
||||
'r2': R2_LYON_BAT_B_config
|
||||
}
|
||||
|
||||
if __name__ == "__main__":
|
||||
"""
|
||||
process question 3 to 5:
|
||||
"""
|
||||
#question 3:
|
||||
#config = create_config_cpe_lyon_batA()
|
||||
config = create_config_cpe_lyon_batA()
|
||||
|
||||
#question 4:
|
||||
# save_built_config('config/R1_CPE_LYON_BAT_A.conf', config.get('r1'))
|
||||
# save_built_config('config/R2_CPE_LYON_BAT_A.conf', config.get('r2'))
|
||||
# save_built_config('config/ESW1_CPE_LYON_BAT_A.conf', config.get('esw1'))
|
||||
save_built_config('config/R1_CPE_LYON_BAT_A.conf', config.get('r1'))
|
||||
save_built_config('config/R2_CPE_LYON_BAT_A.conf', config.get('r2'))
|
||||
save_built_config('config/ESW1_CPE_LYON_BAT_A.conf', config.get('esw1'))
|
||||
|
||||
#question 5:
|
||||
# config = create_config_cpe_lyon_batB()
|
||||
# save_built_config('config/R1_CPE_LYON_BAT_B.conf', config.get('r1'))
|
||||
# save_built_config('config/R2_CPE_LYON_BAT_B.conf', config.get('r2'))
|
||||
# save_built_config('config/ESW1_CPE_LYON_BAT_B.conf', config.get('esw1'))
|
||||
config = create_config_cpe_lyon_batB()
|
||||
save_built_config('config/R1_CPE_LYON_BAT_B.conf', config.get('r1'))
|
||||
save_built_config('config/R2_CPE_LYON_BAT_B.conf', config.get('r2'))
|
||||
save_built_config('config/ESW1_CPE_LYON_BAT_B.conf', config.get('esw1'))
|
||||
|
||||
Reference in New Issue
Block a user