Пример #1
0
def check_depend(clustershell_IHM, service, name, j):
    if (service[j].dependance != ""):
        serv = str(service[j].dependance)
        serv_split = serv.split(",")
        taske = task_self()
        nodes = str(service[j].noeuds)
        result = []
        error_nodes = []
        for m in range(0, len(serv_split)):
            out = ""
            output = ""
            cli = "service %s start" % serv_split[m]
            taske.shell(cli, nodes=nodes)
            taske.run()
            for output, nodelist in taske.iter_buffers():
                result.append(serv_split[m])
                print(
                    "/!\ Avortement /!\ %s: le service %s n'est pas activé ou installé"
                    % (NodeSet.fromlist(nodelist), serv_split[m]))
                clustershell_IHM.listWidget.addItem(
                    u"Avortement %s: le service %s n'est pas activé ou installé"
                    % (NodeSet.fromlist(nodelist), serv_split[m]))
                dep = "Avortement %s: le service %s n'est pas activé ou installé" % (
                    NodeSet.fromlist(nodelist), serv_split[m])
                clustershell_IHM.list_recap.append(
                    recap_cluster(serv, serv_split[m],
                                  NodeSet.fromlist(nodelist), 0, 1, dep))

    else:
        return (True, 0)
    if (len(result) == 0):
        return (True, 0)
    else:
        return (False, result)
Пример #2
0
def main():
    if len(sys.argv) <= 3:
        print "Veuillez entrer des paramètres (./script.py node[1-3] cron stop)"
    else:
        if ((len(sys.argv) % 2) == 0):
            try:  # vérifie les erreurs de syntaxe pour les nodes
                nodeset = NodeSet(sys.argv[1])
            except:
                print("Erreur: Problème avec la syntaxe \"%s\"" % sys.argv[1])
                return
            for i in range(2, len(sys.argv)):
                if i % 2 == 0:  # pour chaque chiffre pair
                    if (sys.argv[i + 1] == 'start' or 'stop' or 'status'
                            or 'restart' or 'reload'):
                        task = task_self()
                        cli = "service %s %s" % (sys.argv[i], sys.argv[i + 1])
                        task.shell(cli, nodes=sys.argv[1])
                        task.run()
                        for output, nodelist in task.iter_buffers():
                            print ''
                            print '%s: %s' % (NodeSet.fromlist(nodelist),
                                              output)
                    else:
                        print(
                            "Erreur: Veuillez vérifier que la commande soit compris dans [start,stop,status,restart,reload]"
                        )
        else:
            print("Erreur: Veuillez vérifier le nombre de paramètres")
Пример #3
0
def check_etat_noeud2(etatnoeud_IHM, nodeset):

    etatnoeud_IHM.listWidget.clear()
    etatnoeud_IHM.listWidget_2.clear()
    etatnoeud_IHM.listWidget_3.clear()

    i = 1

    print nodeset
    for node in nodeset:
        cli = "echo Hello"
        taske = task_self()
        taske.shell(cli, nodes=node)
        taske.run()

        for output, nodelist in task_self().iter_buffers():
            if (output == "Hello"):

                etatnoeud_IHM.listWidget.insertItem(
                    i, "%s" % (NodeSet.fromlist(nodelist)))
                i = i + 1

            else:
                etatnoeud_IHM.listWidget_2.insertItem(
                    i, "%s" % (NodeSet.fromlist(nodelist)))
                i = i + 1
                etatnoeud_IHM.sortie.append(output)
                print "output: %s" % output
Пример #4
0
def run_task(cmd):
        task = task_self()
        for node in NodeSet('@pbsadmin'):
                task.run(cmd, nodes=node, timeout=60)
                for output, nodelist in task.iter_buffers():
                        if str(NodeSet.fromlist(nodelist)) == node:
                                return str(output)
                return None
Пример #5
0
def check_attribut2(doc, service, etatnoeud_IHM):
    a = 0
    new_nodeset = NodeSet()
    for i in range(0, len(service)):
        ok = 0
        name = service[i]

        if (doc[i].get(name).has_key("state") == False):
            print("/!\\ attribut \"state\" manquant pour %d: %s /!\\" %
                  (i, name))
            QMessageBox.about(
                etatnoeud_IHM, u"Erreur",
                "/!\\ attribut \"state\" manquant pour %d: %s /!\\" %
                (i + 1, name))
            return (False)
        if not (doc[i].get(name).get("state")
                in ['start', 'stop', 'status', 'reload']):
            print(
                "/!\\ attribut \"state\" doit être [start/stop/status/reload] pour %d: %s /!\\"
                % (i, name))
            QMessageBox.about(
                etatnoeud_IHM, u"Erreur",
                "/!\\ attribut \"state\" doit être [start/stop/status/reload] pour %d: %s /!\\"
                % (i + 1, name))
            return (False)
        if (doc[i].get(name).has_key("nodes") == False
                or doc[i].get(name).get("nodes") == None):
            print("/!\\ attribut \"nodes\" manquant pour %d: %s /!\\" %
                  (i, name))
            QMessageBox.about(
                etatnoeud_IHM, u"Erreur",
                "/!\\ attribut \"nodes\" manquant pour %d: %s /!\\" %
                (i + 1, name))
            return (False)
        try:  # vérifie les erreurs de syntaxe pour les node
            nodeset = NodeSet(doc[i].get(name).get("nodes"))
            new_nodeset.update(nodeset)
            ok = 1
        except:
            QMessageBox.about(
                etatnoeud_IHM, u"Erreur",
                "/!\\ Problème avec la syntaxe de \"%s\" pour %d: %s /!\\" %
                (doc[i].get(name).get("nodes"), i, name))
            print("/!\\ Problème avec la syntaxe de \"%s\" pour %d: %s /!\\" %
                  (doc[i].get(name).get("nodes"), i + 1, name))
            print("\n")
            return (False)

    if (ok == 1):
        check_etat_noeud2(etatnoeud_IHM, new_nodeset)

    return (True)
Пример #6
0
def check_attribut(doc, service):
    for i in range(
            0, len(service)):  # vérification des attributs de chaque service
        name = service[i]
        if (doc[i].get(name).has_key("state") == False):
            print("/!\\ attribut \"state\" manquant pour %d: %s /!\\" %
                  (i, name))
            return (False)
        if not (doc[i].get(name).get("state")
                in ['start', 'stop', 'status', 'reload', 'restart']):
            print(
                "/!\\ attribut \"state\" doit être [start/stop/status/reload] pour %d: %s /!\\"
                % (i, name))
            return (False)
        if (doc[i].get(name).has_key("nodes") == False
                or doc[i].get(name).get("nodes") == None):
            print("/!\\ attribut \"nodes\" manquant pour %d: %s /!\\" %
                  (i, name))
            return (False)
        try:  # vérifie les erreurs de syntaxe pour les nodes
            nodeset = NodeSet(doc[i].get(name).get("nodes"))
        except:
            print("/!\\ Problème avec la syntaxe de \"%s\" pour %d: %s /!\\" %
                  (doc[i].get(name).get("nodes"), i, name))
            print("\n")
            return (False)
    return (True)
Пример #7
0
    def __init__(self, hostname, nids, hdlr=None):
        assert isinstance(nids, list)
        self.nids = nids
        self.hostname = NodeSet(hostname)
        self.modules = dict()
        self.action_enabled = True

        self.hdlr = hdlr or EventHandler()
        self._running_actions = []
Пример #8
0
    def check_etat_noeud():
        etatnoeud_IHM.listWidget.clear()
        etatnoeud_IHM.listWidget_2.clear()
        etatnoeud_IHM.listWidget_3.clear()

        i = 1
        msg = QMessageBox()
        msg.setIcon(QMessageBox.Warning)
        msg.setWindowTitle("Erreur")
        noeuds = etatnoeud_IHM.lineEdit.text()
        print "noeuds %s" % noeuds
        if (noeuds != ""):
            try:
                nodeset = NodeSet(str(noeuds))
                print nodeset
                for node in nodeset:
                    cli = "echo Hello"
                    taske = task_self()
                    taske.shell(cli, nodes=node)
                    taske.run()

                    for output, nodelist in task_self().iter_buffers():
                        if (output == "Hello"):

                            etatnoeud_IHM.listWidget.insertItem(
                                i, u"%s" % (NodeSet.fromlist(nodelist)))
                            i = i + 1

                        else:
                            etatnoeud_IHM.listWidget_2.insertItem(
                                i, u"%s" % (NodeSet.fromlist(nodelist)))
                            i = i + 1
                            etatnoeud_IHM.sortie.append(output)
                            print "output: %s" % output

            except:
                msg.setText("Oups ! Probleme")
                msg.exec_()

        else:
            msg.setText("Veuillez rentrer un ou plusieur noeuds")
            msg.setDetailedText(
                "node1,node2\nnode[1-5]\nnode1,node[5-6]\netc...")
            msg.exec_()
Пример #9
0
def run_task(cmd):
    """ run task on pbs server node """

    task = task_self()

    for node in NodeSet('@pbsadmin'):
        """ run on pbs nodes until it works """
        #print (cmd, node)
        task.run(cmd, nodes=node, timeout=60)

        #print 'node: %s error: %s' % (node, task.node_error(node))
        vlog(
            4, '%s timeouts:%s Error=%s' %
            (node, task.num_timeout(), task.node_error(node)))

        for output, nodelist in task.iter_buffers():
            #print 'nodelist:%s' % NodeSet.fromlist(nodelist)
            if str(NodeSet.fromlist(nodelist)) == node:
                return str(output)
            #print '%s: %s' % (NodeSet.fromlist(nodelist), output)

    return None
Пример #10
0
def clustershell(doc, service):  # Commandes distribuées
    recap = []
    for i in range(0, len(service)):
        task = task_self()
        name = service[i]
        name_split = service[i].split(",")
        state = doc[i].get(name).get("state")
        nodes = doc[i].get(name).get("nodes")
        x, y = getTerminalSize()
        string = "TASK: [%s]" % name
        star = '*' * (x - len(string))
        print("%s %s" % (string, star))
        test_depend, result, error_nodes = check_depend(doc, name, i)
        if (test_depend == True):
            for n in range(0, len(name_split)):
                out = ""
                output = ""
                cli = "service %s %s" % (name_split[n], state)
                task.shell(cli, nodes=nodes)
                task.run()
                space = ' ' * (15 - len(name_split[n]))
                printout(
                    "%s%s:  state=%s     nodes=%s\n" %
                    (name_split[n], space, state, nodes), YELLOW)
                for output, nodelist in task.iter_buffers():
                    printout(
                        'Error: %s: %s\n' %
                        (NodeSet.fromlist(nodelist), output), RED)
                    recap.append(0)
                if (out == output):
                    printout("OK\n", GREEN)
                    recap.append(1)
                print("")
        else:
            space = ' ' * (15 - len(name))
            printout(
                "%s%s:  state=%s    nodes=%s\n" % (name, space, state, nodes),
                YELLOW)
            printout(
                "Error depend %s: le(s) service(s) %s n'est(sont) pas activé(s) ou installé(s)\n"
                % (error_nodes, result), RED)
            print("")
            for yop in range(0, len(name_split)):
                recap.append(0)
    return recap
Пример #11
0
def clustershell(clustershell_IHM, service, i):
    task = task_self()
    name = str(service[i].nom)
    name_split = name.split(",")
    state = str(service[i].action)
    nodes = str(service[i].noeuds)
    test_depend, result = check_depend(clustershell_IHM, service, name, i)
    if (test_depend == True):
        for n in range(0, len(name_split)):
            out = ""
            output = ""
            cli = "service %s %s" % (name_split[n], state)
            task.shell(cli, nodes=nodes)
            task.run()
            nodeset = NodeSet(nodes)
            for output, nodelist in task.iter_buffers():
                print("FAIL %s: %s %s" %
                      (name_split[n], NodeSet.fromlist(nodelist), output))
                clustershell_IHM.listWidget.addItem(
                    u"FAIL %s: %s %s" %
                    (name_split[n], NodeSet.fromlist(nodelist), output))
                nodeset.remove(NodeSet.fromlist(nodelist))
                clustershell_IHM.list_recap.append(
                    recap_cluster(name, name_split[n],
                                  NodeSet.fromlist(nodelist), 0, 2, output))
            if (str(nodeset) != nodes):
                if (len(nodeset) > 0):
                    print("OK %s: %s" % (name_split[n], nodeset))
                    clustershell_IHM.listWidget.addItem(
                        u"OK %s: %s" % (name_split[n], nodeset))
                    clustershell_IHM.list_recap.append(
                        recap_cluster(name, name_split[n], nodeset, 1))
            if (str(nodeset) == nodes):
                print("OK %s: %s" % (name_split[n], nodes))
                clustershell_IHM.listWidget.addItem(u"OK %s: %s" %
                                                    (name_split[n], nodes))
                clustershell_IHM.list_recap.append(
                    recap_cluster(name, name_split[n], nodes, 1))
Пример #12
0
 def on_click_add_service():
     ok = 0
     if (configuration_IHM.lineEdit.text() != ""):
         name = configuration_IHM.lineEdit.text()
         dependance = configuration_IHM.lineEdit_3.text()
         action = configuration_IHM.comboBox.currentText()
         if (configuration_IHM.lineEdit_2.text() != ""):
             try:
                 noeuds = configuration_IHM.lineEdit_2.text()
                 nodeset = NodeSet(str(noeuds))
                 ok = 1
             except:
                 noeuds = ""
                 QMessageBox.about(configuration_IHM, "Erreur",
                                   "Syntaxe noeuds incorrect")
             if (ok == 1 and name != "" and noeuds != ""
                     and dependance != ""):
                 configuration_IHM.listWidget.addItem(
                     u"%d: %s %s ON %s (depend %s)" %
                     (configuration_IHM.listWidget.count() + 1, name,
                      action, noeuds, dependance))
                 clustershell_IHM.list_service.append(
                     typeservice(name, action, noeuds, dependance))
                 print("c'est cool")
             if (ok == 1 and name != "" and noeuds != ""
                     and dependance == ""):
                 configuration_IHM.listWidget.addItem(
                     u"%d: %s %s ON %s" %
                     (configuration_IHM.listWidget.count() + 1, name,
                      action, noeuds))
                 clustershell_IHM.list_service.append(
                     typeservice(name, action, noeuds))
         else:
             QMessageBox.about(configuration_IHM, "Erreur",
                               "Attribut noeuds manquant")
     else:
         QMessageBox.about(configuration_IHM, "Erreur",
                           "Attribut service manquant")
Пример #13
0
def check_depend(doc, name, i):
    if (doc[i].get(name).get("depend") != None):
        serv = doc[i].get(name).get("depend")
        serv_split = serv.split(",")
        taske = task_self()
        nodes = doc[i].get(name).get("nodes")
        # out=""
        # output=""
        result = []
        for m in range(0, len(serv_split)):
            out = ""
            output = ""
            cli = "service %s start" % serv_split[m]
            taske.shell(cli, nodes=nodes)
            taske.run()
            for output, nodelist in taske.iter_buffers():
                result.append(serv_split[m])
                error_nodes = NodeSet.fromlist(nodelist)
    else:
        return (True, 0, 0)
    if (len(result) == 0):
        return (True, 0, 0)
    else:
        return (False, result, error_nodes)
Пример #14
0
 def nodeset(self):
     """Return a NodeSet from server hostnames."""
     return NodeSet.fromlist((srv.hostname for srv in self))
Пример #15
0
	def display(self, task) :
		self.clearnodes()
		for output, nodeset in task.iter_buffers() :
			self.nodes['text'] += str(NodeSet.fromlist(nodeset)) + ' ' + str(output) + '\n'
Пример #16
0
	def addnode(self, nodelist) :
		self.nodes.insert(END, unicode(NodeSet.fromlist(map(str, nodelist))))
		self.edited()
Пример #17
0
 def nodeset(self):
     """Return a NodeSet from server hostnames."""
     return NodeSet.fromlist((srv.hostname for srv in self))
Пример #18
0
def check_attribut(doc, service, clustershell_IHM, configuration_IHM):
    for i in range(0, len(service)):
        ok = 0
        name = service[i]
        if (doc[i].get(name).has_key("state") == False):
            print("/!\\ attribut \"state\" manquant pour %d: %s /!\\" %
                  (i, name))
            QMessageBox.about(
                configuration_IHM, u"Erreur",
                "/!\\ attribut \"state\" manquant pour %d: %s /!\\" %
                (i + 1, name))
            return (False)
        if not (doc[i].get(name).get("state")
                in ['start', 'stop', 'status', 'reload']):
            print(
                "/!\\ attribut \"state\" doit être [start/stop/status/reload] pour %d: %s /!\\"
                % (i, name))
            QMessageBox.about(
                configuration_IHM, u"Erreur",
                "/!\\ attribut \"state\" doit être [start/stop/status/reload] pour %d: %s /!\\"
                % (i + 1, name))
            return (False)
        if (doc[i].get(name).has_key("nodes") == False
                or doc[i].get(name).get("nodes") == None):
            print("/!\\ attribut \"nodes\" manquant pour %d: %s /!\\" %
                  (i, name))
            QMessageBox.about(
                configuration_IHM, u"Erreur",
                "/!\\ attribut \"nodes\" manquant pour %d: %s /!\\" %
                (i + 1, name))
            return (False)
        try:  # vérifie les erreurs de syntaxe pour les node
            nodeset = NodeSet(doc[i].get(name).get("nodes"))
            ok = 1
        except:
            QMessageBox.about(
                configuration_IHM, u"Erreur",
                "/!\\ Problème avec la syntaxe de \"%s\" pour %d: %s /!\\" %
                (doc[i].get(name).get("nodes"), i, name))
            print("/!\\ Problème avec la syntaxe de \"%s\" pour %d: %s /!\\" %
                  (doc[i].get(name).get("nodes"), i + 1, name))
            print("\n")
            return (False)

    if (ok == 1):
        for i in range(0, len(service)):
            name = service[i]
            action = doc[i].get(name).get("state")
            noeuds = doc[i].get(name).get("nodes")
            if (doc[i].get(name).get("depend") != None):
                dependance = doc[i].get(name).get("depend")
                print dependance
                configuration_IHM.listWidget.addItem(
                    u"%d: %s %s ON %s (depend %s)" %
                    (configuration_IHM.listWidget.count() + 1, name, action,
                     str(nodeset), dependance))
                clustershell_IHM.list_service.append(
                    typeservice(name, action, noeuds, dependance))
            else:
                configuration_IHM.listWidget.addItem(
                    u"%d: %s %s ON %s" %
                    (configuration_IHM.listWidget.count() + 1, name, action,
                     str(nodeset)))
                clustershell_IHM.list_service.append(
                    typeservice(name, action, noeuds))

    return (True)
Пример #19
0
	def display(self, task) :
		self.clearnodes()
		for output, nodeset in task.iter_buffers() :
			self.nodes['text'] += str(NodeSet.fromlist(nodeset)) + ' ' + str(output) + '\n'
		service = self.services.get(self.services.curselection()[0])
		self.enableactions(self.application.config['services'][service]['actions'])
Пример #20
0
if len(sys.argv) == 4 :
	action = sys.argv[2]
	nodes = [(sys.argv[1], 'service ', sys.argv[1], sys.argv[3])]
elif len(sys.argv) == 3 :
	config.load()

	action = sys.argv[2]
	nodes = config.fetchNodes(sys.argv[1], action)
	
	if len(nodes) == 0 :
		print 'Service ' + sys.argv[1] + ' not found'
		exit(2)

else :
	print 'Usage : ' + sys.argv[0] + ' <service> <action> <nodeset>'
	exit(1)

task = task_self()

for service, daemon, manager, node in nodes:
	if config.checkAction(service, action) :
		task.shell(manager + daemon + ' ' + action, nodes=node)

	else :
		print 'Action "' + action + '" is not supported by ' + service
		print 'Actions supported : ' + config.listActions(service)
task.run()

for output, nodeset in task.iter_buffers():
	print NodeSet.fromlist(nodeset), output