host.py
changeset 1 2223ade4f259
child 5 86b05c0ab5cd
equal deleted inserted replaced
0:257003279747 1:2223ade4f259
       
     1 """
       
     2     Information about one physica host
       
     3 """
       
     4 
       
     5 import dhcp
       
     6 
       
     7 class Interface (object) :
       
     8     """
       
     9         A physical interface for a host
       
    10     """
       
    11 
       
    12     def __init__ (self, mac_addr, name=None) :
       
    13         """
       
    14             @param name the short name of the interface (e.g. 'lan' or 'wlan'), or None for no suffix
       
    15             @param mac the physical-layer addr.MAC address
       
    16         """
       
    17 
       
    18         self.addr = mac_addr
       
    19         self.name = name
       
    20 
       
    21 class Host (object) :
       
    22     """
       
    23         A host has a single address/name, an owner, and multiple interfaces
       
    24     """
       
    25 
       
    26     def __init__ (self, hostname, address, interfaces) :
       
    27         """
       
    28             @param hostname the short hostname, without the domain name component
       
    29             @param address the addr.IP address
       
    30             @param interfaces a list of zero or more Interface objects
       
    31         """
       
    32 
       
    33         self.hostname = hostname
       
    34         self.address = address
       
    35         self.interfaces = interfaces
       
    36     
       
    37     def build_dhcp_hosts (self) :
       
    38         """
       
    39             Build and yield a series of dhcp_conf.Host objects for this host.
       
    40 
       
    41             If the host does not have any interfaces defined, this doesn't yield anything
       
    42         """
       
    43         
       
    44         # XXX: do we want to ensure that the host names are unique?
       
    45         
       
    46         for iface in self.interfaces :
       
    47             # the DHCP hostname
       
    48             name = "%s%s" % (self.hostname, ('-%s' % (iface.name)) if iface.name else '')
       
    49             
       
    50             # build it
       
    51             yield dhcp.Host(name, iface.addr, self.address)
       
    52