You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
957 B
Python
28 lines
957 B
Python
import ssh
|
|
import csv
|
|
from util import fprint
|
|
from util import find_data_file
|
|
from time import sleep
|
|
|
|
def login(config, user, password, sysid):
|
|
fprint("Attempting to login as " + user)
|
|
filename = sysid + "login.csv"
|
|
with open(find_data_file(filename), "w", newline="") as f:
|
|
writer = csv.writer(f)
|
|
writer.writerows([[user,password,sysid],])
|
|
fprint("done creating csv")
|
|
ssh.sftp_send_data(config, filename, 'sendlogin')
|
|
command = "python3 login_service.py " + sysid
|
|
ssh.run_ssh(config, command, 'scripts')
|
|
sleep(1)
|
|
filename = sysid + "success.txt"
|
|
output = ssh.check_for_file(config, filename, 'receivelogin')
|
|
if output == False:
|
|
filename = sysid + "fail.txt"
|
|
if ssh.check_for_file(config, filename, 'receivelogin') == False:
|
|
raise ValueError("Unable to determine login status")
|
|
else:
|
|
return False
|
|
else:
|
|
return True
|
|
fprint(output) |