try/except on kvm allocation

This commit is contained in:
deflax 2017-04-09 02:56:09 +03:00
parent 1b6e7e629e
commit ab8a099ff9

View file

@ -71,8 +71,8 @@ def vmcreate(req):
#generators #generators
#slave_name = str(grid.query_happiness(region_id, weight)) #TODO: provide weight parameters here and calculate route #slave_name = str(grid.query_happiness(region_id, weight)) #TODO: provide weight parameters here and calculate route
slave_name = 'lexx' #staic route #slave_name = 'lexx' #staic route
#slave_name = 'warrior' slave_name = 'warrior'
#vmid = str(grid.generate_vmid()) #TODO: this should be between 100 and 65000 #vmid = str(grid.generate_vmid()) #TODO: this should be between 100 and 65000
vm_id = random.randint(1000, 9999) vm_id = random.randint(1000, 9999)
@ -113,10 +113,14 @@ def vmcreate(req):
if req['vps_type'] == 'kvm': if req['vps_type'] == 'kvm':
#create partition #create partition
image_name = 'vm-' + str(vm_id) + '-disk-1' image_name = 'vm-' + str(vm_id) + '-disk-1'
local_storage = proxobject.nodes(real_slave_name).storage('lvm') try:
local_storage.content.post(vmid=vm_id, local_storage = proxobject.nodes(real_slave_name).storage('lvm')
filename=image_name, storage_create_result = local_storage.content.post(vmid=vm_id, filename=image_name, size=req['vps_hdd'] + 'G')
size=req['vps_hdd'] + 'G') ioconfig.logger.info('slave[%s]> allocated %s as %s' % (slave_name, req['vps_hdd'], image_name))
except:
ioconfig.logger.info('slave[%s]> unable to allocate %s' % (slave_name, image_name))
response = { 'status':'FAIL' }
return response
create_result = proxobject.nodes(real_slave_name).qemu.post(vmid=int(vm_id), create_result = proxobject.nodes(real_slave_name).qemu.post(vmid=int(vm_id),
name=vm_name, name=vm_name,
@ -143,12 +147,12 @@ def vmcreate(req):
onboot=1, onboot=1,
description=description) description=description)
print(str(create_result))
#TODO: setup based on req['vps_recipe'] #TODO: setup based on req['vps_recipe']
#start the machihe #start the machihe
#time.sleep(7) #wait few seconds for the slave to prepare the machine for initial run #time.sleep(7) #wait few seconds for the slave to prepare the machine for initial run
#vmstart(cubeid) #vmstart(cubeid)
#print(str(create_result))
response = { 'status':'CREATE', 'cube':cubeid, 'name':vm_name, 'password':vm_pass, 'ipv4_0':ipv4_list[0] } response = { 'status':'CREATE', 'cube':cubeid, 'name':vm_name, 'password':vm_pass, 'ipv4_0':ipv4_list[0] }
grid.writedb(deploy) grid.writedb(deploy)