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 print 'UP: pppd -detach crtscts lock %(ip)s:%(peer)s /dev/ttyS0' % iface
56 os.system('pppd -detach crtscts lock %(ip)s:%(peer)s /dev/ttyS0 &' % iface)
59 print 'UP: ifconfig %(iface)s %(ip)s broadcast %(broadcast)s netmask %(mascara)s' % iface
60 os.system('ifconfig %(iface)s %(ip)s broadcast %(broadcast)s netmask %(mascara)s' % iface)
62 print 'while sleep 1; do if ping -c1 %(peer)s 2>&1 > /dev/null; then break; else echo Esperando link ppp...; fi; done' % iface
63 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)
64 for ruta in hosts[host]['rutas']:
65 if ruta['metrica'] <> "0":
66 print 'UP: route add -net %(ip)s gw %(gateway)s netmask %(mascara)s dev %(iface)s metric %(metrica)s' % ruta
67 os.system('route add -net %(ip)s gw %(gateway)s netmask %(mascara)s dev %(iface)s metric %(metrica)s' % ruta)
68 os.system('cp /etc/hosts /etc/hosts.13.bak')
69 os.system('cp hosts /etc/hosts')
70 os.system('cp /etc/networks /etc/networks.13.bak')
71 os.system('cp networks /etc/networks')
75 for iface in hosts[host]['ifaces']:
76 print 'DOWN: ifconfig %(iface)s down' % iface
77 if iface['iface'].startswith('ppp'):
78 os.system('killall pppd')
80 os.system('ifconfig %(iface)s down' % iface)
81 os.system('mv /etc/hosts.13.bak /etc/hosts')
82 os.system('mv /etc/networks.13.bak /etc/networks')
86 for host in hosts.keys():
89 if __name__ == '__main__':
90 fd = file('routers_labo.csv')
92 print >>sys.stderr, 'Uso: %s [up|down] host' % sys.argv[0]
94 if sys.argv[1] == 'up':
96 elif sys.argv[1] == 'down':
98 elif sys.argv[1] == 'restart':
100 up(sys.argv[2], file('routers_labo.csv'))
101 elif sys.argv[1] == 'list':