]> git.llucax.com Git - software/pymin.git/blobdiff - pymin/services/ip/__init__.py
replaces prints with calls
[software/pymin.git] / pymin / services / ip / __init__.py
index 4330eeb359b8cdb8a31d49295505c07a69d9d911..f699a0d7a1e00e88f6f9d94df359785acfc660c2 100644 (file)
@@ -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, \
 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',
 
 __ALL__ = ('IpHandler', 'Error','DeviceError', 'DeviceNotFoundError',
            'RouteError', 'RouteNotFoundError', 'RouteAlreadyExistsError',
@@ -21,53 +21,47 @@ class Error(HandlerError):
 
     message - A descriptive error message.
     """
 
     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):
 
 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):
 
 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):
 
 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):
 
 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):
 
 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):
 
 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):
 
 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):
 
 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):
 
 
 class Route(Sequence):
@@ -89,6 +83,8 @@ class Route(Sequence):
 
 class RouteHandler(Handler):
 
 
 class RouteHandler(Handler):
 
+    handler_help = u"Manage IP routes"
+
     def __init__(self, devices):
         self.devices = devices
 
     def __init__(self, devices):
         self.devices = devices
 
@@ -149,6 +145,8 @@ class Address(Sequence):
 
 class AddressHandler(Handler):
 
 
 class AddressHandler(Handler):
 
+    handler_help = u"Manage IP addresses"
+
     def __init__(self, devices):
         self.devices = devices
 
     def __init__(self, devices):
         self.devices = devices
 
@@ -204,6 +202,8 @@ class Device(Sequence):
 
 class DeviceHandler(Handler):
 
 
 class DeviceHandler(Handler):
 
+    handler_help = u"Manage network devices"
+
     def __init__(self, devices):
         # FIXME remove templates to execute commands
         from mako.template import Template
     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:
     @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:
         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)
 
         else:
             raise DeviceNotFoundError(name)
 
@@ -251,6 +251,8 @@ def get_devices():
 
 class IpHandler(Restorable, ConfigWriter, TransactionalHandler):
 
 
 class IpHandler(Restorable, ConfigWriter, TransactionalHandler):
 
+    handler_help = u"Manage IP devices, addresses and routes"
+
     _persistent_attrs = 'devices'
 
     _restorable_defaults = dict(devices=get_devices())
     _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():
     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():
             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,
                     )
                         dev = device.name,
                         addr = address.ip,
                         prefix = address.prefix,
                         broadcast = address.broadcast,
                     )
-                )
+                ), shell=True)
             for route in device.routes:
             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,
                     )
                         dev = device.name,
                         net_addr = route.net_addr,
                         prefix = route.prefix,
                         gateway = route.gateway,
                     )
-                )
+                ), shell=True)
 
 
 if __name__ == '__main__':
 
 
 if __name__ == '__main__':