incubator-tashi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rg...@apache.org
Subject svn commit: r1152252 - in /incubator/tashi/branches/zoni-dev/trunk/src/zoni: agents/dhcpdns.py client/zoni-cli.py
Date Fri, 29 Jul 2011 15:00:19 GMT
Author: rgass
Date: Fri Jul 29 15:00:18 2011
New Revision: 1152252

URL: http://svn.apache.org/viewvc?rev=1152252&view=rev
Log:
Use gethostbyaddr in dhcpdns in case you enter the wrong option when adding cnames
Minor changes to the cli

Modified:
    incubator/tashi/branches/zoni-dev/trunk/src/zoni/agents/dhcpdns.py
    incubator/tashi/branches/zoni-dev/trunk/src/zoni/client/zoni-cli.py

Modified: incubator/tashi/branches/zoni-dev/trunk/src/zoni/agents/dhcpdns.py
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/zoni-dev/trunk/src/zoni/agents/dhcpdns.py?rev=1152252&r1=1152251&r2=1152252&view=diff
==============================================================================
--- incubator/tashi/branches/zoni-dev/trunk/src/zoni/agents/dhcpdns.py (original)
+++ incubator/tashi/branches/zoni-dev/trunk/src/zoni/agents/dhcpdns.py Fri Jul 29 15:00:18
2011
@@ -155,7 +155,8 @@ class DhcpDns():
 			stdin.write("update delete %s.%s A\n" % (name, self.dnsDomain))
 			stdin.write("\n")
 			if (self.reverseDns):
-				ip = socket.gethostbyname(name)
+				hostInfo = socket.gethostbyaddr(name)
+				ip = hostInfo[2]
 				ipSegments = map(int, ip.split("."))
 				ipSegments.reverse()
 				reverseIpStr = ("%d.%d.%d.%d.in-addr.arpa" % (ipSegments[0], ipSegments[1], ipSegments[2],
ipSegments[3]))
@@ -175,15 +176,20 @@ class DhcpDns():
 				(pid, status) = os.waitpid(child.pid, os.WNOHANG)
 
 	def addCname(self, name, origName):
+		
 		cmd = "nsupdate"
 		child = subprocess.Popen(args=cmd.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
 		try:
 			#  Check for existance of hostname
-			ip = socket.gethostbyname(origName)
+			#ip = socket.gethostbyname(origName)
+			#  add this to make sure we always input the textual name instead of the ip address by
mistake
+			hostInfo = socket.gethostbyaddr(origName)
+			hostName = hostInfo[0].split(".")[0]
+
 			(stdin, stdout) = (child.stdin, child.stdout)
 			stdin.write("server %s\n" % (self.dnsServer))
 			stdin.write("key %s %s\n" % (self.dnsKeyName, self.dnsSecretKey))
-			stdin.write("update add %s.%s %d CNAME %s.%s\n" % (name, self.dnsDomain, self.dnsExpire,
origName, self.dnsDomain))
+			stdin.write("update add %s.%s %d CNAME %s.%s\n" % (name, self.dnsDomain, self.dnsExpire,
hostName, self.dnsDomain))
 			stdin.write("\n")
 			stdin.close()
 			output = stdout.read()

Modified: incubator/tashi/branches/zoni-dev/trunk/src/zoni/client/zoni-cli.py
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/zoni-dev/trunk/src/zoni/client/zoni-cli.py?rev=1152252&r1=1152251&r2=1152252&view=diff
==============================================================================
--- incubator/tashi/branches/zoni-dev/trunk/src/zoni/client/zoni-cli.py (original)
+++ incubator/tashi/branches/zoni-dev/trunk/src/zoni/client/zoni-cli.py Fri Jul 29 15:00:18
2011
@@ -745,7 +745,7 @@ def main():
 		if options.addCname:
 			if len(args) < 2:
 				mesg = "ERROR:  Incorrect number of arguments\n"
-				mesg += "Example:  " + os.path.basename(sys.argv[0]) + " " + thisone + "cname existing_name"
+				mesg += "Example: %s %s cname existing_name" % (os.path.basename(sys.argv[0]), thisone)

 				print mesg
 				exit()
 			hostName = args[1]
@@ -755,10 +755,10 @@ def main():
 			dhcpdns = DhcpDns(configs, verbose=options.verbosity)
 			dhcpdns.addCname(cname, hostName)
 			if dhcpdns.error: 
-				mesg = "[FAIL]  \n" + str(dhcpdns.error) + "\n" 
+				mesg = "[FAIL]  \n %s\n" % str(dhcpdns.error)
 				sys.stdout.write(mesg) 
 			else: 
-				mesg = "[SUCCESS]" + "\n" 
+				mesg = "[SUCCESS]\n"
 				sys.stdout.write(mesg) 
 
 if __name__ == "__main__":



Mime
View raw message