36 lines
1.9 KiB
Python
36 lines
1.9 KiB
Python
import logging
|
|
|
|
def relativeUsage(encPowerUsageAC, baysInUseCount, servers):
|
|
# Input validation
|
|
if not type(encPowerUsageAC) is int:
|
|
raise TypeError("relativeUsage: command must be an integer, '" + str(encPowerUsageAC) + "' is not.")
|
|
if not type(baysInUseCount) is int:
|
|
raise TypeError("relativeUsage: command must be an integer, '" + str(baysInUseCount) + "' is not.")
|
|
if not type(servers) is list:
|
|
raise TypeError("relativeUsage: command must be a list, '" + str(servers) + "' is not.")
|
|
|
|
# Add up the total DC usage of blades.
|
|
absoluteBladesUsage = 0
|
|
for n in range(baysInUseCount):
|
|
absoluteBladesUsage += servers[n][6]
|
|
# absoluteBladesUsage = sum(totalBladesUsage)
|
|
logging.info("Blade raw usage DC: " + str(absoluteBladesUsage))
|
|
|
|
# Get the relative percentage multiplier for blades AC.
|
|
percentageMultiplier = encPowerUsageAC / absoluteBladesUsage
|
|
|
|
for n in range(baysInUseCount):
|
|
servers[n].append( round(servers[n][6] * percentageMultiplier) ) # Multiply to get the relative AC usage of the blade.
|
|
|
|
srvAvg = 0
|
|
for n in range(baysInUseCount):
|
|
srvAvg += servers[n][7]
|
|
serversAverageAC = round(srvAvg / baysInUseCount)
|
|
|
|
return serversAverageAC, servers
|
|
|
|
# Testing data:
|
|
#encPowerUsageAC = 1775
|
|
#baysInUseCount = 11
|
|
#servers = [[1, 'foo-lab-1', '', 'OK', 'On', 'Off', 144], [2, 'foo-lab-2', 'CZ302243P9', 'OK', 'On', 'Off', 86], [3, 'foo-lab-3', 'CZJI441OKP', 'Failed', 'On', 'Off', 129], [4, 'kspve1', 'CZJ18450FK', 'OK', 'On', 'Off', 87], [5, 'kspve2-2', '', 'OK', 'On', 'Off', 87], [6, 'kspve3', '', 'OK', 'On', 'Off', 82], [7, 'foo-blade', '', 'OK', 'On', 'Off', 81], [8, 'Bar-01', 'CZ241274CC', 'OK', 'On', 'Off', 124], [9, 'baz-sar', 'CZ3217FNYE', 'OK', 'On', 'Off', 132], [10, 'baz-sar2', 'CZ3217FFSS', 'OK', 'On', 'Off', 101], [12, 'bee-bar', '', 'OK', 'On', 'Off', 88]]
|
|
#print(relativeUsage(encPowerUsageAC, baysInUseCount, servers)) |