]> git.llucax.com Git - software/pymin.git/commitdiff
Merge jack2@192.168.7.8:src/pymin
authorLeandro Lucarella <llucax@gmail.com>
Sat, 27 Oct 2007 20:52:07 +0000 (17:52 -0300)
committerLeandro Lucarella <llucax@gmail.com>
Sat, 27 Oct 2007 20:52:07 +0000 (17:52 -0300)
config.py
pymin/services/ip/__init__.py
pymin/services/ppp/__init__.py
pymin/services/util.py

index 8e7715ed0e690d1ca00c99493ef41525c709874b..db3151b2f93a4125e33cacd519736e817a33a5a4 100644 (file)
--- a/config.py
+++ b/config.py
@@ -10,31 +10,45 @@ pickle_path = join(base_path, 'pickle')
 config_path = join(base_path, 'config')
 
 class Root(Handler):
-    ip = IpHandler(
-        pickle_dir = join(pickle_path, 'ip'),
-        config_dir = join(config_path, 'ip'))
+
     firewall = FirewallHandler(
         pickle_dir = join(pickle_path, 'firewall'),
-        config_dir = join(config_path, 'firewall'))
+        config_dir = '/tmp')
+
     nat = NatHandler(pickle_dir = join(pickle_path, 'nat'))
+
+    ppp = PppHandler(
+        pickle_dir = join(pickle_path, 'ppp'),
+        config_dir = {
+            'pap-secrets':  '/etc/ppp',
+            'chap-secrets': '/etc/ppp',
+            'options.X':    '/etc/ppp',
+            'nameX':        '/etc/ppp/peers',
+        })
+
+    ip = IpHandler(
+        pickle_dir = join(pickle_path, 'ip'),
+        config_dir = join(config_path, 'ip'))
+
     dns = DnsHandler(
         pickle_dir = join(pickle_path, 'dns'),
         config_dir = {
-            'named.conf': join(config_path, 'dns'),
-            'zoneX.zone': join(config_path, 'dns', 'zones'),
+            'named.conf': '/etc',
+            'zoneX.zone': '/var/lib/named',
         })
+
     dhcp = DhcpHandler(
         pickle_dir = join(pickle_path, 'dhcp'),
-        config_dir = join(config_path, 'dhcp'))
-    ppp = PppHandler(
-        pickle_dir = join(pickle_path, 'ppp'),
-        config_dir = join(config_path, 'ppp'))
-    vrrp = VrrpHandler(
-        pickle_dir = join(pickle_path, 'vrrp'),
-        config_dir = join(config_path, 'vrrp'))
+        config_dir = '/etc')
+
     proxy = ProxyHandler(
         pickle_dir = join(pickle_path, 'proxy'),
-        config_dir = join(config_path, 'proxy'))
+        config_dir = '/etc/squid')
+
+    vrrp = VrrpHandler(
+        pickle_dir = join(pickle_path, 'vrrp'),
+        config_dir = join(config_path, 'vrrp'),
+        pid_dir    = '/var/run')
 
 bind_addr = \
 (
index 7b5eafe698583518dc3c457948417ce7cffe549b..a6a0e676debb17b3aecb149e236181c2792daf72 100644 (file)
@@ -223,9 +223,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 2115d65de3ec08a0b08b95d6917a0ed4dd246b07..a58e212da387d6b0b1687963b6752b947a5b02ba 100644 (file)
@@ -197,6 +197,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..abf30e9ce097956ecf0543b98461da6c4df5abc4 100644 (file)
@@ -12,8 +12,8 @@ except ImportError:
 from pymin.dispatcher import Handler, handler, HandlerError, \
                                 CommandNotFoundError
 
-#DEBUG = False
-DEBUG = True
+DEBUG = False
+#DEBUG = True
 
 __ALL__ = ('Error', 'ReturnNot0Error', 'ExecutionError', 'ItemError',
             'ItemAlreadyExistsError', 'ItemNotFoundError', 'ContainerError',
@@ -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,
@@ -177,6 +185,7 @@ def call(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
         print 'Executing command:', command
         return
     try:
+        print 'Executing command:', command
         r = subprocess.call(command, stdin=stdin, stdout=stdout, stderr=stderr,
                                 universal_newlines=universal_newlines,
                                 close_fds=close_fds, **kw)