From eabe84bd3f3ea514893ec700d598a06c2418f37e Mon Sep 17 00:00:00 2001 From: Steven Valdez Date: Mon, 29 Apr 2013 21:43:24 -0400 Subject: [PATCH] More fixes to hanging query in cherrypy compat --- code/cache_acls.py | 4 ++-- code/controls.py | 4 ++-- code/templates/functions.mako | 4 ++-- code/validation.py | 12 ++++++------ debian/changelog | 6 ++++++ 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/code/cache_acls.py b/code/cache_acls.py index 3c3d11e..46e5c73 100755 --- a/code/cache_acls.py +++ b/code/cache_acls.py @@ -25,14 +25,14 @@ def refreshCache(): session.begin() try: - machines = Machine.query().all() + machines = Machine.query.all() for m in machines: refreshMachine(m) session.flush() # Update the admin ACL as well admin_acl = set(authz.expandAdmin(config.adminacl)) - old_admin_acl = set(a.user for a in Admin.query()) + old_admin_acl = set(a.user for a in Admin.query) for removed in old_admin_acl - admin_acl: old = Admin.query.filter_by(user=removed).first() session.delete(old) diff --git a/code/controls.py b/code/controls.py index 6346002..09367e2 100644 --- a/code/controls.py +++ b/code/controls.py @@ -113,7 +113,7 @@ def createVm(username, state, owner, contact, name, description, memory, disksiz session.save_or_update(machine) disk = Disk(machine=machine, guest_device_name='hda', size=disksize) - nic = NIC.query().filter_by(machine_id=None).filter_by(reusable=True).first() + nic = NIC.query.filter_by(machine_id=None).filter_by(reusable=True).first() if not nic: #No IPs left! raise CodeError("No IP addresses left! " "Contact %s." % config.contact) @@ -226,7 +226,7 @@ def commandResult(username, state, command_name, machine_id, fields): machine = validation.Validate(username, state, machine_id=machine_id).machine action = command_name cdrom = fields.get('cdrom') or None - if cdrom is not None and not CDROM.query().filter_by(cdrom_id=cdrom).one(): + if cdrom is not None and not CDROM.query.filter_by(cdrom_id=cdrom).one(): raise CodeError("Invalid cdrom type '%s'" % cdrom) if action not in "reboot create destroy shutdown delete".split(" "): raise CodeError("Invalid action '%s'" % action) diff --git a/code/templates/functions.mako b/code/templates/functions.mako index f5a9166..7b46a35 100644 --- a/code/templates/functions.mako +++ b/code/templates/functions.mako @@ -15,12 +15,12 @@ onchange="${onchange}"\ <%def name="cdromList(default='', onchange=None)"> -${databaseList(sorted(database.CDROM.query(), key=lambda x: x.description), +${databaseList(sorted(database.CDROM.query, key=lambda x: x.description), default, onchange, 'cdrom', 'cdromlist', 'cdrom_id', 'description')|n} <%def name="autoList(default='', onchange=None)"> -${databaseList(sorted(database.Autoinstall.query(), key=lambda x: x.description), +${databaseList(sorted(database.Autoinstall.query, key=lambda x: x.description), default, onchange, 'autoinstall', 'autoinstalllist', 'autoinstall_id', 'description')|n} diff --git a/code/validation.py b/code/validation.py index d288a69..18666be 100755 --- a/code/validation.py +++ b/code/validation.py @@ -57,13 +57,13 @@ class Validate: if vmtype is not None: self.vmtype = validVmType(vmtype) if cdrom is not None: - if not CDROM.query().get(cdrom): + if not CDROM.query.get(cdrom): raise CodeError("Invalid cdrom type '%s'" % cdrom) self.cdrom = cdrom if autoinstall is not None: #raise InvalidInput('autoinstall', 'install', # "The autoinstaller has been temporarily disabled") - self.autoinstall = Autoinstall.query().get(autoinstall) + self.autoinstall = Autoinstall.query.get(autoinstall) def getMachinesByOwner(owner, machine=None): @@ -74,7 +74,7 @@ def getMachinesByOwner(owner, machine=None): """ if machine: owner = machine.owner - return Machine.query().filter_by(owner=owner) + return Machine.query.filter_by(owner=owner) def maxMemory(owner, g, machine=None, on=True): """Return the maximum memory for a machine or a user. @@ -107,7 +107,7 @@ def maxDisk(owner, machine=None): machine_id = machine.machine_id else: machine_id = None - disk_usage = Disk.query().filter(Disk.c.machine_id != machine_id).\ + disk_usage = Disk.query.filter(Disk.c.machine_id != machine_id).\ join('machine').\ filter_by(owner=owner).sum(Disk.c.size) or 0 return min(quota_single, quota_total-disk_usage/1024.) @@ -181,7 +181,7 @@ def validDisk(owner, g, disk, machine=None): def validVmType(vm_type): if vm_type is None: return None - t = Type.query().get(vm_type) + t = Type.query.get(vm_type) if t is None: raise CodeError("Invalid vm type '%s'" % vm_type) return t @@ -198,7 +198,7 @@ def testMachineId(user, state, machine_id, exists=True): machine_id = int(machine_id) except ValueError: raise InvalidInput('machine_id', machine_id, "Must be an integer.") - machine = Machine.query().get(machine_id) + machine = Machine.query.get(machine_id) if exists and machine is None: raise InvalidInput('machine_id', machine_id, "Does not exist.") if machine is not None and not haveAccess(user, state, machine): diff --git a/debian/changelog b/debian/changelog index 69d5471..5dafef0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,6 +4,12 @@ invirt-web (0.1.31) unstable; urgency=low -- Peter A. Iannucci Mon, 20 May 2013 09:00:00 -0400 +invirt-web (0.1.31~dvorak425) precise; urgency=low + + * Fixing use of query() vs query on cherrypy. + + -- Steven Valdez Mon, 29 Apr 2013 21:43:31 -0400 + invirt-web (0.1.31~dvorak424) precise; urgency=low * Fixing cherrypy initialization for different versions. -- 1.7.9.5