Bug 2218 - la mise à jour de simpatix51 a échoué (ClusterConfigurator)
- Correction : bug introduit récemment lors du refactoring
This commit is contained in:
parent
7e8edeab20
commit
05d21bc427
84
Util.py
84
Util.py
|
@ -1,29 +1,33 @@
|
||||||
import time
|
import time
|
||||||
import subprocess
|
import subprocess
|
||||||
import StringIO
|
# import StringIO
|
||||||
import re
|
import re
|
||||||
from wol import *
|
# from wol import *
|
||||||
import os
|
# import os
|
||||||
import signal
|
# import signal
|
||||||
import smtplib
|
import smtplib
|
||||||
from email.MIMEText import MIMEText
|
from email.MIMEText import MIMEText
|
||||||
|
from HTMLParser import HTMLParser
|
||||||
|
|
||||||
def sendTextMail(strFrom, to, strSubject, text ):
|
|
||||||
#from = "SimpaCluster <guillaume.raffy@univ-rennes1.fr>"
|
def sendTextMail(strFrom, to, strSubject, text):
|
||||||
|
# from = "SimpaCluster <guillaume.raffy@univ-rennes1.fr>"
|
||||||
mail = MIMEText(text)
|
mail = MIMEText(text)
|
||||||
mail['From'] = strFrom
|
mail['From'] = strFrom
|
||||||
mail['Subject'] = strSubject
|
mail['Subject'] = strSubject
|
||||||
mail['To'] = to
|
mail['To'] = to
|
||||||
smtp = smtplib.SMTP('smtp.univ-rennes1.fr', 25)
|
smtp = smtplib.SMTP('smtp.univ-rennes1.fr', 25)
|
||||||
#smtp.connect()
|
# smtp.connect()
|
||||||
#smtp.login('guillaume.raffy@univ-rennes1.fr', 'password')
|
# smtp.login('guillaume.raffy@univ-rennes1.fr', 'password')
|
||||||
smtp.sendmail(strFrom, [to], mail.as_string())
|
smtp.sendmail(strFrom, [to], mail.as_string())
|
||||||
smtp.close()
|
smtp.close()
|
||||||
|
|
||||||
class Error( Exception ):
|
|
||||||
def __init__( self, strMessage ):
|
class Error(Exception):
|
||||||
|
def __init__(self, strMessage):
|
||||||
self.m_strMessage = strMessage
|
self.m_strMessage = strMessage
|
||||||
|
|
||||||
|
|
||||||
def getHostName():
|
def getHostName():
|
||||||
(returnCode, stdout, stderr) = executeProgram(['hostname', '-s'])
|
(returnCode, stdout, stderr) = executeProgram(['hostname', '-s'])
|
||||||
if returnCode != 0:
|
if returnCode != 0:
|
||||||
|
@ -31,36 +35,65 @@ def getHostName():
|
||||||
strHostName = re.sub(r"\n", "", stdout)
|
strHostName = re.sub(r"\n", "", stdout)
|
||||||
return strHostName
|
return strHostName
|
||||||
|
|
||||||
def log( message ):
|
|
||||||
print time.asctime(time.localtime())+' : '+ message
|
|
||||||
|
|
||||||
def executeProgram( astrArguments ):
|
def log(message):
|
||||||
|
print time.asctime(time.localtime()) + ' : ' + message
|
||||||
|
|
||||||
#log('executeProgram : program [%s]' % (','.join(astrArguments)))
|
|
||||||
popen = subprocess.Popen( astrArguments, bufsize=1, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) # bufsize=1 seems to prevent deadlocks that happen 50% the time
|
def executeProgram(astrArguments):
|
||||||
|
# log('executeProgram : program [%s]' % (','.join(astrArguments)))
|
||||||
|
popen = subprocess.Popen( astrArguments, bufsize=1, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # bufsize=1 seems to prevent deadlocks that happen 50% the time
|
||||||
stdout, stderr = popen.communicate()
|
stdout, stderr = popen.communicate()
|
||||||
#popen.wait()
|
# popen.wait()
|
||||||
result = (popen.returncode, stdout, stderr)
|
result = (popen.returncode, stdout, stderr)
|
||||||
#log('executeProgram : command %s popen.pid = %d' % (astrArguments[0], popen.pid))
|
# log('executeProgram : command %s popen.pid = %d' % (astrArguments[0], popen.pid))
|
||||||
#os.kill(popen.pid, signal.SIGTERM)
|
# os.kill(popen.pid, signal.SIGTERM)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def executeCommand( command ):
|
|
||||||
|
def executeCommand(command):
|
||||||
"""
|
"""
|
||||||
executes the shell command such as 'set x=1; myprog $x'
|
executes the shell command such as 'set x=1; myprog $x'
|
||||||
"""
|
"""
|
||||||
popen = subprocess.Popen( [ command ], bufsize=1, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, executable = '/bin/bash' ) # bufsize=1 seems to prevent deadlocks that happen 50% the time
|
popen = subprocess.Popen( [command], bufsize=1, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, executable='/bin/bash') # bufsize=1 seems to prevent deadlocks that happen 50% the time
|
||||||
# if we don't specify the optional executable argument, then the default non interactive shell will be used. On debian, the default non-interactive shell is dash, which doesn't understand the keyword 'source' that we use in many places
|
# if we don't specify the optional executable argument, then the default non interactive shell will be used. On debian, the default non-interactive shell is dash, which doesn't understand the keyword 'source' that we use in many places
|
||||||
stdout, stderr = popen.communicate()
|
stdout, stderr = popen.communicate()
|
||||||
#popen.wait()
|
# popen.wait()
|
||||||
result = (popen.returncode, stdout, stderr)
|
result = (popen.returncode, stdout, stderr)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def executeCommandOn(strTargetMachineName, strCommand):
|
||||||
|
"""
|
||||||
|
execute command on a local or remote machine (using ssh then)
|
||||||
|
"""
|
||||||
|
# print("comparing %s and %s" % (Lib.Util.getHostName(), strTargetMachineName))
|
||||||
|
if getHostName() == strTargetMachineName:
|
||||||
|
return executeCommand(strCommand)
|
||||||
|
else:
|
||||||
|
return executeProgram(['ssh', strTargetMachineName, "%s" % strCommand])
|
||||||
|
|
||||||
|
|
||||||
def getUpsStatus():
|
def getUpsStatus():
|
||||||
|
|
||||||
|
class MyHTMLParser(HTMLParser):
|
||||||
|
def __init__(self):
|
||||||
|
HTMLParser.__init__(self)
|
||||||
|
self.TokenList = []
|
||||||
|
|
||||||
|
def handle_data( self, data):
|
||||||
|
data = data.strip()
|
||||||
|
if data and len(data) > 0:
|
||||||
|
self.TokenList.append(data)
|
||||||
|
# print data
|
||||||
|
|
||||||
|
def GetTokenList(self):
|
||||||
|
return self.TokenList
|
||||||
|
import urllib2
|
||||||
|
|
||||||
try:
|
try:
|
||||||
url = 'http://Net Vision:public@129.20.27.119/PageMonComprehensive.html'
|
url = 'http://Net Vision:public@129.20.27.119/PageMonComprehensive.html'
|
||||||
f = urllib.urlopen(url)
|
f = urllib2.urlopen(url)
|
||||||
res = f.read()
|
res = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
except:
|
except:
|
||||||
|
@ -68,14 +101,15 @@ def getUpsStatus():
|
||||||
return
|
return
|
||||||
h = MyHTMLParser()
|
h = MyHTMLParser()
|
||||||
h.feed(res)
|
h.feed(res)
|
||||||
tokensList = h.GetTokenList()
|
tokensList = h.GetTokenList() # @UnusedVariable
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
from SimpaDbUtil import wakeUp
|
||||||
"""
|
"""
|
||||||
for i in range(30):
|
for i in range(30):
|
||||||
machineName = 'simpatix%d' % (i+10)
|
machineName = 'simpatix%d' % (i+10)
|
||||||
print 'lom ip of %s is %s' % (machineName, getLightOutManagementIpAddress(machineName))
|
print 'lom ip of %s is %s' % (machineName, getLightOutManagementIpAddress(machineName))
|
||||||
"""
|
"""
|
||||||
wakeUp('simpatix21')
|
wakeUp('simpatix21')
|
||||||
#print putToSleep('simpatix13')
|
# print putToSleep('simpatix13')
|
||||||
#print isNonRespondingMachineSleeping('simpatix13')
|
# print isNonRespondingMachineSleeping('simpatix13')
|
||||||
|
|
Loading…
Reference in New Issue