index = info
@cherrypy.expose
+ @cherrypy.tools.mako(filename="/info.mako")
+ @cherrypy.tools.require_POST()
+ def modify(self, machine_id, **fields):
+ """Handler for modifying attributes of a machine."""
+ try:
+ modify_dict = modifyDict(cherrypy.request.login, cherrypy.request.state, machine_id, fields)
+ except InvalidInput, err:
+ result = None
+ machine = validation.Validate(cherrypy.request.login, cherrypy.request.state, machine_id=machine_id).machine
+ else:
+ machine = modify_dict['machine']
+ result = 'Success!'
+ err = None
+ info_dict = infoDict(cherrypy.request.login, cherrypy.request.state, machine)
+ info_dict['err'] = err
+ if err:
+ for field in fields.keys():
+ setattr(info_dict['defaults'], field, fields.get(field))
+ info_dict['result'] = result
+ return info_dict
+
+ @cherrypy.expose
@cherrypy.tools.mako(filename="/vnc.mako")
def vnc(self, machine_id):
"""VNC applet page.
autoinstall = ''
name = ''
description = ''
+ administrator = ''
type = 'linux-hvm'
def __init__(self, max_memory=None, max_disk=None, **kws):
data_dict['%s_size' % name] = "%0.1f GiB" % (disk.size / 1024.)
return disk_fields
-def modifyDict(username, state, fields):
+def modifyDict(username, state, machine_id, fields):
"""Modify a machine as specified by CGI arguments.
- Return a list of local variables for modify.tmpl.
+ Return a dict containing the machine that was modified.
"""
olddisk = {}
session.begin()
try:
- kws = dict([(kw, fields.getfirst(kw)) for kw in 'machine_id owner admin contact name description memory vmtype disksize'.split()])
+ kws = dict([(kw, fields.get(kw)) for kw in 'owner admin contact name description memory vmtype disksize'.split() if fields.get(kw)])
+ kws['machine_id'] = machine_id
validate = validation.Validate(username, state, **kws)
machine = validate.machine
oldname = machine.name
controls.resizeDisk(oldname, diskname, str(olddisk[diskname]))
if hasattr(validate, 'name'):
controls.renameMachine(machine, oldname, validate.name)
- return dict(user=username,
- command="modify",
- machine=machine)
+ return dict(machine=machine)
-def modify(username, state, path, fields):
- """Handler for modifying attributes of a machine."""
- try:
- modify_dict = modifyDict(username, state, fields)
- except InvalidInput, err:
- result = None
- machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine
- else:
- machine = modify_dict['machine']
- result = 'Success!'
- err = None
- info_dict = infoDict(username, state, machine)
- info_dict['err'] = err
- if err:
- for field in fields.keys():
- setattr(info_dict['defaults'], field, fields.getfirst(field))
- info_dict['result'] = result
- return templates.info(searchList=[info_dict])
def badOperation(u, s, p, e):
"""Function called when accessing an unknown URI."""
max_disk = validation.maxDisk(machine.owner, machine)
defaults = Defaults()
for name in 'machine_id name description administrator owner memory contact'.split():
- setattr(defaults, name, getattr(machine, name))
+ if getattr(machine, name):
+ setattr(defaults, name, getattr(machine, name))
defaults.type = machine.type.type_id
defaults.disk = "%0.2f" % (machine.disks[0].size/1024.)
checkpoint.checkpoint('Got defaults')
'hostname' : socket.getfqdn()}])
mapping = dict(
- modify=modify,
unauth=unauthFront)
def printHeaders(headers):