-
Notifications
You must be signed in to change notification settings - Fork 1
/
initial_config.py
63 lines (56 loc) · 1.99 KB
/
initial_config.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import sys
import telnetlib
import argparse
import yaml
import time
parser = argparse.ArgumentParser()
parser.add_argument('-t', action='store', dest='TOPOLOGY', help='topology file for which diagram needs to be generated')
args = parser.parse_args()
HOST = "127.0.0.1"
def basicConfig(host, port, hostname, ip):
tn = telnetlib.Telnet(host=host,port=port,timeout=20)
print("***************** opened port {} *************************".format(port))
config_set = ["delete chassis auto-image-upgrade \n",
"delete interfaces fxp0.0 family inet dhcp \n",
"set system services netconf ssh \n",
"set system services telnet \n",
"set system services ssh \n",
"set system services ssh root-login allow \n",
"set system scripts language python \n",
"set system host-name {} \n".format(hostname),
"set interfaces fxp0.0 family inet address {} \n".format(ip),
]
print("setting up root authentication")
tn.write(b"root \n")
tn.write(b"cli \n")
time.sleep(2)
tn.write(b"configure \n")
time.sleep(2)
tn.write(b"set system root-authentication plain-text-password \n")
time.sleep(2)
tn.write(b"juniper123\n")
time.sleep(2)
tn.write(b"juniper123\n")
time.sleep(2)
tn.write(b"commit \n")
time.sleep(5)
for list in config_set:
print(list)
tn.write(str.encode(list))
time.sleep(2)
tn.write(b"commit\n")
print("completed adding config list")
print("added the basic necessary config, you can now login to the box using ssh")
tn.close()
def main():
num = 0
with open(args.TOPOLOGY, 'r') as f:
mapp = yaml.safe_load(f)
for i in mapp["network_nodes"]:
num = num + 1
hostname = i["name"]
port = int(i["re_port"])
ip = "192.167.1."+str(num)+"/24"
basicConfig(HOST, port, hostname, ip)
if __name__ == "__main__" :
main()