def sftpConnect(f_key, ip, port, username, cryptPasswd, verbose): if verbose: print("\n--- Connecting with sftp ...") cmd = ("sftp " + " -P " + port + " -o UserKnownHostsFile=" + knownHostsFile + " " + username + "@" + ip) runSubprocess(cmd, verbose)
def sshCopyID(ip, port, username, keyFile, verbose): if verbose: print("\n--- Copying id ...") cmd = "ssh-copy-id -p " + port + " -i " + keyFile + " " + (username + "@" + ip) runSubprocess(cmd, verbose)
def sshConnect(ip, port, username, extra, verbose): if verbose: print("\n--- Connecting with ssh " + extra + " ...") cmd = ("ssh " + ip + " -l " + username + " -p " + port + " -o UserKnownHostsFile=" + knownHostsFile + " " + extra) runSubprocess(cmd, verbose)
def sshCreateKey(verbose): if verbose: print("\n--- Checking if there is a key at " + rsaPublicKey) if os.path.isfile(rsaPublicKey): if verbose: print(" OK") keyFile = rsaPublicKey else: keyDir = os.path.dirname(rsaPublicKey) print( "\nCould not find key file at " + rsaPublicKey + "\n\nIf file is at other location, state full path, \nor leave empty to create key pair in\n" + rsaPublicKey) keyFile = input(" ? ") if keyFile: if not os.path.isfile(keyFile): keyDir = os.path.dirname(keyFile) keyFile = os.path.splitext(keyFile)[0] print( "\nCould not find that file either\nDo you want to create key pair at " + keyFile + "?") answer = input("n/Y") if answer.lower() != "n": print("\nWill create key pair at " + keyFile + "\n\n----------") else: keyFile = rsaPublicKey keyFile = os.path.splitext(keyFile)[0] print("\nWill create key pair at " + keyFile + "\n\n----------") keyDir = os.path.dirname(keyFile) if keyDir == "": keyDir = "./" if not os.path.isdir(keyDir): try: os.makedirs(keyDir, exist_ok=False) except: onError(6, ("Could not create directory " + keyDir)) cmd = "ssh-keygen -f " + keyFile runSubprocess(cmd, verbose) return keyFile
if status: output = groupSettings(verbose) output = output.split("\n") for line in output: print(line) sys.exit(0) if on: cmd = cmd + deviceOn(verbose) if volt: cmd = cmd + setVolt(group, volt, verbose) if ampere: cmd = cmd + setAmps(group, ampere, verbose) if loadGroup: cmd = cmd + useGroup(group, verbose) # check if device exists if os.system("ls " + devicePath) != 0: onError(7, "Device '" + devicePath + "' does not exist") #if verbose: # cmd = cmd + " --debug" runSubprocess(cmd, verbose)