ajout name dans json, correction champ equipement matrice de routage, correction doublon headers matrice de routage
This commit is contained in:
@@ -44,6 +44,9 @@ def export_to_excel(json_file_path, output_file_excel):
|
|||||||
|
|
||||||
for ni in network_instances:
|
for ni in network_instances:
|
||||||
equipement = ni.get("name", "")
|
equipement = ni.get("name", "")
|
||||||
|
fw_names = data.get("firewall-device", {}).get("name", [])
|
||||||
|
if equipement not in fw_names:
|
||||||
|
equipement = ", ".join(fw_names)
|
||||||
|
|
||||||
protocols = ni.get("protocols", {}).get("protocol", [])
|
protocols = ni.get("protocols", {}).get("protocol", [])
|
||||||
for proto in protocols:
|
for proto in protocols:
|
||||||
@@ -84,7 +87,7 @@ def export_to_excel(json_file_path, output_file_excel):
|
|||||||
df = pd.DataFrame(rows)
|
df = pd.DataFrame(rows)
|
||||||
|
|
||||||
with pd.ExcelWriter(output_file_excel, engine="openpyxl") as writer:
|
with pd.ExcelWriter(output_file_excel, engine="openpyxl") as writer:
|
||||||
df.to_excel(writer,sheet_name="Routes statiques",index=False,startrow=1)
|
df.to_excel(writer,sheet_name="Routes statiques",index=False,startrow=1,header=False)
|
||||||
|
|
||||||
wb = load_workbook(output_file_excel)
|
wb = load_workbook(output_file_excel)
|
||||||
if "Sheet1" in wb.sheetnames:
|
if "Sheet1" in wb.sheetnames:
|
||||||
|
|||||||
@@ -6,11 +6,12 @@ Fournit des méthodes communes pour la conversion et l'exportation des données
|
|||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
|
|
||||||
class ParserMixin:
|
class ParserMixin:
|
||||||
def to_openconfig_yang(self, type) -> Dict[str, Any]:
|
def to_openconfig_yang(self, type, name) -> Dict[str, Any]:
|
||||||
"""Convertit la configuration au format OpenConfig YANG avec les nouveaux modèles"""
|
"""Convertit la configuration au format OpenConfig YANG avec les nouveaux modèles"""
|
||||||
openconfig = {
|
openconfig = {
|
||||||
"firewall-device": {
|
"firewall-device": {
|
||||||
"type": type
|
"type": type,
|
||||||
|
"name": name
|
||||||
},
|
},
|
||||||
"openconfig-interfaces:interfaces": {
|
"openconfig-interfaces:interfaces": {
|
||||||
"interface": []
|
"interface": []
|
||||||
|
|||||||
@@ -189,7 +189,8 @@ class ForcepointParser(ParserMixin):
|
|||||||
|
|
||||||
def export_to_json(self, output_file: str):
|
def export_to_json(self, output_file: str):
|
||||||
"""Exporte la configuration au format JSON OpenConfig"""
|
"""Exporte la configuration au format JSON OpenConfig"""
|
||||||
openconfig_data = self.to_openconfig_yang("forcepoint")
|
fw_names = [cluster.get("name") for cluster in self.root.findall(".//fw_cluster")]
|
||||||
|
openconfig_data = self.to_openconfig_yang("forcepoint", fw_names)
|
||||||
|
|
||||||
with open(output_file, 'w', encoding='utf-8') as f:
|
with open(output_file, 'w', encoding='utf-8') as f:
|
||||||
json.dump(openconfig_data, f, indent=2, ensure_ascii=False)
|
json.dump(openconfig_data, f, indent=2, ensure_ascii=False)
|
||||||
|
|||||||
@@ -451,7 +451,11 @@ class PaloAltoParser(ParserMixin):
|
|||||||
|
|
||||||
def export_to_json(self, output_file: str):
|
def export_to_json(self, output_file: str):
|
||||||
"""Exporte la configuration au format JSON OpenConfig"""
|
"""Exporte la configuration au format JSON OpenConfig"""
|
||||||
openconfig_data = self.to_openconfig_yang("palo-alto")
|
fw_name = ""
|
||||||
|
deviceconfig = self.root.find(".//deviceconfig/system/hostname")
|
||||||
|
if deviceconfig is not None and deviceconfig.text:
|
||||||
|
fw_name = deviceconfig.text.strip()
|
||||||
|
openconfig_data = self.to_openconfig_yang("palo-alto", [fw_name])
|
||||||
|
|
||||||
with open(output_file, 'w', encoding='utf-8') as f:
|
with open(output_file, 'w', encoding='utf-8') as f:
|
||||||
json.dump(openconfig_data, f, indent=2, ensure_ascii=False)
|
json.dump(openconfig_data, f, indent=2, ensure_ascii=False)
|
||||||
|
|||||||
@@ -390,6 +390,18 @@ class StormshieldParser(ParserMixin):
|
|||||||
|
|
||||||
self.config["security_rules"].append(rule)
|
self.config["security_rules"].append(rule)
|
||||||
|
|
||||||
|
def _parse_name(self):
|
||||||
|
"""Parse le nom du firewall depuis le fichier network"""
|
||||||
|
path = os.path.join(self.base_dir, "network")
|
||||||
|
fw_name = ""
|
||||||
|
with open(path, "r", encoding="utf-8", errors="ignore") as f:
|
||||||
|
for line in f:
|
||||||
|
line = line.strip()
|
||||||
|
if line.startswith("Name="):
|
||||||
|
fw_name = line.split("=", 1)[1].strip()
|
||||||
|
break
|
||||||
|
return fw_name
|
||||||
|
|
||||||
|
|
||||||
def _extract_comment(self, line: str) -> str:
|
def _extract_comment(self, line: str) -> str:
|
||||||
"""Extrait un commentaire après #"""
|
"""Extrait un commentaire après #"""
|
||||||
@@ -409,7 +421,7 @@ class StormshieldParser(ParserMixin):
|
|||||||
|
|
||||||
def export_to_json(self, output_file: str):
|
def export_to_json(self, output_file: str):
|
||||||
"""Exporte la configuration au format JSON OpenConfig"""
|
"""Exporte la configuration au format JSON OpenConfig"""
|
||||||
openconfig_data = self.to_openconfig_yang("stormshield")
|
openconfig_data = self.to_openconfig_yang("stormshield", [self._parse_name()])
|
||||||
|
|
||||||
with open(output_file, 'w', encoding='utf-8') as f:
|
with open(output_file, 'w', encoding='utf-8') as f:
|
||||||
json.dump(openconfig_data, f, indent=2, ensure_ascii=False)
|
json.dump(openconfig_data, f, indent=2, ensure_ascii=False)
|
||||||
|
|||||||
Reference in New Issue
Block a user