Our windows cluster compute nodes, unfortunately, don't have any entry appear in DHCP (don't sure why this's working all this time). I want to add more nodes, but all the old IP shouldn't be tempted. So I need a script to read in old IP+MAC entry and add it to reservation pool in DHCP. And here it is (Pyht
import os, sys, re
ip_entry = re.compile(r'\s*10\.2\.0.*', re.I | re.DOTALL)
arp_cmd = os.popen('arp -a', 'r')
ip_list = []
while True :
line = arp_cmd.readline()
if not line : break
line = line.strip()
if ip_entry.match(line) :
ip, mac, mode = line.split()
a, b, c, d = ip.split('.')
name = 'compute0%02d' % (int(d) - 1)
ip_list.append( (ip, mac.replace('-', ''), name) )
arp_cmd.close()
print ip_list
for ip in ip_list :
os.system('netsh dhcp server scope 10.0.0.0 add reservedip %s %s %s BOTH' % (ip[0], ip[1], ip[2]))
The key of script above are "arp -a" and "netsh dhcp server scope 10.0.0.0 add reservedip". It's advised to run "clusrun hostname" once so ARP get all MAC entry from every machines. Of course this will only works on "ready" compute nodes.
I tried to create the script using Windows Powershell but it seems too much for me. PowerShell concept is good, too good for me to think of everything as Object when I just want to parse string output from a command line.