From: Nicolas Emiliani Date: Thu, 25 Oct 2007 14:54:54 +0000 (-0300) Subject: Verificacion de interfaces usando handle_timer(). X-Git-Url: https://git.llucax.com/software/pymin.git/commitdiff_plain/0052c50443c26499dee9ae085d138c237ebe25d8?ds=sidebyside;hp=--cc Verificacion de interfaces usando handle_timer(). En util.py se corrige get_network_devices para que levante los link/ppp. En ip/__init__.py se agrega refresh_devices para que a travez del handle_timer se puedan agregar los devices que se registran a travez del commando ppp y tambien se borren los devices caidos. --- 0052c50443c26499dee9ae085d138c237ebe25d8 diff --git a/pymin/services/ip/__init__.py b/pymin/services/ip/__init__.py index 9d256a2..560e2f5 100644 --- a/pymin/services/ip/__init__.py +++ b/pymin/services/ip/__init__.py @@ -226,9 +226,26 @@ class IpHandler(Restorable, ConfigWriter, TransactionalHandler): ), shell=True) + def handle_timer(self): + self.refresh_devices() + + + def refresh_devices(self): + devices = get_network_devices() + #add not registered devices + for k,v in devices.items(): + if k not in self.devices: + self.devices[k] = Device(k,v) + #delete dead devices + for k in self.devices.keys(): + if k not in devices: + del self.devices[k] + + + if __name__ == '__main__': - ip = IpHandler() + ip = IpHanlder() print '----------------------' ip.hop.add('201.21.32.53','eth0') ip.hop.add('205.65.65.25','eth1') diff --git a/pymin/services/ppp/__init__.py b/pymin/services/ppp/__init__.py index c251e50..caf8f4e 100644 --- a/pymin/services/ppp/__init__.py +++ b/pymin/services/ppp/__init__.py @@ -186,6 +186,7 @@ class PppHandler(Restorable, ConfigWriter, ReloadHandler, TransactionalHandler): if __name__ == '__main__': + p = PppHandler() p.conn.add('ppp_c','nico','nico',type='PPP',device='tty0') p.conn.add('pppoe_c','fede','fede',type='OE',device='tty1') diff --git a/pymin/services/util.py b/pymin/services/util.py index a41882b..6e09148 100644 --- a/pymin/services/util.py +++ b/pymin/services/util.py @@ -154,18 +154,26 @@ class ContainerNotFoundError(ContainerError): def get_network_devices(): - p = subprocess.Popen(('ip', 'link', 'list'), stdout=subprocess.PIPE, + p = subprocess.Popen(('ip', '-o', 'link'), stdout=subprocess.PIPE, close_fds=True) string = p.stdout.read() p.wait() d = dict() - i = string.find('eth') - while i != -1: - eth = string[i:i+4] - m = string.find('link/ether', i+4) - mac = string[ m+11 : m+11+17] - d[eth] = mac - i = string.find('eth', m+11+17) + devices = string.splitlines() + for dev in devices: + mac = '' + if dev.find('link/ether') != -1: + i = dev.find('link/ether') + mac = dev[i+11 : i+11+17] + i = dev.find(':',2) + name = dev[3: i] + d[name] = mac + elif dev.find('link/ppp') != -1: + i = dev.find('link/ppp') + mac = '00:00:00:00:00:00' + i = dev.find(':',2) + name = dev[3 : i] + d[name] = mac return d def call(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,