diff -r 57e8168ba8c4 -r 0f9cae2d7147 pvl/config/host.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pvl/config/host.py Sun Jul 12 00:51:08 2009 +0300 @@ -0,0 +1,60 @@ +""" + Information about one physica host +""" + +import dhcp +import bind_conf as bindc + +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) + + def build_bind_domain_records (self, origin) : + """ + Build and yield one or more forward records (A/AAAA) for the host, with the given domain as the origin + """ + + yield bindc.A(self.hostname, self.address) +