# vim: set et sts=4 sw=4 encoding=utf-8 :
-from services import *
-from dispatcher import handler
+from pymin.services import *
+from pymin.dispatcher import handler
# XXX for testing only
@handler
--- /dev/null
+# vim: set encoding=utf-8 et sw=4 sts=4 :
+
+from pymin.pymindaemon import PyminDaemon
+
import signal
import socket
-import dispatcher
-import eventloop
-import serializer
+from pymin import eventloop
+from pymin import serializer
class PyminDaemon(eventloop.EventLoop):
r"""PyminDaemon(bind_addr, routes) -> PyminDaemon instance
# Create EventLoop
eventloop.EventLoop.__init__(self, sock)
# Create Dispatcher
- self.dispatcher = dispatcher.Dispatcher(routes)
+ self.dispatcher = Dispatcher(routes)
# Signal handling
def quit(signum, frame):
print "Shuting down ..."
# vim: set encoding=utf-8 et sw=4 sts=4 :
-import ucsv
-import seqtools
+from pymin import ucsv
+from pymin import seqtools
r"UTF-8 encoded CSV serializer."
--- /dev/null
+# vim: set encoding=utf-8 et sw=4 sts=4 :
+
+from pymin.services.dhcp import DhcpHandler
+from pymin.services.dns import DnsHandler
+from pymin.services.firewall import FirewallHandler
+from pymin.services.ip import IpHandler
+from pymin.services.proxy import ProxyHandler
+
from os import path
-from seqtools import Sequence
-from dispatcher import Handler, handler, HandlerError
-from services.util import Restorable, ConfigWriter
-from services.util import InitdHandler, TransactionalHandler, ParametersHandler
+from pymin.seqtools import Sequence
+from pymin.dispatcher import Handler, handler, HandlerError
+from pymin.services.util import Restorable, ConfigWriter, InitdHandler, \
+ TransactionalHandler, ParametersHandler
__ALL__ = ('DhcpHandler', 'Error', 'HostError', 'HostAlreadyExistsError',
'HostNotFoundError')
r"show() -> list of Hosts :: List all the complete hosts information."
return self.hosts.values()
+
class DhcpHandler(Restorable, ConfigWriter, InitdHandler, TransactionalHandler,
ParametersHandler):
r"""DhcpHandler([pickle_dir[, config_dir]]) -> DhcpHandler instance.
def _get_config_vars(self, config_file):
return dict(hosts=self.hosts.values(), **self.params)
+
if __name__ == '__main__':
import os
from os import unlink
from new import instancemethod
-from seqtools import Sequence
-from dispatcher import handler, HandlerError, Handler
-from services.util import Restorable, ConfigWriter, call
-from services.util import InitdHandler, TransactionalHandler, ParametersHandler
+from pymin.seqtools import Sequence
+from pymin.dispatcher import handler, HandlerError, Handler
+from pymin.services.util import Restorable, ConfigWriter, InitdHandler, \
+ TransactionalHandler, ParametersHandler, call
__ALL__ = ('DnsHandler', 'Error',
'ZoneError', 'ZoneNotFoundError', 'ZoneAlreadyExistsError',
r"Initialize the object. See class documentation for more info."
self.message = 'Zone error: "%s"' % zonename
-
class ZoneNotFoundError(ZoneError):
r"""
ZoneNotFoundError(hostname) -> ZoneNotFoundError instance
r"Initialize the object. See class documentation for more info."
self.message = 'zone not found: "%s"' % zonename
-
class ZoneAlreadyExistsError(ZoneError):
r"""
ZoneAlreadyExistsError(hostname) -> ZoneAlreadyExistsError instance
r"Initialize the object. See class documentation for more info."
self.message = 'Zone already exists: "%s"' % zonename
-
class HostError(Error, KeyError):
r"""
HostError(hostname) -> HostError instance
r"Initialize the object. See class documentation for more info."
self.message = 'Host not found: "%s"' % hostname
-
class MailExchangeError(Error, KeyError):
r"""
MailExchangeError(hostname) -> MailExchangeError instance
r"Initialize the object. See class documentation for more info."
self.message = 'Mail Exchange error: "%s"' % mx
-
class MailExchangeAlreadyExistsError(MailExchangeError):
r"""
MailExchangeAlreadyExistsError(hostname) -> MailExchangeAlreadyExistsError instance
r"Initialize the object. See class documentation for more info."
self.message = 'Mail Exchange already exists: "%s"' % mx
-
class MailExchangeNotFoundError(MailExchangeError):
r"""
MailExchangeNotFoundError(hostname) -> MailExchangeNotFoundError instance
r"Initialize the object. See class documentation for more info."
self.message = 'Mail Exchange not found: "%s"' % mx
-
-
class NameServerError(Error, KeyError):
r"""
NameServerError(ns) -> NameServerError instance
self.message = 'Mail Exchange not found: "%s"' % ns
-class ParameterError(Error, KeyError):
- r"""
- ParameterError(paramname) -> ParameterError instance
-
- This is the base exception for all DhcpHandler parameters related errors.
- """
-
- def __init__(self, paramname):
- r"Initialize the object. See class documentation for more info."
- self.message = 'Parameter error: "%s"' % paramname
-
-class ParameterNotFoundError(ParameterError):
- r"""
- ParameterNotFoundError(hostname) -> ParameterNotFoundError instance
-
- This exception is raised when trying to operate on a parameter that doesn't
- exists.
- """
-
- def __init__(self, paramname):
- r"Initialize the object. See class documentation for more info."
- self.message = 'Parameter not found: "%s"' % paramname
-
class Host(Sequence):
def __init__(self, name, ip):
self.name = name
def show(self):
return self.zones.values()
+
class DnsHandler(Restorable, ConfigWriter, InitdHandler, TransactionalHandler,
ParametersHandler):
r"""DnsHandler([pickle_dir[, config_dir]]) -> DnsHandler instance.
self.mod = False
self.reload()
+
if __name__ == '__main__':
dns = DnsHandler();
from os import path
-from seqtools import Sequence
-from dispatcher import Handler, handler, HandlerError
-from services.util import Restorable, ConfigWriter
-from services.util import ServiceHandler, TransactionalHandler
+from pymin.seqtools import Sequence
+from pymin.dispatcher import Handler, handler, HandlerError
+from pymin.services.util import Restorable, ConfigWriter, ServiceHandler, \
+ TransactionalHandler
__ALL__ = ('FirewallHandler', 'Error', 'RuleError', 'RuleAlreadyExistsError',
'RuleNotFoundError')
r"Initialize the object. See class documentation for more info."
self.message = 'Rule not found: "%s"' % rule
+
class Rule(Sequence):
r"""Rule(chain, target[, src[, dst[, ...]]]) -> Rule instance.
r"show() -> list of Rules :: List all the complete rules information."
return self.rules
+
class FirewallHandler(Restorable, ConfigWriter, ServiceHandler,
TransactionalHandler):
r"""FirewallHandler([pickle_dir[, config_dir]]) -> FirewallHandler instance.
def _get_config_vars(self, config_file):
return dict(rules=self.rules)
+
if __name__ == '__main__':
import os
from subprocess import Popen, PIPE
from os import path
-from seqtools import Sequence
-from dispatcher import handler, HandlerError, Handler
-from services.util import Restorable, ConfigWriter
-from services.util import InitdHandler, TransactionalHandler
+from pymin.seqtools import Sequence
+from pymin.dispatcher import handler, HandlerError, Handler
+from pymin.services.util import Restorable, ConfigWriter, InitdHandler, \
+ TransactionalHandler
-__ALL__ = ('IpHandler','Error','DeviceError','DeviceNotFoundError','RouteError','RouteNotFoundError',
- 'RouteAlreadyExistsError','AddressError','AddressNotFoundError','AddressAlreadyExistsError')
+__ALL__ = ('IpHandler', 'Error','DeviceError', 'DeviceNotFoundError',
+ 'RouteError', 'RouteNotFoundError', 'RouteAlreadyExistsError',
+ 'AddressError', 'AddressNotFoundError', 'AddressAlreadyExistsError')
class Error(HandlerError):
r"""
def __init__(self, route):
self.message = 'Route already exists : "%s"' % route
+
class Route(Sequence):
def __init__(self, net_addr, prefix, gateway):
k = list()
return k
+
class Address(Sequence):
def __init__(self, ip, prefix, broadcast):
k = list()
return k
+
class Device(Sequence):
def __init__(self, name, mac):
def show(self):
return self.devices.items()
+
def get_devices():
p = Popen(('ip', 'link', 'list'), stdout=PIPE, close_fds=True)
string = p.stdout.read()
from os import path
-from seqtools import Sequence
-from dispatcher import Handler, handler, HandlerError
-from services.util import Restorable, ConfigWriter
-from services.util import InitdHandler, TransactionalHandler, ParametersHandler
+from pymin.seqtools import Sequence
+from pymin.dispatcher import Handler, handler, HandlerError
+from pymin.services.util import Restorable, ConfigWriter, InitdHandler, \
+ TransactionalHandler, ParametersHandler
__ALL__ = ('ProxyHandler', 'Error', 'HostError', 'HostAlreadyExistsError',
- 'HostNotFoundError', 'ParameterError', 'ParameterNotFoundError')
+ 'HostNotFoundError')
class Error(HandlerError):
r"""
r"Initialize the object. See class documentation for more info."
self.message = 'Host not found: "%s"' % hostname
-class ParameterError(Error, KeyError):
- r"""
- ParameterError(paramname) -> ParameterError instance
-
- This is the base exception for all DhcpHandler parameters related errors.
- """
-
- def __init__(self, paramname):
- r"Initialize the object. See class documentation for more info."
- self.message = 'Parameter error: "%s"' % paramname
-
-class ParameterNotFoundError(ParameterError):
- r"""
- ParameterNotFoundError(hostname) -> ParameterNotFoundError instance
-
- This exception is raised when trying to operate on a parameter that doesn't
- exists.
- """
-
- def __init__(self, paramname):
- r"Initialize the object. See class documentation for more info."
- self.message = 'Parameter not found: "%s"' % paramname
class Host(Sequence):
except ImportError:
import pickle
-from dispatcher import Handler, handler, HandlerError
+from pymin.dispatcher import Handler, handler, HandlerError
#DEBUG = False
DEBUG = True
r"Initialize the object. See class documentation for more info."
self.message = 'Parameter not found: "%s"' % paramname
+
def call(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True, universal_newlines=True,
**kw):
for t in self._config_writer_files:
self._write_single_config(t)
+
class ServiceHandler(Handler):
r"""ServiceHandler([start[, stop[, restart[, reload]]]]) -> ServiceHandler.
#!/usr/bin/env python
# vim: set encoding=utf-8 et sw=4 sts=4 :
-from pymindaemon import PyminDaemon
+from pymin.pymindaemon import PyminDaemon
import config
PyminDaemon(config.routes, config.bind_addr).run()
+++ /dev/null
-# vim: set encoding=utf-8 et sw=4 sts=4 :
-
-from services.dhcp import DhcpHandler
-from services.dns import DnsHandler
-from services.firewall import FirewallHandler
-from services.ip import IpHandler
-from services.proxy import ProxyHandler
-