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
48
Util.py
48
Util.py
|
@ -1,12 +1,14 @@
|
|||
import time
|
||||
import subprocess
|
||||
import StringIO
|
||||
# import StringIO
|
||||
import re
|
||||
from wol import *
|
||||
import os
|
||||
import signal
|
||||
# from wol import *
|
||||
# import os
|
||||
# import signal
|
||||
import smtplib
|
||||
from email.MIMEText import MIMEText
|
||||
from HTMLParser import HTMLParser
|
||||
|
||||
|
||||
def sendTextMail(strFrom, to, strSubject, text):
|
||||
# from = "SimpaCluster <guillaume.raffy@univ-rennes1.fr>"
|
||||
|
@ -20,10 +22,12 @@ def sendTextMail(strFrom, to, strSubject, text ):
|
|||
smtp.sendmail(strFrom, [to], mail.as_string())
|
||||
smtp.close()
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
def __init__(self, strMessage):
|
||||
self.m_strMessage = strMessage
|
||||
|
||||
|
||||
def getHostName():
|
||||
(returnCode, stdout, stderr) = executeProgram(['hostname', '-s'])
|
||||
if returnCode != 0:
|
||||
|
@ -31,11 +35,12 @@ def getHostName():
|
|||
strHostName = re.sub(r"\n", "", stdout)
|
||||
return strHostName
|
||||
|
||||
|
||||
def log(message):
|
||||
print time.asctime(time.localtime()) + ' : ' + message
|
||||
|
||||
def executeProgram( astrArguments ):
|
||||
|
||||
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()
|
||||
|
@ -45,6 +50,7 @@ def executeProgram( astrArguments ):
|
|||
# os.kill(popen.pid, signal.SIGTERM)
|
||||
return result
|
||||
|
||||
|
||||
def executeCommand(command):
|
||||
"""
|
||||
executes the shell command such as 'set x=1; myprog $x'
|
||||
|
@ -57,10 +63,37 @@ def executeCommand( command ):
|
|||
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():
|
||||
|
||||
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:
|
||||
url = 'http://Net Vision:public@129.20.27.119/PageMonComprehensive.html'
|
||||
f = urllib.urlopen(url)
|
||||
f = urllib2.urlopen(url)
|
||||
res = f.read()
|
||||
f.close()
|
||||
except:
|
||||
|
@ -68,9 +101,10 @@ def getUpsStatus():
|
|||
return
|
||||
h = MyHTMLParser()
|
||||
h.feed(res)
|
||||
tokensList = h.GetTokenList()
|
||||
tokensList = h.GetTokenList() # @UnusedVariable
|
||||
|
||||
if __name__ == '__main__':
|
||||
from SimpaDbUtil import wakeUp
|
||||
"""
|
||||
for i in range(30):
|
||||
machineName = 'simpatix%d' % (i+10)
|
||||
|
|
Loading…
Reference in New Issue