From d67c4d6a21fa21e3759b7ce6e8007bc875b4fe8d Mon Sep 17 00:00:00 2001 From: Guillaume Raffy Date: Thu, 28 Jun 2012 12:22:07 +0000 Subject: [PATCH] =?UTF-8?q?dans=20l'optique=20de=20remettre=20ClusterContr?= =?UTF-8?q?oller=20en=20production,=20les=20administateurs=20peuvent=20d?= =?UTF-8?q?=C3=A9sormais=20ajouter=20ou=20supprimer=20une=20machine=20du?= =?UTF-8?q?=20contr=C3=B4le=20du=20cluster=20controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ClusterController/ClusterNode.py | 16 ++++++++-------- ClusterController/WebServer.py | 20 ++++++++++++++++---- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/ClusterController/ClusterNode.py b/ClusterController/ClusterNode.py index c51d9e2..70b2cf5 100644 --- a/ClusterController/ClusterNode.py +++ b/ClusterController/ClusterNode.py @@ -57,17 +57,17 @@ class ClusterNode: bUpdateRequiredChecks = True if bUpdateRequiredChecks: if self.m_powerState == PowerState.ON: - self.m_machineStatusUpdater.m_bCheckPowerState = True - self.m_machineStatusUpdater.m_bCheckSensors = True + self.m_machineStatusUpdater.m_bCheckPowerState = True + self.m_machineStatusUpdater.m_bCheckSensors = True elif self.m_powerState == PowerState.OFF: - self.m_machineStatusUpdater.m_bCheckPowerState = True - self.m_machineStatusUpdater.m_bCheckSensors = False + self.m_machineStatusUpdater.m_bCheckPowerState = True + self.m_machineStatusUpdater.m_bCheckSensors = False elif self.m_powerState == PowerState.SLEEP: - self.m_machineStatusUpdater.m_bCheckPowerState = True - self.m_machineStatusUpdater.m_bCheckSensors = False + self.m_machineStatusUpdater.m_bCheckPowerState = True + self.m_machineStatusUpdater.m_bCheckSensors = False elif self.m_powerState == PowerState.UNPLUGGED: - self.m_machineStatusUpdater.m_bCheckPowerState = True - self.m_machineStatusUpdater.m_bCheckSensors = False + self.m_machineStatusUpdater.m_bCheckPowerState = True + self.m_machineStatusUpdater.m_bCheckSensors = False else: assert( False ) diff --git a/ClusterController/WebServer.py b/ClusterController/WebServer.py index ea84c30..f17fd38 100644 --- a/ClusterController/WebServer.py +++ b/ClusterController/WebServer.py @@ -7,6 +7,7 @@ import threading import Util #import pri from urlparse import urlparse, parse_qs +import xml.dom.minidom #>>> url = 'http://example.com/?foo=bar&one=1' #>>> parse_qs(urlparse(url).query) #{'foo': ['bar'], 'one': ['1']} @@ -36,12 +37,23 @@ class MyHandler(BaseHTTPRequestHandler): return if self.path.endswith("ShowControlledMachines"): #http://simpatix10.univ-rennes1.fr:8080/ShowControlledMachines self.send_response(200) - self.send_header('Content-type', 'text/html') + self.send_header('Content-type', 'text/xml') self.end_headers() - self.wfile.write("hey, today is the" + str(time.localtime()[7])) - self.wfile.write(" day in the year " + str(time.localtime()[0])) + + # Create the minidom document + doc = xml.dom.minidom.Document() + + # Create the root element + controlledMachinesElement = doc.createElement("ControlledMachines") + doc.appendChild(controlledMachinesElement) + for machine in self.server.m_clusterController.m_clusterStatus.m_clusterNodes.itervalues(): - self.wfile.write("%s is controlled by ClusterController" % machine.getName()) + # Create the main element + controlledMachineElement = doc.createElement("Machine") + controlledMachineElement.setAttribute("name", machine.getName()) + controlledMachinesElement.appendChild(controlledMachineElement) + # Print our newly created XML + self.wfile.write(doc.toprettyxml(indent=" ")) return if urlparse(self.path).path == '/SetControlOnMachine': #http://simpatix10.univ-rennes1.fr:8080/SetControlOnMachine?machineName=simpatix30&control=1 machineName = paramsDict['machineName'][0]