fixed create vm method
This commit is contained in:
parent
97fecf88db
commit
c9c7023c73
4 changed files with 66 additions and 1 deletions
|
|
@ -87,6 +87,48 @@ class HostingManageVMAdmin(admin.ModelAdmin):
|
|||
)
|
||||
return TemplateResponse(request, "hosting/managevms.html", context)
|
||||
|
||||
def create_vm_view(self, specs):
|
||||
|
||||
try:
|
||||
# We do have the vm_template param set. Get and parse it
|
||||
# and check it to be in the desired range.
|
||||
# We have 8 possible VM templates for the moment which are 1x, 2x, 4x ...
|
||||
# the basic template of 10GB disk, 1GB ram, 1 vcpu, 0.1 cpu
|
||||
vm_string_formatter = """<VM>
|
||||
<MEMORY>{memory}</MEMORY>
|
||||
<VCPU>{vcpu}</VCPU>
|
||||
<CPU>{cpu}</CPU>
|
||||
<DISK>
|
||||
<TYPE>{disk_type}</TYPE>
|
||||
<SIZE>{size}</SIZE>
|
||||
</DISK>
|
||||
</VM>
|
||||
"""
|
||||
vm_id = oca.VirtualMachine.allocate(
|
||||
self.client,
|
||||
vm_string_formatter.format(
|
||||
memory=specs.get('memory'),
|
||||
vcpu=specs.get('cores'),
|
||||
cpu=0.1 * specs.get('cores'),
|
||||
disk_type='fs',
|
||||
size=specs.get('disk_size')
|
||||
)
|
||||
)
|
||||
# message = _("Created with id = " + str(vm_id))
|
||||
# messages.add_message(request, messages.SUCCESS, message)
|
||||
except socket.timeout as socket_err:
|
||||
logger.error("Socket timeout error: {0}".format(socket_err))
|
||||
except OpenNebulaException as opennebula_err:
|
||||
logger.error("OpenNebulaException error: {0}".format(opennebula_err))
|
||||
except OSError as os_err:
|
||||
logger.error("OSError : {0}".format(os_err))
|
||||
except ValueError as value_err:
|
||||
logger.error("ValueError : {0}".format(value_err))
|
||||
|
||||
return vm_id
|
||||
|
||||
|
||||
|
||||
# Creating VM by using method allocate(client, template)
|
||||
def create_vm(self, request):
|
||||
# check if the request contains the template parameter, if it is
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue