From: Leandro Lucarella Date: Sat, 27 Oct 2007 20:52:07 +0000 (-0300) Subject: Merge jack2@192.168.7.8:src/pymin X-Git-Url: https://git.llucax.com/software/pymin.git/commitdiff_plain/28ba753ea84e470b67de6601b15ebeb39ba0b97f?hp=9a8d314470c4fa1f0fb347470983365853d663d4 Merge jack2@192.168.7.8:src/pymin --- diff --git a/config.py b/config.py index 8e7715e..db3151b 100644 --- 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 = \ ( diff --git a/pymin/services/ip/__init__.py b/pymin/services/ip/__init__.py index 7b5eafe..a6a0e67 100644 --- a/pymin/services/ip/__init__.py +++ b/pymin/services/ip/__init__.py @@ -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') diff --git a/pymin/services/ppp/__init__.py b/pymin/services/ppp/__init__.py index 2115d65..a58e212 100644 --- a/pymin/services/ppp/__init__.py +++ b/pymin/services/ppp/__init__.py @@ -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') diff --git a/pymin/services/util.py b/pymin/services/util.py index a41882b..abf30e9 100644 --- a/pymin/services/util.py +++ b/pymin/services/util.py @@ -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)