diff --git a/hosting/admin.py b/hosting/admin.py
index 5f8e52f8..d6dd8975 100644
--- a/hosting/admin.py
+++ b/hosting/admin.py
@@ -137,21 +137,30 @@ class HostingManageVMsAdmin(admin.ModelAdmin):
# Creating VM by using method allocate(client, template)
def create_vm(self, request):
message = ''
- try :
- # Lets create a test VM with 128MB of ram and 1 CPU
- vm_id = oca.VirtualMachine.allocate(self.client, '1281')
- message = "Created with id = " + str(vm_id)
- vm_pool = self.get_vms()
- messages.add_message(request, messages.SUCCESS, message)
- # Lets print the VMs available in the pool
- # print("Printing the available VMs in the pool.")
- # vm_pool = oca.VirtualMachinePool(client)
- # for vm in vm_pool:
- # print("%s (memory: %s MB)" % ( vm.name, vm.template.memory))
- except socket.timeout:
- messages.add_message(request, messages.ERROR, "Socket timeout error.")
- except OpenNebulaException:
- messages.add_message(request, messages.ERROR, "OpenNebulaException occurred.")
+ # check if the request contains the template parameter, if it is
+ # not set warn the user of setting this.
+ vm_template = request.POST.get('vm_template')
+ if vm_template == 'select' :
+ messages.add_message(request, messages.ERROR, "Please select a vm template")
+ else :
+ try :
+ # We do have the vm_template param set. Get and parse it
+ # and check it to be in the desired range.
+ vm_template_int = int(vm_template)
+ if vm_template_int >=1 and vm_template_int <= 8:
+ # Lets create a test VM with 128MB of ram and 1 CPU
+ vm_id = oca.VirtualMachine.allocate(self.client, '' + str(1024 * vm_template_int) + '' + str(vm_template_int)+ '' + str(0.1 * vm_template_int) + 'fs' + str(10000 * vm_template_int) + '')
+ message = "Created with id = " + str(vm_id)
+ vm_pool = self.get_vms()
+ messages.add_message(request, messages.SUCCESS, message)
+ else:
+ messages.add_message(request, messages.ERROR, "Please select an appropriate value for vm template.")
+ except socket.timeout:
+ messages.add_message(request, messages.ERROR, "Socket timeout error.")
+ except OpenNebulaException:
+ messages.add_message(request, messages.ERROR, "OpenNebulaException occurred.")
+ except ValueError:
+ messages.add_message(request, messages.ERROR, "Please select an appropriate value for vm template.")
return redirect('admin:showvms')
# Retrives virtual machine pool information
diff --git a/hosting/templates/hosting/managevms.html b/hosting/templates/hosting/managevms.html
index f732d425..554252b6 100644
--- a/hosting/templates/hosting/managevms.html
+++ b/hosting/templates/hosting/managevms.html
@@ -1,11 +1,15 @@
{% extends "admin/base_site.html" %}
-{% load staticfiles bootstrap3 i18n %}
{% block content %}
-
-
-Create VM
-
+
{% if vms %}