import getafsgroups
import re
import string
+import dns.resolver
from invirt.database import Machine, NIC, Type, Disk, CDROM, Autoinstall
from invirt.config import structs as config
from webcommon import InvalidInput
name = name.lower()
if machine is not None and name == machine.name:
return None
- if not Machine.query().filter_by(name=name).count():
+ try:
+ f = open('/tmp/log', 'a')
+ dns.resolver.query('%s.%s.' % (name, config.dns.domains[0]), 'A')
+ # If the hostname didn't exist, it would have thrown an
+ # exception by now - error out
+ raise InvalidInput('name', name, 'Name is already taken.')
+ except dns.resolver.NXDOMAIN, e:
if not validMachineName(name):
raise InvalidInput('name', name, 'You must provide a machine name. Max 63 chars, alnum plus \'-\', does not begin or end with \'-\'.')
return name
- raise InvalidInput('name', name, "Name is already taken.")
+ except InvalidInput:
+ raise
+ except:
+ # Any other error is a validation failure
+ raise InvalidInput('name', name, 'We were unable to verify that this name is available. If you believe this is in error, please contact us at %s' % config.dns.contact)
def testDescription(user, description, machine=None):
if description is None or description.strip() == '':