Changeset 1013 for trunk/packages
- Timestamp:
- Oct 3, 2008, 7:26:43 PM (16 years ago)
- Location:
- trunk/packages/sipb-xen-www/code
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/sipb-xen-www/code/cache_acls.py
r879 r1013 46 46 for removed in old_people - people: 47 47 ma = [x for x in m.acl if x.user == removed][0] 48 ctx.current.delete(ma)48 session.delete(ma) 49 49 for p in people - old_people: 50 50 ma = MachineAccess(user=p) 51 51 m.acl.append(ma) 52 ctx.current.save(ma)52 session.save_or_update(ma) 53 53 54 54 def refreshCache(): 55 transaction = ctx.current.create_transaction()55 session.begin() 56 56 57 57 try: … … 59 59 for m in machines: 60 60 refreshMachine(m) 61 ctx.current.flush()61 session.flush() 62 62 63 63 # Atomically execute our changes 64 transaction.commit()64 session.commit() 65 65 except: 66 66 # Failed! Rollback all the changes. 67 transaction.rollback()67 session.rollback() 68 68 raise 69 69 -
trunk/packages/sipb-xen-www/code/controls.py
r1001 r1013 110 110 """Create a VM and put it in the database""" 111 111 # put stuff in the table 112 transaction = ctx.current.create_transaction()112 session.begin() 113 113 try: 114 114 validation.Validate(username, state, name=name, description=description, owner=owner, memory=memory, disksize=disksize/1024.) 115 res = meta.engine.execute('select nextval('116 '\'"machines_machine_id_seq"\')')117 id = res.fetchone()[0]118 115 machine = Machine() 119 machine.machine_id = id120 116 machine.name = name 121 117 machine.description = description … … 126 122 machine.uuid = uuidToString(randomUUID()) 127 123 machine.boot_off_cd = True 128 machine.type _id = machine_type.type_id129 ctx.current.save(machine)130 disk = Disk(machine _id=machine.machine_id,124 machine.type = machine_type 125 session.save_or_update(machine) 126 disk = Disk(machine=machine, 131 127 guest_device_name='hda', size=disksize) 132 open_nics = NIC.select_by(machine_id=None)133 if not open_nics: #No IPs left!128 nic = NIC.query().filter_by(machine_id=None).first() 129 if not nic: #No IPs left! 134 130 raise CodeError("No IP addresses left! " 135 131 "Contact %s." % config.web.errormail) 136 nic = open_nics[0] 137 nic.machine_id = machine.machine_id 132 nic.machine = machine 138 133 nic.hostname = name 139 ctx.current.save(nic)140 ctx.current.save(disk)134 session.save_or_update(nic) 135 session.save_or_update(disk) 141 136 cache_acls.refreshMachine(machine) 142 transaction.commit()137 session.commit() 143 138 except: 144 transaction.rollback()139 session.rollback() 145 140 raise 146 141 makeDisks(machine) … … 209 204 """Delete a VM.""" 210 205 remctl('control', machine.name, 'destroy', err=True) 211 transaction = ctx.current.create_transaction()206 session.begin() 212 207 delete_disk_pairs = [(machine.name, d.guest_device_name) 213 208 for d in machine.disks] 214 209 try: 210 for mname, dname in delete_disk_pairs: 211 remctl('web', 'lvremove', mname, dname) 215 212 for nic in machine.nics: 216 213 nic.machine_id = None 217 214 nic.hostname = None 218 ctx.current.save(nic)215 session.save_or_update(nic) 219 216 for disk in machine.disks: 220 ctx.current.delete(disk)221 ctx.current.delete(machine)222 transaction.commit()217 session.delete(disk) 218 session.delete(machine) 219 session.commit() 223 220 except: 224 transaction.rollback()221 session.rollback() 225 222 raise 226 for mname, dname in delete_disk_pairs:227 remctl('web', 'lvremove', mname, dname)228 223 229 224 def commandResult(username, state, fields): -
trunk/packages/sipb-xen-www/code/main.py
r1001 r1013 362 362 """ 363 363 olddisk = {} 364 transaction = ctx.current.create_transaction()364 session.begin() 365 365 try: 366 366 kws = dict([(kw, fields.getfirst(kw)) for kw in 'machine_id owner admin contact name description memory vmtype disksize'.split()]) … … 381 381 olddisk[disk.guest_device_name] = disksize 382 382 disk.size = disksize 383 ctx.current.save(disk)383 session.save_or_update(disk) 384 384 385 385 update_acl = False … … 397 397 machine.contact = validate.contact 398 398 399 ctx.current.save(machine)399 session.save_or_update(machine) 400 400 if update_acl: 401 401 print >> sys.stderr, machine, machine.administrator 402 402 cache_acls.refreshMachine(machine) 403 transaction.commit()403 session.commit() 404 404 except: 405 transaction.rollback()405 session.rollback() 406 406 raise 407 407 for diskname in olddisk: … … 654 654 errorMessage=str(err), stderr=emsg, traceback=traceback) 655 655 details = templates.error_raw(searchList=[d]) 656 if username not in config.web.errormail_exclude:656 if False: #username not in config.web.errormail_exclude: 657 657 send_error_mail('xvm error on %s for %s: %s' % (op, username, err), 658 658 details) -
trunk/packages/sipb-xen-www/code/validation.py
r1001 r1013 64 64 self.vmtype = validVmType(vmtype) 65 65 if cdrom is not None: 66 if not CDROM. get(cdrom):66 if not CDROM.query().get(cdrom): 67 67 raise CodeError("Invalid cdrom type '%s'" % cdrom) 68 68 self.cdrom = cdrom 69 69 if autoinstall is not None: 70 self.autoinstall = Autoinstall. get(autoinstall)70 self.autoinstall = Autoinstall.query().get(autoinstall) 71 71 72 72 … … 184 184 if vm_type is None: 185 185 return None 186 t = Type. get(vm_type)186 t = Type.query().get(vm_type) 187 187 if t is None: 188 188 raise CodeError("Invalid vm type '%s'" % vm_type) … … 201 201 except ValueError: 202 202 raise InvalidInput('machine_id', machine_id, "Must be an integer.") 203 machine = Machine. get(machine_id)203 machine = Machine.query().get(machine_id) 204 204 if exists and machine is None: 205 205 raise InvalidInput('machine_id', machine_id, "Does not exist.") … … 271 271 if machine is not None and name == machine.name: 272 272 return None 273 if not Machine.query().filter_by(name=name) :273 if not Machine.query().filter_by(name=name).count(): 274 274 if not validMachineName(name): 275 275 raise InvalidInput('name', name, 'You must provide a machine name. Max 63 chars, alnum plus \'-\', does not begin or end with \'-\'.')
Note: See TracChangeset
for help on using the changeset viewer.