-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_junos.py
77 lines (60 loc) · 1.51 KB
/
set_junos.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from Exscript.protocols import SSH2
from Exscript.Account import Account
username = 'user1'
password = 'pass1'
ipv4 = '192.168.0.1'
session = SSH2()
session.connect(ipv4)
session.login(Account(name=username, password=password))
print '='*40
print 'Step 1. run show command'
print '='*40
session.execute('show configuration interfaces xe-0/0/0 | no-more')
print session.response
print '='*40
print 'Step 2. read config file'
print '='*40
config_filename = sys.argv[1]
with open(config_filename, 'r') as config_file :
config_lines = config_file.readlines()
print config_filename
print config_lines
print '='*40
print 'Step 3. run configure command'
print '='*40
session.execute('configure')
for config_line in config_lines :
session.execute(config_line)
print session.response
print '='*40
print 'Step 4. commit check'
print '='*40
session.execute('show | compare')
print session.response
session.execute('commi check')
print session.response
print '='*40
print 'Step 5. commit'
print '='*40
print 'Do you commit? y/n'
choice = raw_input().lower()
if choice == 'y':
session.execute('commit')
print session.response
else:
session.execute('rollback')
print session.response
session.execute('exit')
print session.response
print '='*40
print 'Step 6. run show command(again)'
print '='*40
session.execute('show configuration interfaces xe-0/0/0 | no-more')
print session.response
if session:
session.send('exit\r')
session.close()
else: