]> git.llucax.com Git - software/pymin.git/commitdiff
Verificacion de interfaces usando handle_timer().
authorNicolas Emiliani <nemiliani@integratech.com.ar>
Thu, 25 Oct 2007 14:54:54 +0000 (11:54 -0300)
committerNicolas Emiliani <nemiliani@integratech.com.ar>
Thu, 25 Oct 2007 14:54:54 +0000 (11:54 -0300)
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.

pymin/services/ip/__init__.py
pymin/services/ppp/__init__.py
pymin/services/util.py

index 9d256a294ad3020c9ff6073cba7ce53569c84456..560e2f58747af7b498231ca132c5cc72aff726f6 100644 (file)
@@ -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')
index c251e5025a25f00c12f4106d7d970f52296bfa10..caf8f4ed1cd308f3b23525c81a75105dec6ef790 100644 (file)
@@ -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')
index a41882b6232b9a633dac4c1c0667018d85eb0876..6e09148f864f471157a11de5bbf225945ffbce21 100644 (file)
@@ -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,