try/except on kvm allocation
This commit is contained in:
parent
1b6e7e629e
commit
ab8a099ff9
1 changed files with 11 additions and 7 deletions
16
plugin.py
16
plugin.py
|
@ -71,8 +71,8 @@ def vmcreate(req):
|
|||
|
||||
#generators
|
||||
#slave_name = str(grid.query_happiness(region_id, weight)) #TODO: provide weight parameters here and calculate route
|
||||
slave_name = 'lexx' #staic route
|
||||
#slave_name = 'warrior'
|
||||
#slave_name = 'lexx' #staic route
|
||||
slave_name = 'warrior'
|
||||
|
||||
#vmid = str(grid.generate_vmid()) #TODO: this should be between 100 and 65000
|
||||
vm_id = random.randint(1000, 9999)
|
||||
|
@ -113,10 +113,14 @@ def vmcreate(req):
|
|||
if req['vps_type'] == 'kvm':
|
||||
#create partition
|
||||
image_name = 'vm-' + str(vm_id) + '-disk-1'
|
||||
try:
|
||||
local_storage = proxobject.nodes(real_slave_name).storage('lvm')
|
||||
local_storage.content.post(vmid=vm_id,
|
||||
filename=image_name,
|
||||
size=req['vps_hdd'] + 'G')
|
||||
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))
|
||||
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),
|
||||
name=vm_name,
|
||||
|
@ -143,12 +147,12 @@ def vmcreate(req):
|
|||
onboot=1,
|
||||
description=description)
|
||||
|
||||
print(str(create_result))
|
||||
|
||||
#TODO: setup based on req['vps_recipe']
|
||||
#start the machihe
|
||||
#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)
|
||||
|
|
Loading…
Reference in a new issue