Added DEV_PREFIX parameter when creating VM, so that we create KVM virtual disk

This commit is contained in:
M.Ravi 2017-05-01 14:28:23 +05:30
parent 68e81472d5
commit 7cc2af420b

View file

@ -103,22 +103,30 @@ class HostingManageVMAdmin(admin.ModelAdmin):
vm_template_int = int(vm_template) vm_template_int = int(vm_template)
if 1 <= vm_template_int <= 8: if 1 <= vm_template_int <= 8:
vm_string_formatter = """<VM> vm_string_formatter = """<VM>
<CONTEXT>
<SSH_PUBLIC_KEY>
{ssh_key}
</SSH_PUBLIC_KEY>
</CONTEXT>
<MEMORY>{memory}</MEMORY> <MEMORY>{memory}</MEMORY>
<VCPU>{vcpu}</VCPU> <VCPU>{vcpu}</VCPU>
<CPU>{cpu}</CPU> <CPU>{cpu}</CPU>
<DISK> <DISK>
<TYPE>{disk_type}</TYPE> <TYPE>{disk_type}</TYPE>
<SIZE>{size}</SIZE> <SIZE>{size}</SIZE>
<DEV_PREFIX>{dev_prefix}</DEV_PREFIX>
</DISK> </DISK>
</VM> </VM>
""" """
vm_id = oca.VirtualMachine.allocate(self.client, vm_id = oca.VirtualMachine.allocate(self.client,
vm_string_formatter.format( vm_string_formatter.format(
memory=1024 * vm_template_int, ssh_key='' # public key of the user
vcpu=vm_template_int, memory=1024 * vm_template_int, # memory in MB
cpu=0.1 * vm_template_int, vcpu=vm_template_int, # vpcu
cpu=0.1 * vm_template_int, # cpu
disk_type='fs', disk_type='fs',
size=10000 * vm_template_int)) size=10000 * vm_template_int,
dev_prefix='vd')) # We need KVM virtual disk
message = _("Created with id = " + str(vm_id)) message = _("Created with id = " + str(vm_id))
messages.add_message(request, messages.SUCCESS, message) messages.add_message(request, messages.SUCCESS, message)
else: else: