Bug 2672 - le power diagram contient des erreurs (certains serveurs affichent une consommation de 0 W)

- correction du bug (les machines physix.._.. n'étaient pas gérées, alors que les machines simpatix.._.. l'étaient; du coup, j'ai rendu le code plus générique pour qu'il reconnaisse les machines [a-z]+.._..)
This commit is contained in:
Guillaume Raffy 2019-06-19 07:31:41 +00:00
parent 4b1bb04565
commit e102d33a9d
3 changed files with 11 additions and 6 deletions

View File

@ -7,8 +7,8 @@
'''
import re
import pygraphviz
from inventory import Inventory
import pygraphviz # port install py-pygraphviz
from inventory import Inventory, MachineSpecIdNotFound
from SimpaDbUtil import SqlFile, SqlDatabaseReader
from Lib import SimpaDbUtil
@ -199,7 +199,9 @@ class PowerConfig(object):
machine_name = machine.name
if re.match('simpatix.._..', machine_name):
if re.match('[a-z]+.._..', machine_name):
# machine_name is a group of machines such as physix80_83
# in this case, we use a hack : the type and power consumption is based on the first machine of this group (in this example physix80)
machine_name = '_'.join(machine_name.split('_')[0:-1])
# print(machine_name)
@ -210,7 +212,7 @@ class PowerConfig(object):
machine_spec_id = inventory.machine_name_to_machine_spec_id(machine_name)
if machine_spec_id == '':
machine_spec_id = None # some simple 'machines' such as powerext003 have undefined machine_spec_id
except SimpaDbUtil.TableAttrNotFound:
except MachineSpecIdNotFound:
pass
if machine_spec_id is not None:

View File

@ -1,4 +1,4 @@
import MySQLdb
import MySQLdb # sudo port install py-mysql
import time
import StringIO
import re

View File

@ -45,7 +45,10 @@ class Inventory(object):
return machine_name
def machine_name_to_machine_spec_id(self, machine_name):
try:
machine_spec_id = self._sql_reader.get_table_attr('machines', 'name', machine_name, 'machine_spec_id')
except SimpaDbUtil.TableAttrNotFound as e: # @UnusedVariable
raise MachineSpecIdNotFound(machine_name)
return machine_spec_id
# electricity related methods