vmcreate phase 3

This commit is contained in:
deflax 2017-07-31 04:15:14 +03:00
parent e1e2c72a7c
commit 8dd867dc15
2 changed files with 10 additions and 11 deletions

View file

@ -85,13 +85,13 @@ def vmcreate(req):
real_slave_name = proxobject.cluster.status.get()[0]['name']
description = vm_name + ' (' + str(cubeid) + '/' + str(vm_id) + ')\n' + 'owned by ' + req['clientname'] + ' (' + req['clientid'] + ')\n'
if req['vps_type'] == 'kvm':
if req['type'] == 'kvm':
#create partition
image_name = 'vm-' + str(vm_id) + '-disk-1'
try:
local_storage = proxobject.nodes(real_slave_name).storage('lvm')
storage_create_result = local_storage.content.post(vmid=vm_id, filename=image_name, size=req['vps_hdd'] + 'G')
ioconfig.logger.info('slave[%s]> allocated %s as %s' % (slave_name, req['vps_hdd'], image_name))
storage_create_result = local_storage.content.post(vmid=vm_id, filename=image_name, size=req['hdd'] + 'G')
ioconfig.logger.info('slave[%s]> allocated %s as %s' % (slave_name, req['hdd'], image_name))
except:
ioconfig.logger.info('slave[%s]> unable to allocate %s' % (slave_name, image_name))
response = { 'status':'FAIL' }
@ -100,23 +100,22 @@ def vmcreate(req):
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'],
cores=req['cpu'],
memory=req['mem'],
virtio0='file=lvm:' + image_name,
onboot=1,
description=description)
if req['vps_type'] == 'lxc':
if req['type'] == 'lxc':
create_result = proxobject.nodes(real_slave_name).lxc.post(vmid=int(vm_id),
cpus=req['vps_cpu'],
memory=req['vps_mem'],
cpus=req['cpu'],
memory=req['mem'],
swap=16,
ostemplate='backup:vztmpl/ubuntu-16.04-standard_16.04-1_amd64.tar.gz',
hostname=vm_name,
password=vm_pass,
rootfs='lvm:' + req['vps_hdd'],
rootfs='lvm:' + req['hdd'],
virtio0='file=lvm:' + image_name,
ip_address=req['ipv4'],
onboot=1,
description=description)

View file

@ -140,7 +140,7 @@ class CreateResource(object):
@falcon.before(max_body(64 * 1024))
def on_post(self, req, resp):
"""Create a cluster node, returns array of: status, vmid, pass, ipv4, """
logger.info('grid> create ' + str(req.params))
logger.info('grid> create new cube')
resp.status, response = selector('vmcreate', req)
req.context['result'] = response