copied workspace to master working tree
This commit is contained in:
parent
6f14aa0044
commit
99b92870a8
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,3 @@
|
|||
---schimba perimsiunile lui xboard.cfg
|
||||
---regex pt comanda select
|
||||
ffdc
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,7 @@
|
|||
#! /bin/bash
|
||||
|
||||
git add $1
|
||||
git status
|
||||
|
||||
git commit -m "$2"
|
||||
git push
|
|
@ -0,0 +1,10 @@
|
|||
- error checking - loadcfg.py - if xboard.cfg doesn't exist OR it contains invalid entries start with an empty server list and show an error
|
||||
- bugul cu afisarea
|
||||
- redirect stdout & stderr from commands so they won't be shown to the user
|
||||
- include sample xboard.cfg in repo with 1 line stating entries format
|
||||
- show BMC ip for each command output (e.g. server1 ... list of fans info; server 2 ... list of fans info etc)
|
||||
- prerequisites: python3, paramiko, libssl-dev, pip3 install cryptography==2.4.2
|
||||
|
||||
- la initializare
|
||||
- BMC is up/down - cu nc
|
||||
- daca BMC up, ruleaza 'power status' si verifica daca hostul e up sau down (cele down, vrei sa le pornesc? da/nu)
|
|
@ -0,0 +1,78 @@
|
|||
system> ?
|
||||
? -- Display command list
|
||||
accseccfg -- Account security configuration
|
||||
adapter -- Display the information of the PCIe adapters.
|
||||
alertcfg -- Display or change the BMC global remote alert parameters.
|
||||
alertentries -- This command manages the recipients of alerts.
|
||||
asu -- Set UEFI settings
|
||||
autopromo -- Automated promotion of BMC backup.
|
||||
backup -- Creates a backup file containing the current system settings.
|
||||
batch -- Executes CLI commands in a file for configuring settings.
|
||||
Note: The batch command is intended to configure settings, not to read them.
|
||||
Inclusion of commands that do not configure settings may result in errors.
|
||||
clearcfg -- Resets the BMC to its default settings
|
||||
clearlog -- Clear BMC event log
|
||||
clock -- Display/set date, time, GMT offset, and dst setting
|
||||
console -- Exit CLI, attach to serial console
|
||||
dbgshimm -- Enable secure debug shell (support personnel use only)
|
||||
dhcpinfo -- View DHCP server assigned settings
|
||||
dns -- Displays the current DNS configuration of the BMC.
|
||||
encaps -- Let BMC quit encapsulation mode
|
||||
ethtousb -- Display and configure ethernet to ethernet over usb
|
||||
port mapping
|
||||
exit -- Exit CLI (log off)
|
||||
fans -- Displays the fan speed for all system fans
|
||||
ffdc -- First Failure Data Capture (service data)
|
||||
firewall -- Display the firewall rules
|
||||
fuelg -- Display or set power usage settings
|
||||
gprofile -- Group Profiles
|
||||
hashpw -- Displays and configures the status of the Thirty-Party Password
|
||||
help -- Display command list
|
||||
history -- Display history of last 8 commands
|
||||
hreport -- Embedded Health Report
|
||||
hwlog -- Display the hardware activity log entries
|
||||
identify -- Control system locator LED
|
||||
ifconfig -- Ethernet and PPP configuration
|
||||
info -- Display and configure the information associated with the
|
||||
BMC
|
||||
keycfg -- Display, add or delete activation keys
|
||||
ldap -- LDAP configuration
|
||||
led -- Display LED states.
|
||||
ntp -- Displays and configures the Network Time Protocol
|
||||
portcfg -- Serial port configuration.
|
||||
portcontrol -- Display and control the corresponding port of service
|
||||
ports -- Display and configure port numbers
|
||||
power -- Control server power
|
||||
pxeboot -- Enable or disable pxe next boot status
|
||||
rdmount -- Remote mount
|
||||
readlog -- Displays the BMC event log, five entries at a time
|
||||
reset -- Reset server
|
||||
resetsp -- Reset BMC
|
||||
restore -- Restores the system settings using the input backup file.
|
||||
restoredefaults -- Reset all BMC settings to factory defaults
|
||||
sdemail -- Send service information using e-mail
|
||||
seccfg -- Firmware rollback
|
||||
set -- Display or set CLI environment variables
|
||||
smtp -- Display or set smtp server
|
||||
snmp -- Enable or disable the SNMP agent
|
||||
snmpalerts -- This command manages the recipients of snmp alerts
|
||||
spreset -- Reset BMC
|
||||
srcfg -- Serial redirection configuration
|
||||
sshcfg -- Display and configures SSH parameters
|
||||
ssl -- SSL configuration
|
||||
sslcfg -- Displays and configures the status of the SSL Server
|
||||
and SSL Client
|
||||
storage -- Display and configure the information of the storage.
|
||||
storekeycfg -- Add or delete storage key repository certificate.
|
||||
syshealth -- System Health
|
||||
temps -- Display system temperatures
|
||||
thermal -- Display and configures the thermal mode policy of the host
|
||||
system.
|
||||
timeouts -- Server timeouts configuration
|
||||
tls -- Set minimum TLS Level
|
||||
usbeth -- Enable or disable the inband (Ethernet over USB) interface
|
||||
usbfp -- Front panel USB configuration
|
||||
users -- User profile configuration
|
||||
volts -- Displays all the voltages and voltage thresholds
|
||||
vpd -- Display VPD
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
index,type,ip,state,fw_level,fw_version,release_date, uefi, uefi_release_date
|
||||
index,type,ip,state,fw_level,fw_version,release_date, uefi, uefi_release_date
|
|
|
@ -0,0 +1,44 @@
|
|||
import csv
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
def loadcfg():
|
||||
"Fill a dictionary with the fields [server], [port]"
|
||||
"[user] and [password]"
|
||||
|
||||
# Default cfg file. Name cannot be changed
|
||||
filename = 'xboard.cfg'
|
||||
|
||||
# Configure a dictionary of list with the following
|
||||
# fields
|
||||
|
||||
config = defaultdict(list)
|
||||
config.fromkeys(['server', 'user', 'password', 'port'])
|
||||
|
||||
try:
|
||||
with open(filename) as configFile:
|
||||
|
||||
# Reader for the config file which is saved as csv
|
||||
reader = csv.DictReader(configFile)
|
||||
|
||||
for row in reader:
|
||||
config['server'].append(row['server'])
|
||||
config['user'].append(row['user'])
|
||||
config['password'].append(row['password'])
|
||||
config['port'].append(row['port'])
|
||||
|
||||
except EnvironmentError:
|
||||
print("Error while trying to open xboard.cfg file")
|
||||
print("Check if file xboard.cfg exists!")
|
||||
print("It should be set as a csv file with the following fields:")
|
||||
print("[server],[user],[password],[port]")
|
||||
|
||||
# Return the filled dictionary
|
||||
return config
|
||||
|
||||
def main():
|
||||
print(loadcfg())
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -0,0 +1,37 @@
|
|||
import os
|
||||
from subprocess import PIPE, run, Popen
|
||||
import sys
|
||||
|
||||
# Check if pip3 is installed
|
||||
command = "pip3 -V"
|
||||
|
||||
pipCheck = run(command.split(' '),stdout=PIPE, stderr=PIPE)
|
||||
stderr = pipCheck.stderr
|
||||
|
||||
stderr = stderr.decode('utf-8')
|
||||
|
||||
if "not found" in stderr:
|
||||
install = os.system("sudo apt install python3-pip")
|
||||
if install == 0:
|
||||
print("pip3 was successfully installed")
|
||||
elif install != 0:
|
||||
print("pip3 couldnot be installed")
|
||||
|
||||
|
||||
# Check if paramiko module is installed
|
||||
if 'paramiko' not in sys.modules:
|
||||
|
||||
os.system("sudo pip3 install --upgrade setuptools")
|
||||
os.system("sudo apt-get install build-essential libssl-dev \
|
||||
libffi-dev python-dev")
|
||||
os.system("sudo pip3 install cryptography")
|
||||
|
||||
os.system("sudo pip3 install paramiko")
|
||||
|
||||
if install == 0:
|
||||
print("paramiko was successfully installed")
|
||||
elif install != 0:
|
||||
print("paramiko couldnot be installed")
|
||||
|
||||
# I was testing for arch linux and saw it has not the nc tool
|
||||
# Install furthermore nc
|
|
@ -0,0 +1,3 @@
|
|||
string = 'aaaa bbb cc dddddddddd '
|
||||
string = string.split()
|
||||
print(string)
|
|
@ -0,0 +1,141 @@
|
|||
import datetime
|
||||
import os
|
||||
import paramiko
|
||||
import loadcfg
|
||||
|
||||
def filewrite(func, ssh, servers):
|
||||
with open('xboard.log', 'a+') as log:
|
||||
|
||||
# If the file is not empty place two lines between
|
||||
# every set of info
|
||||
if os.stat("xboard.log").st_size != 0:
|
||||
log.write("\n\n")
|
||||
|
||||
sshLength = len(ssh)
|
||||
|
||||
now = datetime.datetime.now()
|
||||
|
||||
# Date and time info about log
|
||||
log.write('Informations about %s at %s\n' % (func, now.strftime("%Y-%m-%d %H:%M")))
|
||||
|
||||
# Writing stdout of commands into file
|
||||
for i in range(0, sshLength):
|
||||
ssh_stdin, ssh_stdout, ssh_stderr = ssh[i].exec_command(func)
|
||||
for line in ssh_stdout.read().splitlines():
|
||||
log.write('%s\n' % line.decode('utf-8'))
|
||||
for linerr in ssh_stderr.read().splitlines():
|
||||
log.write('%s at %s on port %s\n' % (linerr.decode('utf-8'), \
|
||||
servers['server'][i], servers['port'][i]))
|
||||
|
||||
def connect(servers):
|
||||
|
||||
data = servers
|
||||
dataLength = len(data['server'])
|
||||
|
||||
ssh = []
|
||||
|
||||
for i in range(0, dataLength):
|
||||
# This line creates a new cell in the list with a ssh object
|
||||
ssh.append(paramiko.SSHClient())
|
||||
ssh[i].set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
ssh[i].connect(data['server'][i], port = int(data['port'][i]), \
|
||||
username=data['user'][i], password=data['password'][i])
|
||||
|
||||
return ssh
|
||||
|
||||
def powerstatus(server, user, password, port):
|
||||
connection = paramiko.SSHClient()
|
||||
connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
connection.connect(server, int(port), user, password)
|
||||
ssh_stdin, ssh_stdout, ssh_stderr = connection.exec_command('power state')
|
||||
|
||||
pwstatus = 'test'
|
||||
|
||||
try:
|
||||
tmp = ssh_stdout.read().splitlines()
|
||||
pwstatus = tmp[0].decode('utf-8')
|
||||
except:
|
||||
print("exception powerstatus")
|
||||
|
||||
connection.close()
|
||||
|
||||
##return stdout or stdout
|
||||
return pwstatus
|
||||
|
||||
def poweron(server, user, password, port):
|
||||
connection = paramiko.SSHClient()
|
||||
connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
connection.connect(server, int(port), user, password)
|
||||
ssh_stdin, ssh_stdout, ssh_stderr = connection.exec_command('power on')
|
||||
|
||||
try:
|
||||
ssh_stdout = ssh_stdout.read().splitlines()[0].decode('utf-8')
|
||||
except:
|
||||
print("exception poweron")
|
||||
|
||||
connection.close()
|
||||
|
||||
print(ssh_stdout)
|
||||
|
||||
# Check if it was successful
|
||||
|
||||
def fw(server, user, password, port):
|
||||
|
||||
# List which contains first and third line with the fields
|
||||
# 2 and 4
|
||||
fw_list = []
|
||||
|
||||
connection = paramiko.SSHClient()
|
||||
connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
connection.connect(server, int(port), user, password)
|
||||
ssh_stdin, ssh_stdout, ssh_stderr = connection.exec_command('vpd fw')
|
||||
|
||||
try:
|
||||
tmp = ssh_stdout.read().splitlines()
|
||||
#bmc = ssh_stdout.read().splitlines()[3].decode('utf-8')
|
||||
bmc = tmp[2].decode('utf-8')
|
||||
#uefi = ssh_stdout.read().splitlines()[5].decode('utf-8')
|
||||
uefi = tmp[4].decode('utf-8')
|
||||
|
||||
bmc = bmc.split()
|
||||
uefi = uefi.split()
|
||||
|
||||
fw_list.append(bmc[0])
|
||||
fw_list.append(bmc[2])
|
||||
fw_list.append(bmc[4])
|
||||
fw_list.append(uefi[2])
|
||||
fw_list.append(uefi[4])
|
||||
|
||||
except:
|
||||
print("exception vpd fw")
|
||||
|
||||
connection.close()
|
||||
|
||||
return fw_list
|
||||
|
||||
def sys(server, user, password, port):
|
||||
|
||||
connection = paramiko.SSHClient()
|
||||
connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
connection.connect(server, int(port), user, password)
|
||||
ssh_stdin, ssh_stdout, ssh_stderr = connection.exec_command('vpd sys')
|
||||
|
||||
try:
|
||||
#type_model = ssh_stdout.read().splitlines()[2].decode('utf-8')
|
||||
tmp = ssh_stdout.read().splitlines()
|
||||
tmp1 = tmp[2].decode('utf-8')
|
||||
tmp2 = tmp1.split()
|
||||
type_model = tmp2[0]
|
||||
except:
|
||||
print("exception vpd sys")
|
||||
return "oops"
|
||||
|
||||
connection.close()
|
||||
|
||||
return type_model
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
-adauga comanda de afisare a informatiilor generale despre server
|
||||
- detaliere comenzi cu parametri
|
||||
- [eventual informatii suplimentare despre versiunea de firmware care ruleaza pe BMC (IMM2, XCC,...
|
||||
------------------
|
||||
|
||||
x>> checkup
|
||||
nc: connect to 192.168.1.11 port 22 (tcp) timed out: Operation now in progress
|
||||
Server 192.168.1.11 will be removed from servers list!
|
||||
|
||||
List of down servers:
|
||||
192.168.1.11 1234
|
||||
|
||||
==========================================================================================================================
|
||||
|
||||
export file csv
|
||||
index,type,serverIP,state,firmware level BMC/IMM2, BMC/IMM2 version + release date, fw level UEFI version + release date
|
||||
i++,vpd sys [0],serverIP,power state(on/off), vpd fw[0][2+4], vpd fw[2][2+4]
|
||||
|
||||
index,type,serverIP,state,firmware level BMC/IMM2, BMC/IMM2 version + release date, fw level UEFI version + release date
|
||||
1,7X82CTO2WW,10.241.18.3,on,BMC(Primary),1.90 (2018-06-22),1.30 (2018-06-15)
|
||||
2,7X82CTO2WW,10.241.18.4,on,IMM2(Primary),1.90 (2018-06-22),1.30 (2018-06-15)
|
||||
|
||||
vpd sys
|
||||
|
||||
system> Machine Type-Model Serial Number UUID
|
||||
-------------- --------- ----
|
||||
7X82CTO2WW 1234 1234
|
||||
|
||||
vpd fw
|
||||
|
||||
system> vpd fw
|
||||
Type Status Version BuildID ReleaseDate
|
||||
---- ------ ------- ------- -----------
|
||||
BMC(Primary) Active 1.90 12324 2018-06-22
|
||||
BMC(Backup) Inactive 1.90 1234 2018-06-22
|
||||
UEFI Active 1.30 1234 2018-06-15
|
||||
LXPM Active 1.00 1234 2017-05-26
|
||||
LXPM Windows Drivers Active 1.00 12434 2017-05-18
|
||||
LXPM Linux Drivers Active 1.00 123445 2017-05-18
|
||||
system>
|
||||
|
||||
system> vpd fw
|
||||
Type Status Version BuildID ReleaseDate
|
||||
---- ------ ------- ------- -----------
|
||||
IMM2(Primary) Active 5.30 1234 2019/01/22
|
||||
IMM2(Backup) Inactive 5.11 1234 2018/09/21
|
||||
UEFI(Primary) Active 2.90 1234 2019/02/13
|
||||
UEFI(Backup) Inactive 2.90 1234 2019/02/13
|
||||
DSA Active 10.3 1234 2018/05/15
|
||||
system>
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
server,user,password,port
|
||||
bandit.labs.overthewire.org,bandit1,boJ9jbbUNNfktd78OOpsqOltutMc3MY1,2220
|
||||
bandit.labs.overthewire.org,bandit2,CV1DtqXWVFXTvM2F0k09SHz0YwRINYA9,2220
|
||||
bandit.labs.overthewire.org,bandit3,UmHadQclWmgdLOKQ3YNgjWxGoRMb5luK,2220
|
||||
bandit.labs.overthewir4.og,bandit4,pIwrPrtPN36QITSp3EQaw936yaFoFgAB,2220
|
||||
bandit.labs.overthewir5.org,bandit5,koReBOKuIDDepwhWk7jZC0RTdopnAYKh,2220
|
||||
bandit.labs.overthewir5.org,bandit6,DXjZPULLxYr17uwoI01bNLQbtFemEgo7,2220
|
||||
bandit.labs.overthewir6.org,bandit7,HKBPTKQnIay4Fw76bEy8PVxKEDQRKTzs,2220
|
||||
bandit.labs.overthewir7.org,bandit8,cvX2JJa4CFALtqS87jk27qwqGhBM9plV,2220
|
||||
bandit.labs.overthewir8.org,bandit9,UsvVyFSfZZWbi6wgC7dAFyFuR6jQQUhR,2220
|
||||
bandit.labs.overthewir8.org,bandit10,truKLdjsbJ5g7yyJ2X2R0o3a5HQJFuLk,2220
|
||||
bandit.labs.overthewir9.rg,bandit11,IFukwKGsFW8MOq3IRFqrxE1hxTNEbUPR,2220
|
||||
bandit.labs.overthewir10.org,bandit12,5Te8Y4drgCRfCx8ugdwuEX8KFC6k2EUu,2220
|
||||
bandit.labs.overthewir11.org,bandit13,8ZjyCRiBWFYkneahHwxCv3wb2a1ORpYL,2220
|
||||
bandit.labs.overthewir12.org,bandit14,4wcYUJFw0k0XLShlDzztnTBHiqxU3b3e,2220
|
||||
bandit.labs.overthewir13.org,bandit15,BfMYroe26WYalil77FoDi9qh59eK5xNr,2220
|
||||
bandit.labs.overthewir14.org,bandit16,cluFn7wTiGryunymYOu4RcffSxQluehd,2220
|
||||
bandit.labs.overthewir16.org,bandit17,xLYVMN9WE5zQ5vHacb0sZEVqbrp7nBTn,2220
|
||||
bandit.labs.overthewir16.org,bandit18,kfBf3eYk5BPBRzwjqutbbfE887SVc5Yd,2220
|
||||
bandit.labs.overthewir17.org,bandit19,IueksS7Ubh8G3DCwVzrTd8rAVOwq3M5x,2220
|
||||
bandit.labs.overthewir18.org,bandit20,GbKksEFF4yrVs6il55v6gwY5aVje5f0j,2220
|
||||
bandit.labs.overthewir19.org,bandit21,gE269g2h3mw3pwgrj0Ha9Uoqen1c9DGr,2220
|
||||
bandit.labs.overthewir20.org,bandit22,Yk7owGAcWjwMVRwrTesJEwB7WVOiILLI,2220
|
||||
bandit.labs.overthewir21.org,bandit23,jc1udXuA1tiHqjIsL8yaapX5XIAI6i0n,2220
|
||||
bandit.labs.overthewir22.org,bandit24,UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ,2220
|
||||
141.85.224.99,connect,c0nn3ct,2222
|
||||
leviathan.labs.overthewire.org,leviathan0,leviathan0,2223
|
||||
leviathan.labs.overthewire.org,leviathan0,leviathan0,2223
|
||||
fdsa,fasd,das,12
|
||||
1234,dfa,fsdafsad,1111
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,822 @@
|
|||
from cmd import Cmd
|
||||
from subprocess import Popen, PIPE
|
||||
import argparse
|
||||
import datetime
|
||||
import traceback
|
||||
import os
|
||||
import sys
|
||||
import sidefun
|
||||
import readline
|
||||
import loadcfg
|
||||
import subprocess
|
||||
import getpass
|
||||
from collections import defaultdict
|
||||
|
||||
import warnings
|
||||
warnings.filterwarnings(action='ignore', module=".*paramiko.*")
|
||||
|
||||
histfile = os.path.expanduser('~/xboard/.xboard.history')
|
||||
histfile_size = 1000
|
||||
|
||||
class xBoard(Cmd):
|
||||
|
||||
# Prompt for shell tool
|
||||
prompt = 'x>> '
|
||||
|
||||
# When paramiko throws the output back to this script the prompt
|
||||
# 'system> ' is also included. So I will replace it in order to have
|
||||
# a cleaner output
|
||||
systemPrompt = 'system> '
|
||||
|
||||
# Initial servers info
|
||||
servers = loadcfg.loadcfg()
|
||||
|
||||
#List of servers which are powered off
|
||||
off = defaultdict(list)
|
||||
off.fromkeys(['server', 'user', 'password', 'port'])
|
||||
|
||||
|
||||
|
||||
# Keep track of command history using preloop
|
||||
# and postloop functions
|
||||
def preloop(self):
|
||||
if readline and os.path.exists(histfile):
|
||||
readline.read_history_file(histfile)
|
||||
|
||||
def postloop(self):
|
||||
if readline:
|
||||
readline.set_history_length(histfile_size)
|
||||
readline.write_history_file(histfile)
|
||||
########
|
||||
|
||||
def do_addserver(self, inp):
|
||||
"""Configure the settings for adding a new server. Options:
|
||||
-wf Add furthermore the server in xboard.cfg"""
|
||||
server = input("Server: ")
|
||||
user = input("User: ")
|
||||
port = input("Port: ")
|
||||
password = getpass.getpass("Password: ")
|
||||
|
||||
# Remove whitespaces
|
||||
|
||||
server = server.replace(" ", "")
|
||||
user = user.replace(" ", "")
|
||||
user = user.replace(" ", "")
|
||||
password = password.replace(" ", "")
|
||||
|
||||
self.servers['server'].append(server)
|
||||
self.servers['user'].append(user)
|
||||
self.servers['port'].append(port)
|
||||
self.servers['password'].append(password)
|
||||
|
||||
if inp == '-wf':
|
||||
with open('xboard.cfg', 'a+') as configFile:
|
||||
line = ','.join([server, user, password, port])
|
||||
configFile.write(line + '\n')
|
||||
|
||||
def do_refill(self, inp):
|
||||
"Refills the list of initial servers"
|
||||
self.servers = loadcfg.loadcfg()
|
||||
self.do_ls(inp)
|
||||
print("Servers list was refilled!")
|
||||
|
||||
|
||||
def do_checkup(self, inp):
|
||||
"""Check if servers are up using nc tool. Options:
|
||||
-t set timeout for listening. Default is 10"""
|
||||
|
||||
# Set timeout
|
||||
timeout = 10;
|
||||
if inp:
|
||||
timeout = int(agrs[1])
|
||||
|
||||
# List of servers which are down
|
||||
unavailable = defaultdict(list)
|
||||
unavailable.fromkeys(['server', 'user', 'password', 'port'])
|
||||
|
||||
serverLength = len(self.servers['server'])
|
||||
|
||||
# Used for writing date and time info in file
|
||||
infocount = 0
|
||||
|
||||
for i in range(0, serverLength):
|
||||
|
||||
commandfull = 'nc -v -w %d %s -z 22' % (timeout, \
|
||||
self.servers['server'][i])
|
||||
|
||||
commandlist = commandfull.split(' ')
|
||||
|
||||
checkProcess = Popen(commandlist, stdout=PIPE, stderr=PIPE)
|
||||
|
||||
# Apparently nc flushes all output to stderr
|
||||
stdout, stderr = checkProcess.communicate()
|
||||
stderr = stderr.decode('utf-8')
|
||||
|
||||
# Fill a dictionary with servers which are down
|
||||
if "Connected" not in stderr:
|
||||
|
||||
print('Server %s will be removed from servers list!' % \
|
||||
self.servers['server'][i])
|
||||
|
||||
with open('xboard.log', 'a+') as log:
|
||||
now = datetime.datetime.now()
|
||||
|
||||
# Write info about date and time just at the first line
|
||||
# of local block of data
|
||||
|
||||
if infocount == 0:
|
||||
log.write('Informations about checkup at %s\n' % \
|
||||
now.strftime("%Y-%m-%d %H:%M"))
|
||||
infocount = 1
|
||||
log.write(stderr)
|
||||
|
||||
unavailable['server'].append(self.servers['server'][i])
|
||||
unavailable['user'].append(self.servers['user'][i])
|
||||
unavailable['password'].append(self.servers['password'][i])
|
||||
unavailable['port'].append(self.servers['port'][i])
|
||||
|
||||
else:
|
||||
print(stderr, end='')
|
||||
|
||||
# power status
|
||||
checkPower = sidefun.powerstatus(self.servers['server'][i], \
|
||||
self.servers['user'][i], self.servers['password'][i], \
|
||||
self.servers['port'][i])
|
||||
|
||||
if 'on' not in checkPower:
|
||||
print("Server's power state is off!")
|
||||
|
||||
self.off['server'].append(self.servers['server'][i])
|
||||
self.off['user'].append(self.servers['user'][i])
|
||||
self.off['password'].append(self.servers['password'][i])
|
||||
self.off['port'].append(self.servers['port'][i])
|
||||
|
||||
|
||||
####### Print servers which are unavailable
|
||||
if unavailable:
|
||||
print("\nList of down servers:")
|
||||
for i in range(0, len(unavailable['server'])):
|
||||
print(unavailable['server'][i], unavailable['port'][i])
|
||||
self.servers['server'].remove(unavailable['server'][i])
|
||||
self.servers['user'].remove(unavailable['user'][i])
|
||||
self.servers['password'].remove(unavailable['password'][i])
|
||||
self.servers['port'].remove(unavailable['port'][i])
|
||||
|
||||
####### Print servers which are off
|
||||
if self.off:
|
||||
print("\nList of powered off servers:")
|
||||
for i in range(0, len(self.off['server'])):
|
||||
print(self.off['server'][i], self.off['port'][i])
|
||||
|
||||
# Maybe remove will fail because the server is already
|
||||
# removed from self.servers['server'] list so a try-except
|
||||
# block is useful here
|
||||
|
||||
try:
|
||||
self.servers['server'].remove(self.off['server'][i])
|
||||
self.servers['user'].remove(self.off['user'][i])
|
||||
self.servers['password'].remove(self.off['password'][i])
|
||||
self.servers['port'].remove(self.off['port'][i])
|
||||
except:
|
||||
pass
|
||||
|
||||
print("Do you want to power on this servers?" + '\n')
|
||||
confirm = input("Y/n: ")
|
||||
if confirm is 'Y' or confirm is 'y':
|
||||
for i in range(len(self.off['server'])):
|
||||
sidefun.poweron(self.off['server'][i], \
|
||||
self.off['user'][i], self.off['password'][i], \
|
||||
self.off['port'][i])
|
||||
|
||||
|
||||
print("Check xboard.log for more info about checkup using 'log' command!")
|
||||
elif not unavailable and self.servers['server']:
|
||||
print("\nAll servers are up!")
|
||||
|
||||
|
||||
|
||||
def do_select(self, option):
|
||||
# TODO check index range
|
||||
"""options:
|
||||
-out exclude a server or a list of servers separated by commas
|
||||
-outn exclude first n servers from servers list
|
||||
-outN exclude last N servers from servers list
|
||||
-r delete all servers excluding a given server or a list of servers
|
||||
"""
|
||||
args = option.split()
|
||||
|
||||
# If out option has no arguments
|
||||
if len(args) == 1 and args[0] == '-out' :
|
||||
print("You must include servers to be ignored from servers list!")
|
||||
return
|
||||
|
||||
|
||||
if len(args) > 3:
|
||||
print("Error: too many arguments. See '? select'")
|
||||
return
|
||||
|
||||
# Config for out option
|
||||
if len(args) == 2 and args[0] == '-out':
|
||||
|
||||
serverList = args[1].split(',')
|
||||
for serverToDelete in serverList:
|
||||
|
||||
if "*" in serverToDelete:
|
||||
search = serverToDelete.split('*')
|
||||
# String starts with text preceded by *
|
||||
if search[1] == '':
|
||||
indexes = [i for i in range(len(self.servers['server']))\
|
||||
if self.servers['server'][i].startswith(search[0])]
|
||||
|
||||
# String ends with text succeeded by *
|
||||
elif search[0] == '':
|
||||
indexes = [i for i in range(len(self.servers['server']))\
|
||||
if self.servers['server'][i].endswith(search[1])]
|
||||
|
||||
# * is in the middle of the string
|
||||
elif search[0] != '' and search[1] != '':
|
||||
indexes = [i for i in range(len(self.servers['server'])) if \
|
||||
search[0] in self.servers['server'][i] and search[1] \
|
||||
in self.servers['server'][i]]
|
||||
|
||||
elif "*" not in serverToDelete:
|
||||
indexes = [i for i in range(len(self.servers['server'])) \
|
||||
if self.servers['server'][i] == serverToDelete]
|
||||
|
||||
if not indexes:
|
||||
print("Server not found!")
|
||||
return
|
||||
|
||||
for index in sorted(indexes, reverse=True):
|
||||
del self.servers['server'][index]
|
||||
del self.servers['password'][index]
|
||||
del self.servers['user'][index]
|
||||
del self.servers['port'][index]
|
||||
|
||||
return
|
||||
|
||||
if len(args) == 2 and args[0] == '-outn':
|
||||
indexes = []
|
||||
for i in range(int(args[1])):
|
||||
indexes.append(i)
|
||||
|
||||
for index in sorted(indexes, reverse=True):
|
||||
del self.servers['server'][index]
|
||||
del self.servers['password'][index]
|
||||
del self.servers['user'][index]
|
||||
del self.servers['port'][index]
|
||||
|
||||
return
|
||||
|
||||
if len(args) == 2 and args[0] == '-outN':
|
||||
indexes = []
|
||||
|
||||
for i in range(len(self.servers['server']) - int(args[1]), \
|
||||
len(self.servers['server'])):
|
||||
indexes.append(i)
|
||||
|
||||
for index in sorted(indexes, reverse=True):
|
||||
del self.servers['server'][index]
|
||||
del self.servers['password'][index]
|
||||
del self.servers['user'][index]
|
||||
del self.servers['port'][index]
|
||||
|
||||
return
|
||||
|
||||
if len(args) == 2 and args[0] == '-r':
|
||||
|
||||
serverList = args[1].split(',')
|
||||
for serverToDelete in serverList:
|
||||
|
||||
if "*" in serverToDelete:
|
||||
search = serverToDelete.split('*')
|
||||
# String starts with text preceded by *
|
||||
if search[1] == '':
|
||||
indexes = [i for i in range(len(self.servers['server']))\
|
||||
if self.servers['server'][i].startswith(search[0])]
|
||||
|
||||
# String ends with text succeeded by *
|
||||
elif search[0] == '':
|
||||
indexes = [i for i in range(len(self.servers['server']))\
|
||||
if self.servers['server'][i].endswith(search[1])]
|
||||
|
||||
# * is in the middle of the string
|
||||
elif search[0] != '' and search[1] != '':
|
||||
indexes = [i for i in range(len(self.servers['server'])) if \
|
||||
search[0] in self.servers['server'][i] and search[1] \
|
||||
in self.servers['server'][i]]
|
||||
|
||||
elif "*" not in serverToDelete:
|
||||
indexes = [i for i in range(len(self.servers['server'])) \
|
||||
if self.servers['server'][i] == serverToDelete]
|
||||
|
||||
|
||||
# Calculate complement of indexes list
|
||||
allindexes = []
|
||||
for i in range(len(self.servers['server'])):
|
||||
allindexes.append(i)
|
||||
|
||||
indexes = set(allindexes) - set(indexes)
|
||||
|
||||
if not indexes:
|
||||
print("Server not found!")
|
||||
return
|
||||
|
||||
for index in sorted(indexes, reverse=True):
|
||||
del self.servers['server'][index]
|
||||
del self.servers['password'][index]
|
||||
del self.servers['user'][index]
|
||||
del self.servers['port'][index]
|
||||
|
||||
return
|
||||
|
||||
|
||||
print("Error: unknown arguments. See '? select'")
|
||||
|
||||
def do_nums(self, inp):
|
||||
"Print how many servers are available"
|
||||
print(len(self.servers['server']))
|
||||
|
||||
def do_fans(self, options):
|
||||
"Get information about fans from every server"
|
||||
|
||||
self.do_checkup(None)
|
||||
|
||||
# List of servers from do_conn function
|
||||
ssh = sidefun.connect(self.servers)
|
||||
|
||||
argv = options.split(' ')
|
||||
|
||||
# If -f option is passed write to xboard.log and return
|
||||
if argv[0] == '-f':
|
||||
sidefun.filewrite('fans', ssh, self.servers)
|
||||
return
|
||||
|
||||
# If an unknown option is passed display an error message and
|
||||
# return
|
||||
elif argv[0] != '-f' and argv[0] != '':
|
||||
print("Error: Unknown argument '%s' for command fans!" % argv[0])
|
||||
return
|
||||
|
||||
sshLength = len(ssh)
|
||||
|
||||
print('\n')
|
||||
|
||||
# Go through the list and execute the command for
|
||||
# every server
|
||||
for i in range(0, sshLength):
|
||||
ssh_stdin, ssh_stdout, ssh_stderr = ssh[i].exec_command('fans')
|
||||
for lineout in ssh_stdout.read().splitlines():
|
||||
print(lineout.decode('utf-8').replace(systemPropmt, ''))
|
||||
for linerr in ssh_stderr.read().splitlines():
|
||||
print ('%s at %s on port %s' % (linerr.decode('utf-8').replace(systemPrompt, ''), \
|
||||
self.servers['server'][i], self.servers['port'][i]))
|
||||
|
||||
ssh[i].close()
|
||||
|
||||
|
||||
def do_led(self, options):
|
||||
"Get information about leds from every server"
|
||||
|
||||
self.do_checkup(None)
|
||||
|
||||
# List of servers from do_conn function
|
||||
ssh = sidefun.connect(self.servers)
|
||||
|
||||
argv = options.split(' ')
|
||||
|
||||
# If -f option is passed write to xboard.log and return
|
||||
if argv[0] == '-f':
|
||||
sidefun.filewrite('led', ssh, self.servers)
|
||||
return
|
||||
|
||||
# If an unknown option is passed display an error message and
|
||||
# return
|
||||
elif argv[0] != '-f' and argv[0] != '':
|
||||
print("Error: Unknown argument '%s' for command led!" % argv[0])
|
||||
return
|
||||
|
||||
sshLength = len(ssh)
|
||||
|
||||
# Go through the list and execute the command for
|
||||
# every server
|
||||
for i in range(0, sshLength):
|
||||
ssh_stdin, ssh_stdout, ssh_stderr = ssh[i].exec_command('led')
|
||||
for line in ssh_stdout.read().splitlines():
|
||||
print(line.decode('utf-8').replace(systemPrompt, ''))
|
||||
for linerr in ssh_stderr.read().splitlines():
|
||||
print ('%s at %s on port %s' % (linerr.decode('utf-8').replace(systemPrompt, ''), \
|
||||
self.servers['server'][i], self.servers['port'][i]))
|
||||
|
||||
ssh[i].close()
|
||||
|
||||
|
||||
def do_volts(self, options):
|
||||
"Get information about voltages from every server"
|
||||
|
||||
self.do_checkup(None)
|
||||
|
||||
# List of servers from do_conn function
|
||||
ssh = sidefun.connect(self.servers)
|
||||
|
||||
argv = options.split(' ')
|
||||
|
||||
# If -f option is passed write to xboard.log and return
|
||||
if argv[0] == '-f':
|
||||
sidefun.filewrite('volts', ssh, self.servers)
|
||||
return
|
||||
|
||||
# If an unknown option is passed display an error message and
|
||||
# return
|
||||
elif argv[0] != '-f' and argv[0] != '':
|
||||
print("Error: Unknown argument '%s' for command volts!" % argv[0])
|
||||
return
|
||||
|
||||
sshLength = len(ssh)
|
||||
|
||||
# Go through the list and execute the command for
|
||||
# every server
|
||||
for i in range(0, sshLength):
|
||||
ssh_stdin, ssh_stdout, ssh_stderr = ssh[i].exec_command('volts')
|
||||
for line in ssh_stdout.read().splitlines():
|
||||
print(line.decode('utf-8').replace(systemPrompt, ''))
|
||||
for linerr in ssh_stderr.read().splitlines():
|
||||
print ('%s at %s on port %s' % (linerr.decode('utf-8').replace(systemPrompt, ''), \
|
||||
self.servers['server'][i], self.servers['port'][i]))
|
||||
|
||||
ssh[i].close()
|
||||
|
||||
|
||||
def do_temps(self, options):
|
||||
"Get information about temperature of every server"
|
||||
|
||||
self.do_checkup(None)
|
||||
|
||||
# List of servers from do_conn function
|
||||
ssh = sidefun.connect(self.servers)
|
||||
|
||||
argv = options.split(' ')
|
||||
|
||||
# If -f option is passed write to xboard.log and return
|
||||
if argv[0] == '-f':
|
||||
sidefun.filewrite('temps', ssh, self.servers)
|
||||
return
|
||||
|
||||
# If an unknown option is passed display an error message and
|
||||
# return
|
||||
elif argv[0] != '-f' and argv[0] != '':
|
||||
print("Error: Unknown argument '%s' for command temps!" % argv[0])
|
||||
return
|
||||
|
||||
sshLength = len(ssh)
|
||||
|
||||
# Go through the list and execute the command for
|
||||
# every server
|
||||
for i in range(0, sshLength):
|
||||
ssh_stdin, ssh_stdout, ssh_stderr = ssh[i].exec_command('temps')
|
||||
for line in ssh_stdout.read().splitlines():
|
||||
print(line.decode('utf-8').replace(systemPrompt, ''))
|
||||
for linerr in ssh_stderr.read().splitlines():
|
||||
print ('%s at %s on port %s' % (linerr.decode('utf-8').replace(systemPrompt, ''), \
|
||||
self.servers['server'][i], self.servers['port'][i]))
|
||||
|
||||
ssh[i].close()
|
||||
|
||||
def do_adapter(self, options):
|
||||
"Get information about adapters from every server"
|
||||
|
||||
self.do_checkup(None)
|
||||
|
||||
# List of servers from do_conn function
|
||||
ssh = sidefun.connect(self.servers)
|
||||
|
||||
argv = options.split(' ')
|
||||
|
||||
# If -f option is passed write to xboard.log and return
|
||||
if argv[0] == '-f':
|
||||
sidefun.filewrite('adapter', ssh, self.servers)
|
||||
return
|
||||
|
||||
# If an unknown option is passed display an error message and
|
||||
# return
|
||||
elif argv[0] != '-f' and argv[0] != '':
|
||||
print("Error: Unknown argument '%s' for command adapter!" % argv[0])
|
||||
return
|
||||
|
||||
sshLength = len(ssh)
|
||||
|
||||
# Go through the list and execute the command for
|
||||
# every server
|
||||
for i in range(0, sshLength):
|
||||
ssh_stdin, ssh_stdout, ssh_stderr = ssh[i].exec_command('adapter')
|
||||
for line in ssh_stdout.read().splitlines():
|
||||
print(line.decode('utf-8').replace(systemPrompt, ''))
|
||||
for linerr in ssh_stderr.read().splitlines():
|
||||
print ('%s at %s on port %s' % (linerr.decode('utf-8').replace(systemPrompt, ''), \
|
||||
self.servers['server'][i], self.servers['port'][i]))
|
||||
|
||||
ssh[i].close()
|
||||
|
||||
def do_fw(self, options):
|
||||
"Get information about Vital Product Data for every server"
|
||||
|
||||
self.do_checkup(None)
|
||||
|
||||
# List of servers from do_conn function
|
||||
ssh = sidefun.connect(self.servers)
|
||||
|
||||
argv = options.split(' ')
|
||||
|
||||
# If -f option is passed write to xboard.log and return
|
||||
if argv[0] == '-f':
|
||||
sidefun.filewrite('fw', ssh, self.servers)
|
||||
return
|
||||
|
||||
# If an unknown option is passed display an error message and
|
||||
# return
|
||||
elif argv[0] != '-f' and argv[0] != '':
|
||||
print("Error: Unknown argument '%s' for command fw!" % argv[0])
|
||||
return
|
||||
|
||||
sshLength = len(ssh)
|
||||
|
||||
# Go through the list and execute the command for
|
||||
# every server
|
||||
for i in range(0, sshLength):
|
||||
ssh_stdin, ssh_stdout, ssh_stderr = ssh[i].exec_command('vpd fw')
|
||||
for line in ssh_stdout.read().splitlines():
|
||||
print(line.decode('utf-8').replace(self.systemPrompt, ''))
|
||||
for linerr in ssh_stderr.read().splitlines():
|
||||
print ('%s at %s on port %s' % (linerr.decode('utf-8').replace(self.systemPrompt, ''), \
|
||||
self.servers['server'][i], self.servers['port'][i]))
|
||||
|
||||
ssh[i].close()
|
||||
|
||||
def do_imm(self, options):
|
||||
"Get information about Vital Product Data for every server"
|
||||
|
||||
self.do_checkup(None)
|
||||
|
||||
# List of servers from do_conn function
|
||||
ssh = sidefun.connect(self.servers)
|
||||
|
||||
argv = options.split(' ')
|
||||
|
||||
# If -f option is passed write to xboard.log and return
|
||||
if argv[0] == '-f':
|
||||
sidefun.filewrite('imm', ssh, self.servers)
|
||||
return
|
||||
|
||||
# If an unknown option is passed display an error message and
|
||||
# return
|
||||
elif argv[0] != '-f' and argv[0] != '':
|
||||
print("Error: Unknown argument '%s' for command imm!" % argv[0])
|
||||
return
|
||||
|
||||
sshLength = len(ssh)
|
||||
|
||||
# Go through the list and execute the command for
|
||||
# every server
|
||||
for i in range(0, sshLength):
|
||||
ssh_stdin, ssh_stdout, ssh_stderr = ssh[i].exec_command('vpd imm')
|
||||
for line in ssh_stdout.read().splitlines():
|
||||
print(line.decode('utf-8').replace(systemPrompt, ''))
|
||||
for linerr in ssh_stderr.read().splitlines():
|
||||
print ('%s at %s on port %s' % (linerr.decode('utf-8').replace(systemPrompt, ''), \
|
||||
self.servers['server'][i], self.servers['port'][i]))
|
||||
|
||||
ssh[i].close()
|
||||
|
||||
def do_sys(self, options):
|
||||
"Get information about Vital Product Data for every server"
|
||||
|
||||
self.do_checkup(None)
|
||||
|
||||
# List of servers from do_conn function
|
||||
ssh = sidefun.connect(self.servers)
|
||||
|
||||
argv = options.split(' ')
|
||||
|
||||
# If -f option is passed write to xboard.log and return
|
||||
if argv[0] == '-f':
|
||||
sidefun.filewrite('sys', ssh, self.servers)
|
||||
return
|
||||
|
||||
# If an unknown option is passed display an error message and
|
||||
# return
|
||||
elif argv[0] != '-f' and argv[0] != '':
|
||||
print("Error: Unknown argument '%s' for command sys!" % argv[0])
|
||||
return
|
||||
|
||||
sshLength = len(ssh)
|
||||
|
||||
# Go through the list and execute the command for
|
||||
# every server
|
||||
for i in range(0, sshLength):
|
||||
ssh_stdin, ssh_stdout, ssh_stderr = ssh[i].exec_command('vpd sys')
|
||||
for line in ssh_stdout.read().splitlines():
|
||||
print(line.decode('utf-8').replace(self.systemPrompt, ''))
|
||||
for linerr in ssh_stderr.read().splitlines():
|
||||
print ('%s at %s on port %s' % (linerr.decode('utf-8').replace(self.systemPrompt, ''), \
|
||||
self.servers['server'][i], self.servers['port'][i]))
|
||||
|
||||
ssh[i].close()
|
||||
|
||||
def do_dns(self, options):
|
||||
"Get information about dns for every server"
|
||||
|
||||
self.do_checkup(None)
|
||||
|
||||
# List of servers from do_conn function
|
||||
ssh = sidefun.connect(self.servers)
|
||||
|
||||
argv = options.split(' ')
|
||||
|
||||
# If -f option is passed write to xboard.log and return
|
||||
if argv[0] == '-f':
|
||||
sidefun.filewrite('dns', ssh, self.servers)
|
||||
return
|
||||
|
||||
# If an unknown option is passed display an error message and
|
||||
# return
|
||||
elif argv[0] != '-f' and argv[0] != '':
|
||||
print("Error: Unknown argument '%s' for command dns!" % argv[0])
|
||||
return
|
||||
|
||||
sshLength = len(ssh)
|
||||
|
||||
# Go through the list and execute the command for
|
||||
# every server
|
||||
for i in range(0, sshLength):
|
||||
ssh_stdin, ssh_stdout, ssh_stderr = ssh[i].exec_command('dns')
|
||||
for line in ssh_stdout.read().splitlines():
|
||||
print(line.decode('utf-8').replace(systemPrompt, ''))
|
||||
for linerr in ssh_stderr.read().splitlines():
|
||||
print ('%s at %s on port %s' % (linerr.decode('utf-8').replace(systemPrompt, ''), \
|
||||
self.servers['server'][i], self.servers['port'][i]))
|
||||
|
||||
ssh[i].close()
|
||||
|
||||
def do_lsn(self, options):
|
||||
"Get information about lss from every server"
|
||||
|
||||
self.do_checkup(None)
|
||||
|
||||
# List of servers from do_conn function
|
||||
ssh = sidefun.connect(self.servers)
|
||||
|
||||
argv = options.split(' ')
|
||||
|
||||
# If -f option is passed write to xboard.log and return
|
||||
if argv[0] == '-f':
|
||||
sidefun.filewrite('ls_release -a', ssh, self.servers)
|
||||
return
|
||||
|
||||
# If an unknown option is passed display an error message and
|
||||
# return
|
||||
elif argv[0] != '-f' and argv[0] != '':
|
||||
print("Error: Unknown argument '%s' for command ls!" % argv[0])
|
||||
return
|
||||
|
||||
sshLength = len(ssh)
|
||||
|
||||
# Go through the list and execute the command for
|
||||
# every server
|
||||
|
||||
print('\n')
|
||||
|
||||
for i in range(0, sshLength):
|
||||
print(self.servers['server'][i], '\n')
|
||||
ssh_stdin, ssh_stdout, ssh_stderr = ssh[i].exec_command('ls -la')
|
||||
for line in ssh_stdout.read().splitlines():
|
||||
print(line.decode('utf-8').replace(systemPrompt, ''))
|
||||
for linerr in ssh_stderr.read().splitlines():
|
||||
if linerr:
|
||||
print ('%s at %s on port %s' % (linerr.decode('utf-8').replace(systemPrompt, ''), \
|
||||
self.servers['server'][i], self.servers['port'][i]))
|
||||
print('============================================')
|
||||
|
||||
ssh[i].close()
|
||||
|
||||
def do_export(self, inp):
|
||||
"""Export all data to a csv file. Run checkup first!!!"""
|
||||
|
||||
ssh = sidefun.connect(self.servers)
|
||||
sshLength = len(ssh)
|
||||
|
||||
if os.path.isfile('./exported.csv'):
|
||||
with open('exported.csv', 'a+') as exportFile:
|
||||
exportFile.write("index,type,ip,state,fw_level,fw_version," + \
|
||||
"release_date, uefi, uefi_release_date" + "\n")
|
||||
|
||||
|
||||
for i in range(sshLength):
|
||||
|
||||
csvline = []
|
||||
# index
|
||||
csvline.append(str(i+1))
|
||||
|
||||
# type
|
||||
type_model = sidefun.sys(self.servers['server'][i], \
|
||||
self.servers['user'][i], self.servers['password'][i], \
|
||||
self.servers['port'][i])
|
||||
csvline.append(type_model)
|
||||
|
||||
# server ip
|
||||
csvline.append(self.servers['server'][i])
|
||||
|
||||
# power state
|
||||
power = sidefun.powerstatus(self.servers['server'][i], \
|
||||
self.servers['user'][i], self.servers['password'][i], \
|
||||
self.servers['port'][i])
|
||||
csvline.append(power.split()[1])
|
||||
|
||||
# firmware info
|
||||
csvline.extend(sidefun.fw(self.servers['server'][i], \
|
||||
self.servers['user'][i], self.servers['password'][i], \
|
||||
self.servers['port'][i]))
|
||||
|
||||
print(csvline)
|
||||
|
||||
with open('exported.csv', 'a+') as exportFile:
|
||||
line = ','.join(csvline)
|
||||
exportFile.write(line + '\n')
|
||||
|
||||
|
||||
def do_log(self, inp):
|
||||
"Display log info"
|
||||
os.system('less xboard.log')
|
||||
|
||||
def do_clrlog(self, inp):
|
||||
# TODO maybe delete after or before a given date
|
||||
"Delete log info"
|
||||
os.system('> xboard.log')
|
||||
|
||||
def do_ls(self, inp):
|
||||
"List the initial servers from xboard.cfg"
|
||||
import loadcfg
|
||||
|
||||
data = loadcfg.loadcfg()
|
||||
for i in data['server']:
|
||||
print(i)
|
||||
|
||||
def do_lsu(self, inp):
|
||||
"List the servers"
|
||||
import loadcfg
|
||||
|
||||
data = self.servers
|
||||
|
||||
if not data['server']:
|
||||
print("There are no alive servers to track! Abort..")
|
||||
return
|
||||
|
||||
for i in data['server']:
|
||||
print(i)
|
||||
|
||||
def do_lso(self, inp):
|
||||
"""List powered off servers.
|
||||
Options: -u power on the servers listed here"""
|
||||
data = self.off
|
||||
|
||||
if not data['server']:
|
||||
print("There are no powered off servers to track! Abort..")
|
||||
return
|
||||
|
||||
for i in data['server']:
|
||||
print(i)
|
||||
|
||||
if '-u' == inp:
|
||||
print('\n')
|
||||
for i in range(len(self.off['server'])):
|
||||
sidefun.poweron(self.off['server'][i], \
|
||||
self.off['user'][i], self.off['password'][i], \
|
||||
self.off['port'][i])
|
||||
|
||||
def do_lp(self, inp):
|
||||
"List the ports"
|
||||
import loadcfg
|
||||
|
||||
data = self.servers
|
||||
for i in data['port']:
|
||||
print(i)
|
||||
|
||||
|
||||
def do_lu(self, inp):
|
||||
"List users"
|
||||
import loadcfg
|
||||
|
||||
data = self.servers
|
||||
for i in data['user']:
|
||||
print(i)
|
||||
|
||||
def do_exit(self, inp):
|
||||
print("\nExit..")
|
||||
return True
|
||||
|
||||
try:
|
||||
xBoard().preloop()
|
||||
xBoard().cmdloop()
|
||||
except KeyboardInterrupt:
|
||||
xBoard().postloop()
|
||||
print("\nExit..")
|
||||
sys.exit(0)
|
Loading…
Reference in New Issue