X-Git-Url: https://git.llucax.com/software/pymin.git/blobdiff_plain/296d853cc95fd5bef262248cfe21b507abd26a4f..a2d8b5d4befdcc9c61c7060c6ab5dda4adfd509a:/pymin/services/ip/__init__.py diff --git a/pymin/services/ip/__init__.py b/pymin/services/ip/__init__.py index 4330eeb..f699a0d 100644 --- a/pymin/services/ip/__init__.py +++ b/pymin/services/ip/__init__.py @@ -6,7 +6,7 @@ from os import path from pymin.seqtools import Sequence from pymin.dispatcher import handler, HandlerError, Handler from pymin.services.util import Restorable, ConfigWriter, InitdHandler, \ - TransactionalHandler + TransactionalHandler, call __ALL__ = ('IpHandler', 'Error','DeviceError', 'DeviceNotFoundError', 'RouteError', 'RouteNotFoundError', 'RouteAlreadyExistsError', @@ -21,53 +21,47 @@ class Error(HandlerError): message - A descriptive error message. """ - - def __init__(self, message): - r"Initialize the Error object. See class documentation for more info." - self.message = message - - def __str__(self): - return self.message + pass class DeviceError(Error): def __init__(self, device): - self.message = 'Device error : "%s"' % device + self.message = u'Device error : "%s"' % device class DeviceNotFoundError(DeviceError): def __init__(self, device): - self.message = 'Device not found : "%s"' % device + self.message = u'Device not found : "%s"' % device class AddressError(Error): def __init__(self, addr): - self.message = 'Address error : "%s"' % addr + self.message = u'Address error : "%s"' % addr class AddressNotFoundError(AddressError): def __init__(self, address): - self.message = 'Address not found : "%s"' % address + self.message = u'Address not found : "%s"' % address class AddressAlreadyExistsError(AddressError): def __init__(self, address): - self.message = 'Address already exists : "%s"' % address + self.message = u'Address already exists : "%s"' % address class RouteError(Error): def __init__(self, route): - self.message = 'Route error : "%s"' % route + self.message = u'Route error : "%s"' % route class RouteNotFoundError(RouteError): def __init__(self, route): - self.message = 'Route not found : "%s"' % route + self.message = u'Route not found : "%s"' % route class RouteAlreadyExistsError(RouteError): def __init__(self, route): - self.message = 'Route already exists : "%s"' % route + self.message = u'Route already exists : "%s"' % route class Route(Sequence): @@ -89,6 +83,8 @@ class Route(Sequence): class RouteHandler(Handler): + handler_help = u"Manage IP routes" + def __init__(self, devices): self.devices = devices @@ -149,6 +145,8 @@ class Address(Sequence): class AddressHandler(Handler): + handler_help = u"Manage IP addresses" + def __init__(self, devices): self.devices = devices @@ -204,6 +202,8 @@ class Device(Sequence): class DeviceHandler(Handler): + handler_help = u"Manage network devices" + def __init__(self, devices): # FIXME remove templates to execute commands from mako.template import Template @@ -215,14 +215,14 @@ class DeviceHandler(Handler): @handler(u'Bring the device up') def up(self, name): if name in self.devices: - print self.device_template.render(dev=name, action='up') + call(self.device_template.render(dev=name, action='up'), shell=True) else: raise DeviceNotFoundError(name) @handler(u'Bring the device down') def down(self, name): if name in self.devices: - print self.device_template.render(dev=name, action='down') + call(self.device_template.render(dev=name, action='down'), shell=True) else: raise DeviceNotFoundError(name) @@ -251,6 +251,8 @@ def get_devices(): class IpHandler(Restorable, ConfigWriter, TransactionalHandler): + handler_help = u"Manage IP devices, addresses and routes" + _persistent_attrs = 'devices' _restorable_defaults = dict(devices=get_devices()) @@ -272,24 +274,24 @@ class IpHandler(Restorable, ConfigWriter, TransactionalHandler): def _write_config(self): r"_write_config() -> None :: Execute all commands." for device in self.devices.values(): - print self._render_config('route_flush', dict(dev=device.name)) - print self._render_config('ip_flush', dict(dev=device.name)) + call(self._render_config('route_flush', dict(dev=device.name)), shell=True) + call(self._render_config('ip_flush', dict(dev=device.name)), shell=True) for address in device.addrs.values(): - print self._render_config('ip_add', dict( + call(self._render_config('ip_add', dict( dev = device.name, addr = address.ip, prefix = address.prefix, broadcast = address.broadcast, ) - ) + ), shell=True) for route in device.routes: - print self._render_config('route_add', dict( + call(self._render_config('route_add', dict( dev = device.name, net_addr = route.net_addr, prefix = route.prefix, gateway = route.gateway, ) - ) + ), shell=True) if __name__ == '__main__':