Passage de chbre_on_off à hptools2 (pour ra2.py)
This commit is contained in:
parent
ae803ba2c3
commit
0b12a81e93
1 changed files with 22 additions and 12 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue