host.py
author Tero Marttila <terom@fixme.fi>
Thu, 02 Apr 2009 21:11:01 +0300
changeset 3 ff98fa9b84ce
parent 1 2223ade4f259
child 5 86b05c0ab5cd
permissions -rw-r--r--
implement comments properly
"""
    Information about one physica host
"""

import dhcp

class Interface (object) :
    """
        A physical interface for a host
    """

    def __init__ (self, mac_addr, name=None) :
        """
            @param name the short name of the interface (e.g. 'lan' or 'wlan'), or None for no suffix
            @param mac the physical-layer addr.MAC address
        """

        self.addr = mac_addr
        self.name = name

class Host (object) :
    """
        A host has a single address/name, an owner, and multiple interfaces
    """

    def __init__ (self, hostname, address, interfaces) :
        """
            @param hostname the short hostname, without the domain name component
            @param address the addr.IP address
            @param interfaces a list of zero or more Interface objects
        """

        self.hostname = hostname
        self.address = address
        self.interfaces = interfaces
    
    def build_dhcp_hosts (self) :
        """
            Build and yield a series of dhcp_conf.Host objects for this host.

            If the host does not have any interfaces defined, this doesn't yield anything
        """
        
        # XXX: do we want to ensure that the host names are unique?
        
        for iface in self.interfaces :
            # the DHCP hostname
            name = "%s%s" % (self.hostname, ('-%s' % (iface.name)) if iface.name else '')
            
            # build it
            yield dhcp.Host(name, iface.addr, self.address)