reformatted code to pep8 convention

This commit is contained in:
Guillaume Raffy 2018-08-27 13:32:41 +00:00
parent c750804914
commit 197e94d320
1 changed files with 219 additions and 212 deletions

View File

@ -1,16 +1,15 @@
import MySQLdb
import time
import subprocess
import StringIO
import re
from wol import *
import os
import signal
from Util import *
import abc
import sqlite3
from mysql2sqlite import mysql_to_sqlite
def isMachineResponding(machineName):
(returnCode, stdout, stderr) = executeProgram(['ping', '-o', '-t', '1', machineName])
# log( 'isMachineResponding : result of command %s : %d' % (command, returnCode) )
@ -20,12 +19,12 @@ def isMachineResponding(machineName):
else:
bMachineNameIsNotKnown = (returnCode == 68)
bMachineIsNotResponding = (returnCode == 2)
if bMachineIsNotResponding == False:
if bMachineIsNotResponding is False:
bBUG_00000004_IS_STILL_ALIVE = True
if bBUG_00000004_IS_STILL_ALIVE == True and returnCode == 142:
if bBUG_00000004_IS_STILL_ALIVE is True and returnCode == 142:
log('isMachineResponding : bug00000004 Unexpected return code : returnCode=%d, stdout="%s", stderr="%s" , machineName = %s' % (returnCode, stdout, stderr, machineName))
# don't stop the program until we understand bug00000004
elif bBUG_00000004_IS_STILL_ALIVE == True and returnCode == -14: # I had this error code on 07/09/2009 20:38 but I don't know yet what that means
elif bBUG_00000004_IS_STILL_ALIVE is True and returnCode == -14: # I had this error code on 07/09/2009 20:38 but I don't know yet what that means
log('isMachineResponding : bug00000004 Unexpected return code : returnCode=%d, stdout="%s", stderr="%s" , machineName = %s' % (returnCode, stdout, stderr, machineName))
# don't stop the program until we understand bug00000004
else:
@ -33,6 +32,7 @@ def isMachineResponding(machineName):
assert(False)
return False
class ISqlDatabaseBackend(object):
def __init__(self):
pass
@ -44,6 +44,7 @@ class ISqlDatabaseBackend(object):
"""
pass
class RemoteMysqlDb(ISqlDatabaseBackend):
def __init__(self, db_server_fqdn, db_user, db_name):
"""
@ -143,6 +144,7 @@ class SqlDatabaseReader(object):
attr_value = rows[0][0]
return attr_value
def machineNameToMacAddress(machineName):
conn = MySQLdb.connect('simpatix10', 'simpadb_reader', '', 'simpadb')
assert(conn)
@ -158,6 +160,7 @@ def machineNameToMacAddress( machineName ):
conn.close()
return macAddress
def getLightOutManagementIpAddress(machineName):
"""
the light out management ip of servers allows to talk to the server even when it's asleep
@ -192,6 +195,7 @@ def getClusterMachinesNames():
conn.close()
return clusterMachinesNames
def machineSupportsIpmi(machineName):
if (machineName == 'simpatix') or (machineName == 'simpatix01' or (machineName == 'simpa-mac2')):
# the command ipmitool sensor on simpatix doesn't work :
@ -200,6 +204,7 @@ def machineSupportsIpmi( machineName ):
return False
return True
def putToSleep(machineName):
# note : pmset must be executed as root
(returnCode, stdout, stderr) = executeCommand(['ssh', machineName, 'pmset sleepnow'])
@ -221,6 +226,7 @@ def putToSleep( machineName ):
else:
return False
def wakeUp(machineName):
macAddress = machineNameToMacAddress(machineName)
wake_on_lan(macAddress)
@ -240,6 +246,7 @@ def isNonRespondingMachineSleeping(machineName):
else:
return False
if __name__ == '__main__':
"""
for i in range(30):