some type validations

This commit is contained in:
rasmus 2020-12-22 00:51:15 +02:00
parent 035e575ddb
commit bcc2c8a3f4
5 changed files with 22 additions and 6 deletions

View File

@ -4,6 +4,9 @@ def listServers(serverName):
# Expected data:
# 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']
# Input validation
if not type(serverName) is list:
raise TypeError("ssh_runcmd: command must be a list, '" + str(serverName) + "' is not.")
# Check if the first item in the list is the header. If this is true (data started at right place), most likely the other data is fine as well.
if not serverName[0] == 'Bay Server Name Serial Number Status Power UID Partner\r':
logging.critical(serverName)

View File

@ -7,8 +7,8 @@ from time import sleep
import listServers, relativeUsage
# Debugging stuffs
logging.basicConfig()
logging.getLogger("paramiko").setLevel(logging.DEBUG)
#logging.basicConfig()
#logging.getLogger("paramiko").setLevel(logging.DEBUG)
# Creds
hostname = '172.23.224.40'
@ -107,7 +107,7 @@ ssh.close()
## Calculating blade usage by percentage. ##
# Keep in mind the querying of the data took a while, a minute or so.
relativeUsage.relativeUsage(encPowerUsageAC, servers)
relativeUsage.relativeUsage(encPowerUsageAC, baysInUseCount, servers)
print(servers)
breakpoint()

View File

@ -1,5 +1,18 @@
# Current data: [[1, 'tty-lab-1', '', 'OK', 'On', 'Off', 144], [2, 'tty-lab-2', 'CZ320263P9', 'OK', 'On', 'Off', 86], [3, 'tty-lab-3', 'CZJ14410KP', 'Failed', 'On', 'Off', 129], [4, 'kspve1', 'CZJ14410KK', 'OK', 'On', 'Off', 87], [5, 'kspve2-2', '', 'OK', 'On', 'Off', 87], [6, 'kspve3', '', 'OK', 'On', 'Off', 82], [7, 'plaes-blade', '', 'OK', 'On', 'Off', 81], [8, 'Ringly-01', 'CZ3402Y48C', 'OK', 'On', 'Off', 124], [9, 'toomas-lepik', 'CZ3217FNYE', 'OK', 'On', 'Off', 132], [10, 'toomas-lepik2', 'CZ3217FFSS', 'OK', 'On', 'Off', 101], [12, 'erki-naumanis', '', 'OK', 'On', 'Off', 88]]
def relativeUsage(encPowerUsageAC, servers):
def relativeUsage(encPowerUsageAC, baysInUseCount, servers):
# Input validation
if not type(encPowerUsageAC) is int:
raise TypeError("ssh_runcmd: command must be an integer, '" + str(encPowerUsageAC) + "' is not.")
if not type(baysInUseCount) is int:
raise TypeError("ssh_runcmd: command must be an integer, '" + str(baysInUseCount) + "' is not.")
if not type(servers) is list:
raise TypeError("ssh_runcmd: command must be a list, '" + str(servers) + "' is not.")
return servers
for srv in range(baysInUseCount):
a
return servers
encPowerUsageAC = 1775
baysInUseCount = 11
servers = [[1, 'tty-lab-1', '', 'OK', 'On', 'Off', 144], [2, 'tty-lab-2', 'CZ320263P9', 'OK', 'On', 'Off', 86], [3, 'tty-lab-3', 'CZJ14410KP', 'Failed', 'On', 'Off', 129], [4, 'kspve1', 'CZJ14410KK', 'OK', 'On', 'Off', 87], [5, 'kspve2-2', '', 'OK', 'On', 'Off', 87], [6, 'kspve3', '', 'OK', 'On', 'Off', 82], [7, 'plaes-blade', '', 'OK', 'On', 'Off', 81], [8, 'Ringly-01', 'CZ3402Y48C', 'OK', 'On', 'Off', 124], [9, 'toomas-lepik', 'CZ3217FNYE', 'OK', 'On', 'Off', 132], [10, 'toomas-lepik2', 'CZ3217FFSS', 'OK', 'On', 'Off', 101], [12, 'erki-naumanis', '', 'OK', 'On', 'Off', 88]]
print(relativeUsage(encPowerUsageAC, baysInUseCount, servers))

View File

View File