we have bays

This commit is contained in:
rasmus 2020-12-21 22:17:16 +02:00
parent e803a57bc2
commit 38037fb3e5
3 changed files with 59 additions and 3 deletions

15
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}

39
dt.py Normal file
View File

@ -0,0 +1,39 @@
import logging
serverName = ['Bay Server Name Serial Number Status Power UID Partner\r', '--- ------------------------------------------------- --------------- -------- ------- --- -------\r', ' 1 tty-lab-1 OK On Off \r', ' 2 tty-lab-2 CZ320263P9 OK On Off \r', ' 3 tty-lab-3 CZJ14410KP Failed On Off \r', ' 4 kspve1 CZJ14410KK OK On Off \r', ' 5 kspve2-2 OK On Off \r', ' 6 kspve3 OK On Off \r', ' 7 plaes-blade OK On Off \r', ' 8 Ringly-01 CZ3402Y48C OK On Off \r', ' 9 toomas-lepik CZ3217FNYE OK On Off \r', ' 10 toomas-lepik2 CZ3217FFSS OK On Off \r', ' 11 [Absent] \r', ' 12 erki-naumanis OK On Off \r', ' 13 [Absent] \r', ' 14 [Absent] \r', ' 15 [Absent] \r', ' 16 [Absent] \r']
serverNamePos = [] # Init list
# https://stackoverflow.com/a/19842807
haystack = serverName[1]
needle = " "
for i, _ in enumerate(haystack):
if haystack[i:i + len(needle)] == needle:
serverNamePos.append(i) # Add results to list. The last positions of each field are indexed, the next one being the seperator.
serverNameFields = len(serverNamePos) # How many fields do we have to process
n = 2 # What server, 2 is the first one.
servers = [] # Init, the results of this.
for n in range(2, len(serverName)): # Loop through servers. | Adjust for the first two being headers.
# Fields: [BayNumber "Server Name", "Serial Number", "Status", "Power", "UID Partner"]
serverNameCurrentTmp = [] # Init
for i in range(serverNameFields):
if i == 0: # Special case, as i-1 would loop around.
serverNameCurrentTmp.append( int( serverName[n][0:serverNamePos[i]].strip() ) ) # Also convert to int, as we know it's a number.
else:
serverNameCurrentTmp.append( serverName[n][serverNamePos[i-1]+1:serverNamePos[i]].strip() ) # Get ith field by character position.
servers.append(serverNameCurrentTmp)
logging.debug('Bays:')
logging.debug(servers)
breakpoint()
for n in range(len(servers)):
print(n)
#print(servers)
breakpoint()

View File

@ -35,12 +35,14 @@ def ssh_runcmd(command): # ssh_runcmd <command>
logging.debug(ssh_runcmd('show date')) # Get rid of motd, init for next cmds. This is better than indefinitely reading buffer before any command as to counter this.
# Get a list of blades
rawServerList = ssh_runcmd('show server names')[2:]
print(rawServerList)
ServerList = ssh_runcmd('show server names')
breakpoint()
print(ServerList)
# ServerList = re.sub('(Banana)', r'\1Toothpaste', oldstring)
# connect server n
# show system1/oemhp_power1
# exit