diff --git a/src/hostinfo/dhcpd.py b/src/hostinfo/dhcpd.py index cb7be61634f0e914d6162548f8b07fce9c1ffbf5..13f48e639beb68a362ecbe2e638d05f24aa7d1bb 100755 --- a/src/hostinfo/dhcpd.py +++ b/src/hostinfo/dhcpd.py @@ -189,11 +189,14 @@ def emit_interface(tree, options, interface): subnet = dict(map(lambda d: (get_subnet(tree, d._parent), map(None, d._parent._dhcpserver_)), interface._ip_._dhcpserver_)) - result += 'shared-network "MAC(%s)" {' % interface.ethernet[0] - for sn,dhcp in map(lambda n: (n, subnet[n]), sorted(subnet)): - result += emit_network(tree, options, sn, dhcp).indent() + for ethernet in util.ethernets(interface.ethernet[0]): + result += 'shared-network "MAC(%s)" {' % ethernet + for sn,dhcp in map(lambda n: (n, subnet[n]), + sorted(subnet, key=lambda s: s.network[0])): + result += emit_network(tree, options, sn, dhcp).indent() + pass + result += "}" pass - result += "}" return result def emit_network(tree, options, subnet, dhcp): @@ -261,27 +264,26 @@ def emit_hosts(tree, options, networks, pxeboot=False): never = {} for ip in tree._host_._interface_._ip_: # Find all hosts that associated with this network - ethernet = ip.ethernet[0:] - if not ethernet: - continue - if pxeboot == 'only' and not bool(ip._pxeboot_): - continue - if ethernet.lower() != ethernet: - raise util.HostinfoException('%s not lower-case' % ethernet) - if ip.never[0]: - if match(util.address(ip.never[0])): - if not ethernet in never: - never[ethernet] = [] + for ethernet in util.ethernets(ip.ethernet[0:]): + if pxeboot == 'only' and not bool(ip._pxeboot_): + continue + if ethernet.lower() != ethernet: + raise util.HostinfoException('%s not lower-case' % ethernet) + if ip.never[0]: + if match(util.address(ip.never[0])): + if not ethernet in never: + never[ethernet] = [] + pass + never[ethernet].append(ip) pass - never[ethernet].append(ip) - pass - continue - if match(util.address(ip)): - if not ethernet in static: - static[ethernet] = [] - pass - static[ethernet].append(ip) - continue + continue + if match(util.address(ip)): + if not ethernet in static: + static[ethernet] = [] + pass + static[ethernet].append(ip) + continue + pass pass def by_name(ether_ip_dict): diff --git a/src/hostinfo/dhcpd_ipv6.py b/src/hostinfo/dhcpd_ipv6.py index 9d589eb21af955df12d349b86aee0a93e0c36d24..98b7f35c4f2f8537be6ecce5b29256e7f5bc3d1a 100755 --- a/src/hostinfo/dhcpd_ipv6.py +++ b/src/hostinfo/dhcpd_ipv6.py @@ -105,11 +105,13 @@ def emit_interface(tree, options, interface): result = util.StringArray() subnet = dict(map(lambda d: (get_subnet(tree, d._parent), d), interface._ipv6_._dhcpserver_)) - result += 'shared-network "MAC(%s)" {' % interface.ethernet[0] - for sn,dhcp in map(lambda n: (n, subnet[n]), sorted(subnet)): - result += emit_network(tree, options, sn, dhcp).indent() + for ethernet in util.ethernets(interface.ethernet[0]): + result += 'shared-network "MAC(%s)" {' % ethernet + for sn,dhcp in map(lambda n: (n, subnet[n]), sorted(subnet)): + result += emit_network(tree, options, sn, dhcp).indent() + pass + result += "}" pass - result += "}" return result def emit_network(tree, options, subnet, dhcp): @@ -171,25 +173,24 @@ def emit_hosts(tree, options, networks): never = {} for ip in tree._host_._interface_._ipv6_: # Find all hosts that associated with this network - ethernet = ip.ethernet[0:] - if not ethernet: - continue - if ethernet.lower() != ethernet: - raise util.HostinfoException('%s not lower-case' % ethernet) - if ip.never[0]: - if match(util.address(ip.never[0])): - if not ethernet in never: - never[ethernet] = [] + for ethernet in util.ethernets(ip.ethernet[0:]): + if ethernet.lower() != ethernet: + raise util.HostinfoException('%s not lower-case' % ethernet) + if ip.never[0]: + if match(util.address(ip.never[0])): + if not ethernet in never: + never[ethernet] = [] + pass + never[ethernet].append(ip) pass - never[ethernet].append(ip) - pass - continue - if match(util.address(ip)): - if not ethernet in static: - static[ethernet] = [] - pass - static[ethernet].append(ip) - continue + continue + if match(util.address(ip)): + if not ethernet in static: + static[ethernet] = [] + pass + static[ethernet].append(ip) + continue + pass pass def by_name(ether_ip_dict): diff --git a/src/hostinfo/ifconfig.py b/src/hostinfo/ifconfig.py index d713f1e6847a3cecccaf2e76317914cf0a88e160..636274878506f15b2997f0d9d57f5ea1703868bb 100755 --- a/src/hostinfo/ifconfig.py +++ b/src/hostinfo/ifconfig.py @@ -236,40 +236,42 @@ def generate_ifcfg(tree, interface): def generate(tree, host): result = [] for i in tree._host_._interface_: - if i._parent.name[0] != host or not device(i.ethernet[0]): - continue - device_name = device(i.ethernet[0]) - if i.bridge[0]: - config = '# Generated by %s\n' % (' '.join(sys.argv)) - config += 'DEVICE=%s\n' % i.bridge[0] - config += 'NAME=%s\n' % i.bridge[0] - config += 'ONBOOT=yes\n' - config += 'TYPE=Bridge\n' - config += 'STP=off\n' - config += get_nm_extra(i.bridge[0]) - config += generate_ifcfg(tree, i) - result.append(('ifcfg-%s' % i.bridge[0], config)) + for ethernet in util.ethernets(i.ethernet[0]): + if i._parent.name[0] != host or not device(ethernet): + continue + device_name = device(ethernet) + if i.bridge[0]: + config = '# Generated by %s\n' % (' '.join(sys.argv)) + config += 'DEVICE=%s\n' % i.bridge[0] + config += 'NAME=%s\n' % i.bridge[0] + config += 'ONBOOT=yes\n' + config += 'TYPE=Bridge\n' + config += 'STP=off\n' + config += get_nm_extra(i.bridge[0]) + config += generate_ifcfg(tree, i) + result.append(('ifcfg-%s' % i.bridge[0], config)) - config = '# Generated by %s\n' % (' '.join(sys.argv)) - config += 'DEVICE=%s\n' % device_name - config += 'NAME=%s\n' % device_name - config += 'HWADDR=%s\n' % i.ethernet[0].upper() - config += 'ONBOOT=yes\n' - config += 'TYPE=Ethernet\n' - config += 'BRIDGE=%s\n' % i.bridge[0] - config += get_nm_extra(device_name) - result.append(('ifcfg-%s' % device_name, config)) - pass - elif i.ethernet[0]: - config = '# Generated by %s\n' % (' '.join(sys.argv)) - config += 'DEVICE=%s\n' % device_name - config += 'NAME=%s\n' % device_name - config += 'HWADDR=%s\n' % i.ethernet[0].upper() - config += 'ONBOOT=yes\n' - config += 'TYPE=Ethernet\n' - config += get_nm_extra(device_name) - config += generate_ifcfg(tree, i) - result.append(('ifcfg-%s' % device_name, config)) + config = '# Generated by %s\n' % (' '.join(sys.argv)) + config += 'DEVICE=%s\n' % device_name + config += 'NAME=%s\n' % device_name + config += 'HWADDR=%s\n' % ethernet.upper() + config += 'ONBOOT=yes\n' + config += 'TYPE=Ethernet\n' + config += 'BRIDGE=%s\n' % i.bridge[0] + config += get_nm_extra(device_name) + result.append(('ifcfg-%s' % device_name, config)) + pass + else: + config = '# Generated by %s\n' % (' '.join(sys.argv)) + config += 'DEVICE=%s\n' % device_name + config += 'NAME=%s\n' % device_name + config += 'HWADDR=%s\n' % ethernet.upper() + config += 'ONBOOT=yes\n' + config += 'TYPE=Ethernet\n' + config += get_nm_extra(device_name) + config += generate_ifcfg(tree, i) + result.append(('ifcfg-%s' % device_name, config)) + pass pass pass return result diff --git a/src/hostinfo/pxelinux.py b/src/hostinfo/pxelinux.py index ce7de35a0034c9ee28dc040faaf0f1c16c362bda..986771b92702c19396debc1f381a34f1fe770d60 100755 --- a/src/hostinfo/pxelinux.py +++ b/src/hostinfo/pxelinux.py @@ -1,14 +1,17 @@ import sys import os from hostinfo.util import ntoa, aton +import hostinfo.util as util def generate(tree, dhcphost): result = [] for i in tree._host_._interface_: if i.ethernet[0] and i._kickstart_: - result.append(("01-" + i.ethernet[0].replace(':', '-'), - i.name[0:], - i._kickstart_[0].file[0])) + for ethernet in util.ethernets( i.ethernet[0]): + result.append(("01-" + ethernet.replace(':', '-'), + i.name[0:], + i._kickstart_[0].file[0])) + pass pass pass result.sort() diff --git a/src/hostinfo/util.py b/src/hostinfo/util.py index 9dc39dda5c65887e035fd47e4508aa1c3c6d12cb..4272c04e179501533d8b0bb0a258820ed0a8418b 100755 --- a/src/hostinfo/util.py +++ b/src/hostinfo/util.py @@ -29,6 +29,10 @@ def subnet(tree, addr): where=result) return result and result[0] or None +def ethernets(ether): + if ether == None: + return [] + return ether.split(',') def aton(addr): result = long(0) diff --git a/src/hostinfo/yp.py b/src/hostinfo/yp.py index 08fa695cd2642c39e6c57d0e040080e481080c16..cac7724f1c4c0ca609f242b4383d379e77f94345 100755 --- a/src/hostinfo/yp.py +++ b/src/hostinfo/yp.py @@ -32,17 +32,23 @@ def ethers(tree): result = "" host = {} for i in filter(lambda i: i.ethernet[0], tree._host_._interface_): - host[i.ethernet[0]] = set([ i.name[0:] ]) + for ethernet in util.ethernets(i.ethernet[0]): + host[ethernet] = set([ i.name[0:] ]) + pass for ip in filter(util.address, i._ip_): fqn = util.fqn(tree, ip) if fqn: - host[i.ethernet[0]].add(fqn[0:-1]) + for ethernet in util.ethernets(i.ethernet[0]): + host[ethernet].add(fqn[0:-1]) + pass pass pass for ipv6 in filter(util.address, i._ipv6_): fqn = util.fqn(tree, ipv6) if fqn: - host[i.ethernet[0]].add(fqn[0:-1]) + for ethernet in util.ethernets(i.ethernet[0]): + host[ethernet].add(fqn[0:-1]) + pass pass pass pass