Proyecto

General

Perfil

87 Chisco
##############################################################################
# -*- coding: utf-8 -*-
# Project: EnciendeEquipos
# Module: EnciendeEquipos.py
# Purpose: Wakes up classrom servers in an IES environment
# Language: Python 2.5
# Date: 23-Feb-2011.
# Ver: 23-Feb-2011.
# Author: Francisco Mendez Palma
# Copyright: 2011 - Francisco Mendez Palma <fmendezpalma @no-spam@ gmail.com>
#
# EnciendeEquipos is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# EnciendeEquipos is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
##############################################################################

from LdapConnection import LdapConnection
import NetworkUtils
import sys

# Capturo argumento para saber que ordenadores encender: Nocturno ("Noche") o Diurno (vacio)
if len (sys.argv)==2:
cuando=sys.argv[1]
else:
cuando="Dia"

#Conexion anonima: solo ip del ldap
l = LdapConnection("172.23.36.5")
l.connect()

#Segun momento del dia, encendemos distintos equipos
if cuando=="Noche":
filter="(|(cn=d-profesores*)(cn=a02-pro)(cn=a03-pro)(cn=a15-pro)(cn=a16-pro)(cn=a17-pro)(cn=a18-pro)(cn=a32-pro)(cn=a33-pro)(cn=a34-pro)(cn=a35-pro))"
else:
filter="(|(cn=*-pro*)(cn=d-profesores*))"

search = l.search("ou=hosts",filter,["macAddress"])

#Obtenemos macs y lanzamos encendido
for elto in search:
mac=elto[0][1]["macAddress"][0]
NetworkUtils.startup(mac)