diff --git a/utils/chambre_on_off.py b/utils/chambre_on_off.py index 14ac7ae1..4402b9c0 100755 --- a/utils/chambre_on_off.py +++ b/utils/chambre_on_off.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#!/bin/bash /usr/scripts/python.sh # -*- coding: utf-8 -*- """chambre_on_off.py: Affiche le statut, active ou désactive une prise @@ -9,29 +9,39 @@ - off : désactiver la prise - absent : affiche le statut de la prise +Script importé par ra2.py + """ import sys -sys.path.append("/usr/scripts/gestion/") - -import hptools +from gestion import annuaires_pg +from gestion import hptools2 def chambre_on_off(chambre, cmd = None): """Active ou désactive une prise - + chambre: numéro de chambre cmd: si fourni, "on" ou "off" pour activer ou désactiver la prise si cmd n'est pas fourni, ne fait qu'afficher le statut de la prise """ + + # On formatte + bat = chambre[0] + chbre = chambre[1:] + + # On cherche + prise = annuaires_pg.chbre_prises(batiment=bat,chambre=chbre) + switch_name = 'bat'+bat.lower()+'-'+prise[0]+'.adm.crans.org' + # connexion au switch - chbre_sw = hptools.sw_chbre(chambre) + chbre_sw = hptools2.HPSwitch(switch_name) # affichage des infos print "chbre : %s" % chambre - print "switch : %s" % chbre_sw.switch - print "prise : %s" % chbre_sw.prise + print "switch : %s" % switch_name + print "prise : %s" % prise - print "statut : %s" % (chbre_sw.is_enable() and "on" or "off") + print "statut : %s" % chbre_sw.is_enabled(int(prise[1:])) if cmd: cmd = cmd.lower() @@ -39,13 +49,13 @@ def chambre_on_off(chambre, cmd = None): # modification du statut if cmd == "off": print "action : disable" - chbre_sw.disable() + chbre_sw.set_enabled(int(prise[1:]),enabled=False) elif cmd == "on": print "action : enable" - chbre_sw.enable() + chbre_sw.set_enabled(int(prise[1:]),enabled=True) # affichage du nouveau statut - print "statut : %s" % (chbre_sw.is_enable() and "on" or "off") + print "statut : %s" % chbre_sw.is_enabled(int(prise[1:])) if __name__ == '__main__': if len(sys.argv) == 2: