2 # vim: set et sw=4 sts=4 :
8 for c in line.split('\t'):
9 r.append(c.strip('"\n'))
16 if line.startswith('"tabla de ruteo de '):
20 hosts[host]['ifaces'] = []
21 while line and line.strip() <> '"red"\t"ip"\t"mascara"\t"gateway"\t"interfaz"\t"metrica"':
22 if line.startswith('"'):
23 (iface, ip, mascara, broadcast, peer) = get_campos(line)[:5]
24 hosts[host]['ifaces'].append({
28 'broadcast': broadcast,
33 hosts[host]['rutas'] = []
34 while line and line.strip() <> '"--"':
35 if line.startswith('"'):
36 (red, ip, mascara, gateway, iface, metrica) = get_campos(line)
37 if not metrica: metrica = "1"
38 hosts[host]['rutas'].append({
53 for iface in hosts[host]['ifaces']:
54 if iface['iface'].startswith('ppp'):
55 if host == 'h131' or host == 'h118':
56 print 'UP: pppd -detach modem crtscts lock %(ip)s:%(peer)s /dev/ttyS0 9600' % iface
57 os.system('pppd -detach modem crtscts lock %(ip)s:%(peer)s /dev/ttyS0 9600 &' % iface)
59 print 'UP: pppd -detach crtscts lock %(ip)s:%(peer)s /dev/ttyS0' % iface
60 os.system('pppd -detach crtscts lock %(ip)s:%(peer)s /dev/ttyS0 &' % iface)
63 print 'UP: ifconfig %(iface)s %(ip)s broadcast %(broadcast)s netmask %(mascara)s' % iface
64 os.system('ifconfig %(iface)s %(ip)s broadcast %(broadcast)s netmask %(mascara)s' % iface)
66 print 'while sleep 1; do if ping -c1 %(peer)s 2>&1 > /dev/null; then break; else echo Esperando link ppp...; fi; done' % iface
67 os.system('while sleep 1; do if ping -c1 %(peer)s 2>&1 > /dev/null; then break; else echo Esperando link ppp...; fi; done' % iface)
68 for ruta in hosts[host]['rutas']:
69 if ruta['metrica'] <> "0":
70 print 'UP: route add -net %(ip)s gw %(gateway)s netmask %(mascara)s dev %(iface)s metric %(metrica)s' % ruta
71 os.system('route add -net %(ip)s gw %(gateway)s netmask %(mascara)s dev %(iface)s metric %(metrica)s' % ruta)
72 os.system('cp /etc/hosts /etc/hosts.13.bak')
73 os.system('cp hosts /etc/hosts')
74 os.system('cp /etc/networks /etc/networks.13.bak')
75 os.system('cp networks /etc/networks')
79 for iface in hosts[host]['ifaces']:
80 print 'DOWN: ifconfig %(iface)s down' % iface
81 if iface['iface'].startswith('ppp'):
82 os.system('killall pppd')
84 os.system('ifconfig %(iface)s down' % iface)
85 os.system('mv /etc/hosts.13.bak /etc/hosts')
86 os.system('mv /etc/networks.13.bak /etc/networks')
90 for host in hosts.keys():
93 if __name__ == '__main__':
94 fd = file('routers_labo.csv')
96 print >>sys.stderr, 'Uso: %s [up|down] host' % sys.argv[0]
98 if sys.argv[1] == 'up':
100 elif sys.argv[1] == 'down':
101 down(sys.argv[2], fd)
102 elif sys.argv[1] == 'restart':
103 down(sys.argv[2], fd)
104 up(sys.argv[2], file('routers_labo.csv'))
105 elif sys.argv[1] == 'list':