# maak rc.node.local from common import * def gen_rcnodelocal(node, version): if version == "5.0": rc = gen_header('rc.node.local') + """ hostname="%s" location="%s" """ % (node.name, node.location) lines = {} # interface naam -> ifconfig argumenten wdata ={} # /usr/local/sbin argumenten def addalias(iface, alias): if not lines.has_key(iface.iface): lines[iface.iface] = alias else: for i in range(100): t = "%s_alias%d" % (iface.iface, i) if not lines.has_key(t): lines[t] = alias break for link in node.links: alias = "inet %s/%s" % (showaddr(link.ip), link.mask) if is_a(link.iface, 'wireless'): extra = "-t 7 -P 0 -Z \\ \n -s %s \\ \n -n %s \\ \n -q %s \\ \n" % (link.iface.essid, link.iface.essid, link.iface.essid) if has_attr(link.iface, 'channel'): extra = extra + " -p 1 -c 1 -f %s" % (link.iface.channel) else: extra = extra + " -p 1" wdata[link.iface.iface] = extra addalias(link.iface, alias) lines = map(lambda x: "ifconfig_%s=\"%s\"" % x, lines.iteritems()) lines.sort() wdata = map(lambda x: "/usr/sbin/wicontrol -i %s %s" % x, wdata.iteritems()) wdata.sort() rc = rc + "\n".join(lines) + "\n\n\n" + "\n".join(wdata) return rc elif version == "5.3": rc = gen_header('rc.node.local') + """ hostname="%s" location="%s" """ % (node.name, node.location) lines = {} # interface naam -> ifconfig argumenten def addalias(iface, alias, extra): if not lines.has_key(iface.iface): lines[iface.iface] = alias + extra else: for i in range(100): t = "%s_alias%d" % (iface.iface, i) if not lines.has_key(t): lines[t] = alias break for link in node.links: alias = "inet %s/%s" % (showaddr(link.ip), link.mask) if is_a(link.iface, 'wireless'): extra = " -promisc -powersave ssid %s" % (link.iface.essid) if has_attr(link.iface, 'channel'): extra = extra + " mediaopt hostap channel %s" % (link.iface.channel) else: extra = '' addalias(link.iface, alias, extra) lines = map(lambda x: "ifconfig_%s=\"%s\"" % x, lines.iteritems()) lines.sort() rc = rc + "\n".join(lines) return rc if __name__ == "__main__": nodes = xml_to_obj_hierarchy(sys.argv[1]) ready_nodes_dtd_hierarchy(nodes) node = findnode(nodes, sys.argv[2]) print gen_rcnodelocal(node, sys.argv[3])