@@ -42,25 +42,36 @@ def renew_ip(starrs, addr):
4242 return results
4343
4444
45+ # Use various STARRS stored procedures to make sure the hostname is valid/available
4546def check_hostname (starrs , hostname ):
4647 c = starrs .cursor ()
4748 try :
49+ # Check for invalid characters in hostname
4850 c .execute ("BEGIN" )
4951 c .callproc ("api.initialize" , ('root' , ))
5052 c .callproc ("api.validate_name" , (hostname , ))
5153 c .execute ("COMMIT" )
54+ # Validate the entire domain name using Data::Validate::Domain
5255 c .execute ("BEGIN" )
5356 c .callproc ("api.initialize" , ('root' , ))
5457 c .callproc ("api.validate_domain" , (hostname , 'csh.rit.edu' ))
5558 valid = c .fetchall ()[0 ][0 ]
5659 c .execute ("COMMIT" )
60+ # Check if the hostname is available (checks A/SRV/CNAME records)
5761 c .execute ("BEGIN" )
5862 c .callproc ("api.initialize" , ('root' , ))
5963 c .callproc ("api.check_dns_hostname" , (hostname , 'csh.rit.edu' ))
6064 available = False
6165 if not c .fetchall ()[0 ][0 ]:
6266 available = True
6367 c .execute ("COMMIT" )
68+ # Check if the system name is taken
69+ c .execute ("BEGIN" )
70+ c .callproc ("api.initialize" , ('root' , ))
71+ c .callproc ("api.get_system" , (hostname , ))
72+ if c .fetchall ():
73+ available = False
74+ c .execute ("COMMIT" )
6475 except (psycopg2 .InternalError ):
6576 valid = False
6677 available = False
0 commit comments