-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
38 lines (31 loc) · 1.32 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import asyncio
import aiofiles
from jinja2 import Environment, FileSystemLoader
from app.contants import PROJECT_ID
from app.gns3_project import GNS3Project
from app.device import Device
MAX_NUMBER_ROUTER = 1000
async def generate_dhcp_config():
env = Environment(loader=FileSystemLoader("app/templates"))
template = env.get_template('dhcp2.j2')
msg = template.render()
async with aiofiles.open("output/dhcpd2.conf", "w") as f:
f.write(msg)
async def main():
# devices = [Device.from_sequence_num(i) for i in range(1, MAX_NUMBER_ROUTER + 1)]
# await generate_dhcp_config()
nodes_data = await GNS3Project.fetch_from_id(PROJECT_ID)
# group = ["Switch1", "Switch2", "Switch3", "Switch4"]
group = ["Switch3", "Switch4"]
for k in range(len(group)):
for i, node in enumerate(nodes_data):
if node["name"] == group[k]:
print("{} coordinates: {} {}".format(group[k], node["x"], node["y"]))
x_sw, y_sw, node_id_sw = node["x"], node["y"], node["node_id"]
for i in range(0, 50):
node_id_router = GNS3Project.add_router(k, i, x_sw, y_sw)
GNS3Project.add_link(i, node_id_sw, node_id_router)
breakpoint()
# TODO: Add asyncio context manager
if __name__ == "__main__":
asyncio.run(main())