+ def getMachines(self):
+ """Get the list of VMs in the database, clearing the cache if it's
+ older than 15 seconds"""
+ if time() - self.lasttime > 15:
+ self.lasttime = time()
+ sipb_xen_database.clear_cache()
+ return [machine.name for machine in sipb_xen_database.Machine.select()]
+
+ def getUid(self, machine_name):
+ """Calculate the UID of a machine-account, which is just machine_id+1000
+ """
+ return sipb_xen_database.Machine.get_by(name=machine_name).machine_id + 1000
+
+ def getK5login(self, machine_name):
+ """Build the ACL for a machine and turn it into a .k5login file
+ """
+ machine = sipb_xen_database.Machine.get_by(name=machine_name)
+ users = [acl.user for acl in machine.acl]
+ return "\n".join(map(self.userToPrinc, users) + [''])
+
+ def userToPrinc(self, user):
+ """Convert Kerberos v4-style names to v5-style and append a default
+ realm if none is specified
+ """
+ if '@' in user:
+ (princ, realm) = user.split('@')
+ else:
+ princ = user
+ realm = "ATHENA.MIT.EDU"
+
+ return princ.replace('.', '/') + '@' + realm
+