+ return Template(file="command.tmpl", searchList=[d, global_dict])
+
+def testAdmin(user, admin, machine):
+ if admin in (None, machine.administrator):
+ return None
+ if admin == user.username:
+ return admin
+ if getafsgroups.checkAfsGroup(user, admin, 'athena.mit.edu'):
+ return admin
+ if getafsgroups.checkAfsGroup(user, 'system:'+admin, 'athena.mit.edu'):
+ return 'system:'+admin
+ raise InvalidInput('admin', admin,
+ 'You must control the group you move it to')
+
+def testOwner(user, owner, machine):
+ if owner in (None, machine.owner):
+ return None
+ #XXX should you be able to transfer ownership if you don't already own it?
+ #if not owns(user, machine):
+ # raise InvalidInput('owner', owner, "You don't own this machine, so you can't transfer ownership")
+ value = getafsgroups.checkLockerOwner(user.username, owner, verbose=True)
+ if value == True:
+ return owner
+ raise InvalidInput('owner', owner, value)
+
+def testContact(user, contact, machine=None):
+ if contact in (None, machine.contact):
+ return None
+ if not re.match("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$", contact, re.I):
+ raise InvalidInput('contact', contact, "Not a valid email")
+ return contact
+
+def testDisk(user, disksize, machine=None):
+ return disksize
+
+def testName(user, name, machine=None):
+ if name in (None, machine.name):
+ return None
+ if not Machine.select_by(name=name):
+ return name
+ raise InvalidInput('name', name, "Already taken")
+
+def testHostname(user, hostname, machine):
+ for nic in machine.nics:
+ if hostname == nic.hostname:
+ return hostname
+ # check if doesn't already exist
+ if NIC.select_by(hostname=hostname):
+ raise InvalidInput('hostname', hostname,
+ "Already exists")
+ if not re.match("^[A-Z0-9-]{1,22}$", hostname, re.I):
+ raise InvalidInput('hostname', hostname, "Not a valid hostname; must only use number, letters, and dashes.")
+ return hostname
+