some type validations
This commit is contained in:
parent
035e575ddb
commit
bcc2c8a3f4
@ -4,6 +4,9 @@ def listServers(serverName):
|
|||||||
# Expected data:
|
# 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']
|
# 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.
|
# 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':
|
if not serverName[0] == 'Bay Server Name Serial Number Status Power UID Partner\r':
|
||||||
logging.critical(serverName)
|
logging.critical(serverName)
|
||||||
|
6
main.py
6
main.py
@ -7,8 +7,8 @@ from time import sleep
|
|||||||
import listServers, relativeUsage
|
import listServers, relativeUsage
|
||||||
|
|
||||||
# Debugging stuffs
|
# Debugging stuffs
|
||||||
logging.basicConfig()
|
#logging.basicConfig()
|
||||||
logging.getLogger("paramiko").setLevel(logging.DEBUG)
|
#logging.getLogger("paramiko").setLevel(logging.DEBUG)
|
||||||
|
|
||||||
# Creds
|
# Creds
|
||||||
hostname = '172.23.224.40'
|
hostname = '172.23.224.40'
|
||||||
@ -107,7 +107,7 @@ ssh.close()
|
|||||||
|
|
||||||
## Calculating blade usage by percentage. ##
|
## Calculating blade usage by percentage. ##
|
||||||
# Keep in mind the querying of the data took a while, a minute or so.
|
# 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)
|
print(servers)
|
||||||
breakpoint()
|
breakpoint()
|
||||||
|
@ -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.")
|
||||||
|
|
||||||
|
for srv in range(baysInUseCount):
|
||||||
|
a
|
||||||
return servers
|
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))
|
Loading…
Reference in New Issue
Block a user