parent
09836efcc4
commit
44166a2507
@ -0,0 +1,26 @@
|
||||
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"
|
||||
if ssh.check_for_file(config, filename, 'receivelogin') == 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
|
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,39 @@
|
||||
#from __future__ import with_statement
|
||||
from fabric import Connection
|
||||
from util import find_data_file
|
||||
from util import setup_child
|
||||
from util import fprint
|
||||
from invoke import exceptions
|
||||
import sys
|
||||
|
||||
def sftp_send_data(res, config, filename):
|
||||
def sftp_send_data(config, filename, filetype):
|
||||
setup_child()
|
||||
fprint("Connecting over SSH to " + config['sftp']['host'])
|
||||
c = Connection(host=config['sftp']['host'], user=config['sftp']['user'], port=config['sftp']['port'], connect_kwargs={"key_filename": find_data_file(config['sftp']['keyfile']),})
|
||||
fprint("Sending data over SFTP: " + filename)
|
||||
fprint(c.put(find_data_file(filename), remote=config['sftp']['filepath']['send']))
|
||||
fprint("Data sent over SFTP sucessfully")
|
||||
#command = 'ls ' + config['sftp']['filepath']['send']
|
||||
#fprint(c.run(command))
|
||||
fprint(c.put(find_data_file(filename), remote=config['sftp']['filepath'][filetype]))
|
||||
fprint("Data sent over SFTP successfully")
|
||||
#command = 'ls ' + config['sftp']['filepath'][filetype]
|
||||
#fprint(c.run(command))
|
||||
|
||||
def check_for_file(config, filename, location):
|
||||
setup_child()
|
||||
fprint("Connecting over SSH to " + config['sftp']['host'])
|
||||
c = Connection(host=config['sftp']['host'], user=config['sftp']['user'], port=config['sftp']['port'], connect_kwargs={"key_filename": find_data_file(config['sftp']['keyfile']),})
|
||||
fprint("Checking for existence of file " + config['sftp']['filepath'][location] + "/" + filename)
|
||||
try:
|
||||
res = c.run("ls -l " + config['sftp']['filepath'][location] + "/" + filename, hide=True)
|
||||
fprint("File " + filename + " exists!")
|
||||
return c.run("cat " + config['sftp']['filepath'][location] + "/" + filename, hide=True)
|
||||
except exceptions.UnexpectedExit:
|
||||
return False
|
||||
|
||||
def run_ssh(config, command, location):
|
||||
setup_child()
|
||||
fprint("Connecting over SSH to " + config['sftp']['host'])
|
||||
c = Connection(host=config['sftp']['host'], user=config['sftp']['user'], port=config['sftp']['port'], connect_kwargs={"key_filename": find_data_file(config['sftp']['keyfile']),})
|
||||
fprint("cd to " + config['sftp']['filepath'][location])
|
||||
with c.cd(config['sftp']['filepath'][location]):
|
||||
fprint("Running ssh command: " + command)
|
||||
res = c.run(command, hide=True, asynchronous=True)
|
||||
return res
|
||||
|
Loading…
Reference in New Issue