diff -r 257003279747 -r 2223ade4f259 host.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host.py Thu Apr 02 20:19:18 2009 +0300 @@ -0,0 +1,52 @@ +""" + 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) +