def getminerconfig(miner: Miner, login): '''ger the miner config file''' connection = Ssh(miner.ipaddress, login.username, login.password, port=getportfromminer(miner)) config = connection.exec_command('cat /config/{0}.conf'.format( getminerfilename(miner))) connection.close_connection() return config
def restartminer(miner: Miner, login): '''restart miner through ssh''' connection = Ssh(miner.ipaddress, login.username, login.password, port=getportfromminer(miner)) connection.open_shell() connection.send_shell('/etc/init.d/{0}.sh restart'.format(getminerfilename(miner))) time.sleep(15) print_connection_data(connection) connection.close_connection()
def sendcommands_and_restart(miner: Miner, login, commands): connection = Ssh(miner.ipaddress, login.username, login.password, port=getportfromminer(miner)) connection.open_shell() for cmd in commands: connection.send_shell(cmd) time.sleep(5) print_connection_data(connection) connection.close_connection() restartminer(miner, login)
def changesshpassword(miner: Miner, oldlogin, newlogin): """ change the factory ssh password """ if newlogin.username != oldlogin.username: print("changesshpassword: currently username change is not supported. only change password") return connection = Ssh(miner.ipaddress, oldlogin.username, oldlogin.password, port=getportfromminer(miner)) connection.open_shell() connection.send_shell('echo "{0}:{1}" | chpasswd'.format(newlogin.username, newlogin.password)) time.sleep(5) print_connection_data(connection) connection.close_connection()
def reboot(miner: Miner, login): """ reboot the miner through ftp """ connection = Ssh(miner.ipaddress, login.username, login.password, port=getportfromminer(miner)) connection.open_shell() response = connection.exec_command('/sbin/reboot') print_connection_data(connection) connection.close_connection() return response
def miner_shell_command(miner: Miner, login, command, timetorun): '''send the command stop/restart to miner shell command''' connection = Ssh(miner.ipaddress, login.username, login.password, port=getportfromminer(miner)) connection.open_shell() connection.send_shell('/etc/init.d/{0}.sh {1}'.format( getminerfilename(miner), command)) time.sleep(timetorun) print_connection_data(connection) connection.close_connection()
def shutdown(miner: Miner, login): """ shutdown the miner through ftp Warning! this will not turn off the power to the machine! It will only shut down the operating system. Machine will still be consuming power if power supply does not have on/off switch. You will have to manually restart the machine. """ connection = Ssh(miner.ipaddress, login.username, login.password, port=getportfromminer(miner)) connection.open_shell() connection.send_shell('/sbin/poweroff') time.sleep(5) print_connection_data(connection) connection.close_connection()
def file_download(miner, login, localfile, remotefile): connection = Ssh(miner.ipaddress, login.username, login.password, port=getportfromminer(miner)) connection.get(localfile, remotefile)