fixing vmcreate

This commit is contained in:
deflax 2016-11-03 07:06:46 +02:00
parent a4b794361b
commit d0d3933c3e
2 changed files with 4 additions and 7 deletions

View file

@ -36,7 +36,7 @@ def querydb(cubeid):
except Exception as e: except Exception as e:
logger.critical('grid> {}'.format(e)) logger.critical('grid> {}'.format(e))
pass pass
return None return data
def writedb(src_data): def writedb(src_data):

View file

@ -75,7 +75,8 @@ def vmcreate(req):
slave_name = 'warrior' #staic route slave_name = 'warrior' #staic route
#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(200, 62000) vm_id = random.randint(200, 62000)
cubeid = time.time() #TODO: make sure this is unique. time since epoch is not random enough but should do the trick for now cubeid = int(time.time() * 10000 * 10000)
ipv4_list = grid.generate_ipv4(req['region'], req['vps_ipv4']) ipv4_list = grid.generate_ipv4(req['region'], req['vps_ipv4'])
#metadata #metadata
@ -99,7 +100,6 @@ def vmcreate(req):
ipv4_dict = {} ipv4_dict = {}
ipidx = 0 ipidx = 0
for ip in ipv4_list: for ip in ipv4_list:
ipv4_dict[str(ipidx)] = str(ip) ipv4_dict[str(ipidx)] = str(ip)
ipidx += 1 ipidx += 1
@ -108,7 +108,7 @@ def vmcreate(req):
description = vm_name + ' (' + str(cubeid) + '/' + str(vm_id) + ')\n' + 'owned by ' + req['clientname'] + ' (' + req['clientid'] + ')\n' + 'master ip: ' + 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 #create partition
image_name = 'vm-' + str(cubeid) + '-disk-0' image_name = 'vm-' + str(vm_id) + '-disk-0'
local_storage = proxobject.nodes(slave_name).storage('lvm') local_storage = proxobject.nodes(slave_name).storage('lvm')
local_storage.content.post(vmid=vm_id, local_storage.content.post(vmid=vm_id,
filename=image_name, filename=image_name,
@ -138,9 +138,6 @@ def vmcreate(req):
onboot=1, onboot=1,
description=description) description=description)
print('result:')
print(create_result)
#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)