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 = \
(
), 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')
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')
from pymin.dispatcher import Handler, handler, HandlerError, \
CommandNotFoundError
-#DEBUG = False
-DEBUG = True
+DEBUG = False
+#DEBUG = True
__ALL__ = ('Error', 'ReturnNot0Error', 'ExecutionError', 'ItemError',
'ItemAlreadyExistsError', 'ItemNotFoundError', '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,
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)