From 38037fb3e55caf4f7b8725570047513d4c7fbd7c Mon Sep 17 00:00:00 2001 From: rasmus Date: Mon, 21 Dec 2020 22:17:16 +0200 Subject: [PATCH] we have bays --- .vscode/launch.json | 15 +++++++++++++++ dt.py | 39 +++++++++++++++++++++++++++++++++++++++ getme.py | 8 +++++--- 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 dt.py diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..17e15f2 --- /dev/null +++ b/.vscode/launch.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/dt.py b/dt.py new file mode 100644 index 0000000..22674b4 --- /dev/null +++ b/dt.py @@ -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() \ No newline at end of file diff --git a/getme.py b/getme.py index 72c9ff4..989e57c 100644 --- a/getme.py +++ b/getme.py @@ -35,12 +35,14 @@ def ssh_runcmd(command): # ssh_runcmd 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