Ajout TP-02

This commit is contained in:
2025-11-13 09:34:59 +01:00
parent 5c7fa4d11a
commit ef4dffe5ef
11 changed files with 279 additions and 13 deletions

View File

@@ -4,21 +4,37 @@ from jinja2 import Template, Environment, FileSystemLoader
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 load_yaml_data_from_file(file_path):
with open(file_path) as yaml_file:
data = yaml.safe_load(yaml_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_vlan_config_cpe_marseille():
"""
Must return two values : router config and the switch config
"""
pass
esw2_data = load_json_data_from_file(file_path='data/vlan_ESW2.json')
esw2_config = render_network_config(template_name='vlan_switch.j2', data=esw2_data)
R2_data = load_json_data_from_file(file_path='data/vlan_R02.json')
R2_config = render_network_config(template_name='vlan_router.j2', data=R2_data)
return R2_config,esw2_config
def create_vlan_config_cpe_paris():
@@ -32,9 +48,9 @@ if __name__ == "__main__":
"""
process question 1 to 5:
"""
# r02_config, esw2_config = create_vlan_config_cpe_marseille()
# save_built_config('config/vlan_R02.conf', r02_config)
# save_built_config('config/vlan_ESW2.conf', esw2_config)
r02_config, esw2_config = create_vlan_config_cpe_marseille()
save_built_config('config/vlan_R02.conf', r02_config)
save_built_config('config/vlan_ESW2.conf', esw2_config)
# r03_config, esw3_config = create_vlan_config_cpe_paris()
# save_built_config('config/vlan_R03.conf', r03_config)