reformatted code to pep8 convention
This commit is contained in:
parent
c750804914
commit
197e94d320
|
@ -1,16 +1,15 @@
|
||||||
import MySQLdb
|
import MySQLdb
|
||||||
import time
|
import time
|
||||||
import subprocess
|
|
||||||
import StringIO
|
import StringIO
|
||||||
import re
|
import re
|
||||||
from wol import *
|
from wol import *
|
||||||
import os
|
import os
|
||||||
import signal
|
|
||||||
from Util import *
|
from Util import *
|
||||||
import abc
|
import abc
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from mysql2sqlite import mysql_to_sqlite
|
from mysql2sqlite import mysql_to_sqlite
|
||||||
|
|
||||||
|
|
||||||
def isMachineResponding(machineName):
|
def isMachineResponding(machineName):
|
||||||
(returnCode, stdout, stderr) = executeProgram(['ping', '-o', '-t', '1', machineName])
|
(returnCode, stdout, stderr) = executeProgram(['ping', '-o', '-t', '1', machineName])
|
||||||
# log( 'isMachineResponding : result of command %s : %d' % (command, returnCode) )
|
# log( 'isMachineResponding : result of command %s : %d' % (command, returnCode) )
|
||||||
|
@ -20,12 +19,12 @@ def isMachineResponding(machineName):
|
||||||
else:
|
else:
|
||||||
bMachineNameIsNotKnown = (returnCode == 68)
|
bMachineNameIsNotKnown = (returnCode == 68)
|
||||||
bMachineIsNotResponding = (returnCode == 2)
|
bMachineIsNotResponding = (returnCode == 2)
|
||||||
if bMachineIsNotResponding == False:
|
if bMachineIsNotResponding is False:
|
||||||
bBUG_00000004_IS_STILL_ALIVE = True
|
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))
|
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
|
# 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))
|
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
|
# don't stop the program until we understand bug00000004
|
||||||
else:
|
else:
|
||||||
|
@ -33,6 +32,7 @@ def isMachineResponding(machineName):
|
||||||
assert(False)
|
assert(False)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class ISqlDatabaseBackend(object):
|
class ISqlDatabaseBackend(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
@ -44,6 +44,7 @@ class ISqlDatabaseBackend(object):
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class RemoteMysqlDb(ISqlDatabaseBackend):
|
class RemoteMysqlDb(ISqlDatabaseBackend):
|
||||||
def __init__(self, db_server_fqdn, db_user, db_name):
|
def __init__(self, db_server_fqdn, db_user, db_name):
|
||||||
"""
|
"""
|
||||||
|
@ -143,6 +144,7 @@ class SqlDatabaseReader(object):
|
||||||
attr_value = rows[0][0]
|
attr_value = rows[0][0]
|
||||||
return attr_value
|
return attr_value
|
||||||
|
|
||||||
|
|
||||||
def machineNameToMacAddress(machineName):
|
def machineNameToMacAddress(machineName):
|
||||||
conn = MySQLdb.connect('simpatix10', 'simpadb_reader', '', 'simpadb')
|
conn = MySQLdb.connect('simpatix10', 'simpadb_reader', '', 'simpadb')
|
||||||
assert(conn)
|
assert(conn)
|
||||||
|
@ -158,6 +160,7 @@ def machineNameToMacAddress( machineName ):
|
||||||
conn.close()
|
conn.close()
|
||||||
return macAddress
|
return macAddress
|
||||||
|
|
||||||
|
|
||||||
def getLightOutManagementIpAddress(machineName):
|
def getLightOutManagementIpAddress(machineName):
|
||||||
"""
|
"""
|
||||||
the light out management ip of servers allows to talk to the server even when it's asleep
|
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()
|
conn.close()
|
||||||
return clusterMachinesNames
|
return clusterMachinesNames
|
||||||
|
|
||||||
|
|
||||||
def machineSupportsIpmi(machineName):
|
def machineSupportsIpmi(machineName):
|
||||||
if (machineName == 'simpatix') or (machineName == 'simpatix01' or (machineName == 'simpa-mac2')):
|
if (machineName == 'simpatix') or (machineName == 'simpatix01' or (machineName == 'simpa-mac2')):
|
||||||
# the command ipmitool sensor on simpatix doesn't work :
|
# the command ipmitool sensor on simpatix doesn't work :
|
||||||
|
@ -200,6 +204,7 @@ def machineSupportsIpmi( machineName ):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def putToSleep(machineName):
|
def putToSleep(machineName):
|
||||||
# note : pmset must be executed as root
|
# note : pmset must be executed as root
|
||||||
(returnCode, stdout, stderr) = executeCommand(['ssh', machineName, 'pmset sleepnow'])
|
(returnCode, stdout, stderr) = executeCommand(['ssh', machineName, 'pmset sleepnow'])
|
||||||
|
@ -221,6 +226,7 @@ def putToSleep( machineName ):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def wakeUp(machineName):
|
def wakeUp(machineName):
|
||||||
macAddress = machineNameToMacAddress(machineName)
|
macAddress = machineNameToMacAddress(machineName)
|
||||||
wake_on_lan(macAddress)
|
wake_on_lan(macAddress)
|
||||||
|
@ -240,6 +246,7 @@ def isNonRespondingMachineSleeping(machineName):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
"""
|
"""
|
||||||
for i in range(30):
|
for i in range(30):
|
||||||
|
|
Loading…
Reference in New Issue