43 lines
881 B
Python
43 lines
881 B
Python
#! /usr/bin/env python
|
|
# -*- coding: iso8859-15 -*-
|
|
|
|
"""
|
|
Activation et désactivation d'une chambre
|
|
|
|
prise [chambre] [on|off]
|
|
"""
|
|
|
|
import sys, os
|
|
sys.path.append('/usr/scripts/gestion')
|
|
|
|
from annuaires_pg import chbre_prises
|
|
from hptools import hpswitch
|
|
|
|
if len(sys.argv)!=3 or not sys.argv[2] in ['on','off']:
|
|
print "Syntaxe : chambre X### on|off"
|
|
sys.exit(1)
|
|
|
|
# détermination de la chambre
|
|
bat = sys.argv[1][0].lower()
|
|
chbre = sys.argv[1][1:].lower()
|
|
|
|
# determination de la prise sur le switch
|
|
prise = chbre_prises(bat, chbre)
|
|
switch = prise[0]
|
|
prise = prise[1:]
|
|
|
|
# connection au switch
|
|
sw = hpswitch( 'bat%s-%s.adm.crans.org'%(bat,switch) )
|
|
|
|
etat = sys.argv[2].lower()
|
|
|
|
# action
|
|
if etat == 'on':
|
|
sw.enable(prise)
|
|
elif etat == 'off':
|
|
sw.disable(prise)
|
|
else:
|
|
print 'Erreur : Commande inconnue'
|
|
sys.exit(0)
|
|
|
|
os.system("whos chbre=%s"%sys.argv[1])
|