-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·76 lines (66 loc) · 2.36 KB
/
test.py
File metadata and controls
executable file
·76 lines (66 loc) · 2.36 KB
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
#!/usr/bin/env python
"""
Script to upgrade couple of Pluribus switches. Steps:
1/ Connect to the switch
2/ Enable SFTP on the switch
3/ Push the file on the local disk
4/ Upgrade the switch
"""
import paramiko
import getpass
#import netmiko
import os,sys,time,datetime
# Import hostfile from another directory
sys.path.insert(0, '/Users/pierregi/python/hostfiles/')
import socket
# Import lists of hosts as an object called devices
import hosts as devices
from netmiko import ConnectHandler
#print '!! Enter SSH UserName !!'
#ssh_username = raw_input("Username: ")
ssh_username = 'network-admin'
print '!! Enter SSH Password !!'
ssh_password = getpass.getpass()
#print '!! Enter SFTP UserName !!'
#sftp_username = raw_input("Username: ")
print '!! Enter SFTP Password !!'
sftp_password = getpass.getpass()
#print 'Your SSH username is:',ssh_username
#print 'Your SSH password is:',ssh_password
#print 'Your SFTP username is:',sftp_username
#print 'Your SFTP password is:',sftp_password
switch = {
'device_type': 'pluribus',
'ip': '10.36.10.37',
'username': ssh_username,
'password': ssh_password,
'port': 22,
'verbose': True,
}
net_connect = ConnectHandler(**switch)
output = net_connect.send_command('admin-sftp-show')
print '1st output is:\n' + output + '\n'
output = net_connect.send_command_timing('admin-sftp-modify enable', strip_command=False, strip_prompt=False)
print '2nd output is:\n' + output + '\n'
#prompt = net_connect.find_prompt()
time.sleep(3)
#if 'sftp password' in output:
# output += net_connect.send_command_timing("test123\n", strip_command=False, strip_prompt=False)
# print '3rd output is:\n' + output + '\n'
#if 'confirm sftp password' in output:
# output += net_connect.send_command_timing("test123\n", strip_command=False, strip_prompt=False)
# print '4th output is:\n' + output + '\n'
while 'sftp password' in output:
output = net_connect.send_command_timing("test123\n", strip_command=False, strip_prompt=False)
print '3rd output is:\n' + output + '\n'
#net_connect.write_channel(sftp_password + '\n')
#time.sleep(3)
#time.sleep(5)
#net_connect.send_command('test123')
#net_connect.write_channel(sftp_password + '\n')
#time.sleep(5)
#net_connect.write_channel(sftp_password + '\n')
#time.sleep(5)
#output = net_connect.send_command('admin-sftp-show\n')
#print '5th output is:\n' + output + '\n'
net_connect.disconnect()