fixing vmcreate

This commit is contained in:
deflax 2016-11-03 20:13:47 +02:00
parent 92e91aa631
commit 40dc709d68

View file

@ -103,39 +103,37 @@ def vmcreate(req):
proxobject = auth(slave_name)
real_slave_name = proxobject.cluster.status.get()[0]['name']
#ioconfig.logger.info('slave[' + slave_name + ']> deploying %s on %s (%s) at %s with %s and %s', cubeid, slave_name, vm_id, region_id, ipv4_list, req)
grid.writedb(deploy)
print(real_slave_name)
response = { 'status':'CREATE', 'cube':cubeid, 'name':vm_name, 'password':vm_pass, 'ipv4_0':ipv4_list[0] }
description = vm_name + ' (' + str(cubeid) + '/' + str(vm_id) + ')\n' + 'owned by ' + req['clientname'] + ' (' + req['clientid'] + ')\n' + 'master ip: ' + ipv4_list[0]
#create partition
image_name = 'vm-' + str(vm_id) + '-disk-0'
local_storage = proxobject.nodes(slave_name).storage('lvm')
image_name = 'vm-' + str(vm_id) + '-disk-1'
local_storage = proxobject.nodes(real_slave_name).storage('lvm')
local_storage.content.post(vmid=vm_id,
filename=image_name,
size=req['vps_hdd'] + 'G')
if req['vps_type'] == 'kvm':
create_result = proxobject.nodes(real_slave_name).qemu.post(vmid=str(vm_id),
create_result = proxobject.nodes(real_slave_name).qemu.post(vmid=int(vm_id),
name=vm_name,
sockets=1,
cores=req['vps_cpu'],
memory=req['vps_mem'],
virtio0='vm:' + image_name,
virtio0='file=lvm:' + image_name,
ide1='skyblue:iso/' + req['vps_iso9660'] + ',media=cdrom',
net0='virtio=' + macaddr + ' ,bridge=vmbr0',
net0='virtio,bridge=vmbr0,macaddr=' + macaddr,
onboot=1,
description=description)
if req['vps_type'] == 'lxc':
create_result = proxobject.nodes(real_slave_name).lxc.post(vmid=str(vm_id),
create_result = proxobject.nodes(real_slave_name).lxc.post(vmid=int(vm_id),
hostname=vm_name,
password=vm_pass,
sockets=1,
cores=req['vps_cpu'],
memory=req['vps_mem'],
virtio0='lvm:' + image_name,
virtio0='file=lvm:' + image_name,
ip_address=ipv4_list[0],
onboot=1,
description=description)
@ -146,6 +144,9 @@ def vmcreate(req):
#time.sleep(7) #wait few seconds for the slave to prepare the machine for initial run
#vmstart(cubeid)
print(str(create_result))
response = { 'status':'CREATE', 'cube':cubeid, 'name':vm_name, 'password':vm_pass, 'ipv4_0':ipv4_list[0] }
grid.writedb(deploy)
return response