How to add support for a new distro/OS

How to add support for a new distro

Adding support for a new distro is relatively straightforward, it basically boils down to:

  • Inheriting from LinuxPlugin.
  • Implementing the is_valid method. This will return True if we are in the given OS/Distro and False otherwise. Usually you will just need to check for a well known file that your distro or OS ships with.
  • Implement the get_timezone method. This method returns a string with the timezone name (i.e. “Europe/Madrid”). Implementing this method is not strictly necessary, and Wader can start up without it, but your SMS dates will probably be off by some hours.

Lets have a look at the Fedora plugin:

from os.path import exists
import re

from twisted.internet.utils import getProcessValue

from wader.common.oses.linux import LinuxPlugin
from wader.common.utils import get_file_data


class FedoraBasedDistro(LinuxPlugin):
    """
    OSPlugin for Fedora-based distros
    """

    #XXX: Almost duplicated code with Suse plugin
    def get_timezone(self):
        timezone_re = re.compile('ZONE="(?P<tzname>[\w/]+)"')
        sysconf_clock_file = get_file_data('/etc/sysconfig/clock')
        search_dict = timezone_re.search(sysconf_clock_file).groupdict()
        return search_dict['tzname']

    def is_valid(self):
        paths = ['/etc/redhat-release', '/etc/fedora-release']
        return any(map(exists, paths))

    def update_dns_cache(self):
        if exists("/usr/sbin/nscd"):
            getProcessValue("/etc/init.d/nscd", ["condrestart"])
            getProcessValue("/etc/init.d/nscd", ["-i", "hosts"])


fedora = FedoraBasedDistro()

As we can see, the Fedora plugin just defines is_valid and provides an implementation for get_timezone.

How to add support for a new OS

Adding support for a new OS is not as easy as the previous point. You need to add a new os class to wader.common.oses with a working implementation for the following methods/objects:

  • get_iface_stats: Accepts just one parameter, the iface name, and returns a tuple with tx,rx bytes.
  • is_valid: Returns True if the plugin is valid in the context where is being run, otherwise returns False.
  • hw_manager: A instance of a class that implements the IHardwareManager interface.

Table Of Contents

Previous topic

How to add support for a new device

Next topic

Glossary

This Page