summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author赵坤 <[email protected]>2024-05-28 08:42:48 +0000
committer赵坤 <[email protected]>2024-05-28 08:42:48 +0000
commit48cdd3a4321f36b3897ff15f76b50d6a49c37901 (patch)
tree571dd49f540cb3d770f66accc5ee296c02452097
parent50d6f37067d2a558401bb91a4787a8d90bed17c4 (diff)
上传新文件
-rw-r--r--overwrite_yaml.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/overwrite_yaml.py b/overwrite_yaml.py
new file mode 100644
index 0000000..059510d
--- /dev/null
+++ b/overwrite_yaml.py
@@ -0,0 +1,25 @@
+import os
+import yaml
+
+class OverwriteYaml():
+ def __init__(self, path_dict):
+ self.traffic_playback_workpath = path_dict["traffic_playback_workpath"]
+ self.data_path = os.path.join(self.traffic_playback_workpath, "traffic_pcap")
+
+ def replace_from_yaml(self, yaml_name, pcap_name, clients_start="10.50.36.1", clients_end="10.50.36.1", servers_start="10.50.66.1", servers_end="10.50.66.1"):
+ # 组织yaml路径、pcap路径
+ yaml_abs_path = os.path.join(self.data_path, yaml_name)
+ pcap_abs_path = os.path.join(self.data_path, pcap_name)
+ #print(yaml_abs_path, pcap_abs_path)
+ with open(yaml_abs_path, "r", encoding="utf-8") as f:
+ result = yaml.load(f.read(), Loader=yaml.FullLoader)
+ # 修改pcap文件路径
+ result[0]["cap_info"][0]["name"] = pcap_abs_path
+ result[0]["generator"]["clients_start"] = clients_start
+ result[0]["generator"]["clients_end"] = clients_end
+ result[0]["generator"]["servers_start"] = servers_start
+ result[0]["generator"]["servers_end"] = servers_end
+ # 修改后重写数据
+ with open(yaml_abs_path, "w", encoding="utf-8") as f:
+ yaml.dump(result, f)
+ print(result) \ No newline at end of file