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