This patch ensures that entries are removed before being added to DHCP/ DNS

--- a/trunk/src/tashi/agents/dhcpdns.py Tue Jul 07 14:01:11 2009 -0400
+++ b/trunk/src/tashi/agents/dhcpdns.py Tue Jul 07 15:01:25 2009 -0400
@@ -100,6 +101,8 @@
                return ipString

        def addDhcp(self, name, ipaddr, hwaddr):
+                self.removeDhcp(name)
+                self.removeDhcp(name, ipaddr)
                cmd = "omshell"
                (stdin, stdout) = os.popen2(cmd)
                stdin.write("server %s\n" % (self.dhcpServer))
@@ -111,12 +114,12 @@
                stdin.write("set ip-address = %s\n" % (ipaddr))
                stdin.write("set hardware-address = %s\n" % (hwaddr))
stdin.write("set hardware-type = 00:00:00:01\n") # Ethernet
                stdin.write("create\n")
                stdin.close()
                output = stdout.read()
                stdout.close()

-       def removeDhcp(self, name):
+       def removeDhcp(self, name, ipaddr=None):
                cmd = "omshell"
                (stdin, stdout) = os.popen2(cmd)
                stdin.write("server %s\n" % (self.dhcpServer))
@@ -124,7 +128,10 @@
stdin.write("key %s %s\n" % (self.dhcpKeyName, self.dhcpSecretKey))
                stdin.write("connect\n")
                stdin.write("new \"host\"\n")
-               stdin.write("set name = \"%s\"\n" % (name))
+                if ipaddr==None:
+                        stdin.write("set name = \"%s\"\n" % (name))
+                else:
+                        stdin.write("set ip-address = %s\n"%(ipaddr))
                stdin.write("open\n")
                stdin.write("remove\n")
                stdin.close()
@@ -132,6 +141,7 @@
                stdout.close()

        def addDns(self, name, ip):
+                self.removeDns(name)
                if (self.dnsKeyFile != ""):
                        cmd = "nsupdate -k %s" % (self.dnsKeyFile)
                else:

Reply via email to