svn path=/trunk/web/; revision=134
--- /dev/null
+#from skeleton import skeleton
+#extends skeleton
+
+#def title
+$command $machine.name
+#end def
+
+
+#def body
+<h1>Command succesful</h1>
+<p>$command ${machine.name} was successful.</p>
+#if $command == "Delete VM"
+<p><a href="list">Return</a></p>
+#else
+<p><a href="info?machine_id=${machine.machine_id}">Return</a></p>
+#end if
+#end def
#else
<p>Odd... no error, but no machine.</p>
#end if
#else
<p>Odd... no error, but no machine.</p>
#end if
+<p><a href="list">Return</a></p>
-def create(user, fields):
- name = fields.getfirst('name')
- if not validMachineName(name):
- raise MyException("Invalid name '%s'" % name)
- name = user.username + '_' + name.lower()
-
- if Machine.get_by(name=name):
- raise MyException("A machine named '%s' already exists" % name)
-
- memory = fields.getfirst('memory')
+def validMemory(user, memory, machine=None):
try:
memory = int(memory)
if memory <= 0:
raise ValueError
except ValueError:
raise MyException("Invalid memory amount")
try:
memory = int(memory)
if memory <= 0:
raise ValueError
except ValueError:
raise MyException("Invalid memory amount")
- if memory > maxMemory(user):
+ if memory > maxMemory(user, machine):
raise MyException("Too much memory requested")
raise MyException("Too much memory requested")
-
- disk = fields.getfirst('disk')
+ return memory
+
+def validDisk(user, disk, machine=None):
- if disk > maxDisk(user):
+ if disk > maxDisk(user, machine):
raise MyException("Too much disk requested")
disk = int(disk * 1024)
if disk <= 0:
raise ValueError
except ValueError:
raise MyException("Invalid disk amount")
raise MyException("Too much disk requested")
disk = int(disk * 1024)
if disk <= 0:
raise ValueError
except ValueError:
raise MyException("Invalid disk amount")
+ return disk
+
+def create(user, fields):
+ name = fields.getfirst('name')
+ if not validMachineName(name):
+ raise MyException("Invalid name '%s'" % name)
+ name = user.username + '_' + name.lower()
+
+ if Machine.get_by(name=name):
+ raise MyException("A machine named '%s' already exists" % name)
+
+ memory = fields.getfirst('memory')
+ memory = validMemory(user, memory)
+ disk = fields.getfirst('disk')
+ disk = validDisk(user, disk)
+
vm_type = fields.getfirst('vmtype')
if vm_type not in ('hvm', 'paravm'):
raise MyException("Invalid vm type '%s'" % vm_type)
vm_type = fields.getfirst('vmtype')
if vm_type not in ('hvm', 'paravm'):
raise MyException("Invalid vm type '%s'" % vm_type)