- print >> sys.stderr, time.time()-start_time
- machine = testMachineId(user, fields.getfirst('machine_id'))
- action = fields.getfirst('action')
- cdrom = fields.getfirst('cdrom')
- print >> sys.stderr, time.time()-start_time
- if cdrom is not None and not CDROM.get(cdrom):
- raise CodeError("Invalid cdrom type '%s'" % cdrom)
- if action not in ('Reboot', 'Power on', 'Power off', 'Shutdown', 'Delete VM'):
- raise CodeError("Invalid action '%s'" % action)
- if action == 'Reboot':
- if cdrom is not None:
- remctl('reboot', machine.name, cdrom)
- else:
- remctl('reboot', machine.name)
- elif action == 'Power on':
- if maxMemory(user) < machine.memory:
- raise InvalidInput('action', 'Power on',
- "You don't have enough free RAM quota to turn on this machine")
- bootMachine(machine, cdrom)
- elif action == 'Power off':
- remctl('destroy', machine.name)
- elif action == 'Shutdown':
- remctl('shutdown', machine.name)
- elif action == 'Delete VM':
- deleteVM(machine)
- print >> sys.stderr, time.time()-start_time
-
- d = dict(user=user,
- command=action,
- machine=machine)
- 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
-
-def modify(user, fields):
- """Handler for modifying attributes of a machine."""
+ back = fields.getfirst('back')
+ try:
+ d = controls.commandResult(user, fields)
+ if d['command'] == 'Delete VM':
+ back = 'list'
+ except InvalidInput, err:
+ if not back:
+ raise
+ print >> sys.stderr, err
+ result = None
+ else:
+ result = 'Success!'
+ if not back:
+ return Template(file='command.tmpl', searchList=[d])
+ if back == 'list':
+ g.clear() #Changed global state
+ d = getListDict(user)
+ d['result'] = result
+ return Template(file='list.tmpl', searchList=[d])
+ elif back == 'info':
+ machine = validation.testMachineId(user, fields.getfirst('machine_id'))
+ d = infoDict(user, machine)
+ d['result'] = result
+ return Template(file='info.tmpl', searchList=[d])
+ else:
+ raise InvalidInput('back', back, 'Not a known back page.')