完善极光配置,格式化代码
This commit is contained in:
43
main.py
43
main.py
@@ -1,11 +1,11 @@
|
||||
from librouteros import connect,Api
|
||||
from librouteros import connect, Api
|
||||
import csv
|
||||
import ssl
|
||||
import threading
|
||||
|
||||
from steps import *
|
||||
|
||||
'''
|
||||
"""
|
||||
自动配置 ros 脚本,需要安装 librouteros 库:
|
||||
|
||||
```
|
||||
@@ -25,21 +25,25 @@ pip install librouteros
|
||||
如果需要添加或修改配置项,从 config.*.bak.csv 文件复制配置项到 config.csv 文件中
|
||||
|
||||
如果需要修改配置内容,在下面 “配置执行步骤” 部分添加或修改函数调用
|
||||
'''
|
||||
"""
|
||||
|
||||
threads = []
|
||||
failed = []
|
||||
|
||||
# 配置执行步骤
|
||||
steps = [
|
||||
configNet
|
||||
configNet,
|
||||
configJgAuth,
|
||||
configJgMixOuts,
|
||||
configJgScripts,
|
||||
configJgLogs,
|
||||
]
|
||||
|
||||
|
||||
def main():
|
||||
# 加载配置文件
|
||||
config_data = []
|
||||
with open('config.csv', 'r', encoding='utf-8-sig') as file:
|
||||
with open("config.csv", "r", encoding="utf-8-sig") as file:
|
||||
reader = csv.DictReader(file)
|
||||
for row in reader:
|
||||
config_data.append(row)
|
||||
@@ -55,13 +59,22 @@ def main():
|
||||
thread.join()
|
||||
|
||||
# 输出结果
|
||||
print('=' * 20)
|
||||
print('配置完成统计({}/{}), 失败项:{}'.format(len(config_data)-len(failed), len(config_data), len(failed)))
|
||||
print("=" * 20)
|
||||
print(
|
||||
"配置完成统计({}/{}), 失败项:{}".format(
|
||||
len(config_data) - len(failed), len(config_data), len(failed)
|
||||
)
|
||||
)
|
||||
for _, (item, err) in enumerate(failed):
|
||||
print('{},{},{},{}'.format(item['public'], item['name'], item['code'], err))
|
||||
print("{},{},{},{}".format(item["public"], item["name"], item["code"], err))
|
||||
|
||||
|
||||
def start(config):
|
||||
print('{}: 配置{}({})'.format(str(config['index']).zfill(3), config['name'], config['code']))
|
||||
print(
|
||||
"{}: 配置{}({})".format(
|
||||
str(config["index"]).zfill(3), config["name"], config["code"]
|
||||
)
|
||||
)
|
||||
|
||||
# 连接到 ros
|
||||
conn: Api
|
||||
@@ -70,14 +83,14 @@ def start(config):
|
||||
ctx.check_hostname = False
|
||||
ctx.load_verify_locations(f'certs/{config["cert"]}')
|
||||
conn = connect(
|
||||
username='admin',
|
||||
password='wyongk9815',
|
||||
host=config['public'],
|
||||
username="admin",
|
||||
password="wyongk9815",
|
||||
host=config["public"],
|
||||
port=8729,
|
||||
ssl_wrapper=ctx.wrap_socket,
|
||||
)
|
||||
except Exception as err:
|
||||
failed.append((config, f'连接失败: {err}'))
|
||||
failed.append((config, f"连接失败: {err}"))
|
||||
return
|
||||
|
||||
# 配置 ros
|
||||
@@ -85,10 +98,10 @@ def start(config):
|
||||
for step in steps:
|
||||
step(conn, config)
|
||||
except Exception as err:
|
||||
failed.append((config, f'配置失败: {err}'))
|
||||
failed.append((config, f"配置失败: {err}"))
|
||||
|
||||
# 关闭连接
|
||||
conn.close()
|
||||
|
||||
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user