fixing vmcreate

This commit is contained in:
deflax 2016-11-03 06:38:26 +02:00
parent f030f3fbb5
commit 07e0e4cfaa

View file

@ -75,16 +75,16 @@ 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
vmid = random.randint(200, 62000) vmid = random.randint(200, 62000)
cube_id = time.time() #TODO: make sure this is unique. time since epoch is not random enough but should do the trick for now cubeid = time.time() #TODO: make sure this is unique. time since epoch is not random enough but should do the trick for now
ipv4_list = grid.generate_ipv4(req['region'], req['vps_ipv4']) ipv4_list = grid.generate_ipv4(req['region'], req['vps_ipv4'])
#metadata #metadata
deploy = { 'cube': int(cube_id), deploy = { 'cube': int(cubeid),
'type': req['vps_type'], 'type': req['vps_type'],
'host': vm_name, 'host': vm_name,
'region': region_fullname, 'region': region_fullname,
'slave': slave_name, 'slave': slave_name,
'vmid': vmid, 'vmid': vm_id,
'cpu_mem_hdd': (req['vps_cpu'], req['vps_mem'], req['vps_hdd']), 'cpu_mem_hdd': (req['vps_cpu'], req['vps_mem'], req['vps_hdd']),
'clientid': req['clientid'], 'clientid': req['clientid'],
'clientname': req['clientname'], 'clientname': req['clientname'],
@ -95,14 +95,17 @@ def vmcreate(req):
proxobject = auth(slave_name) proxobject = auth(slave_name)
#slave_name = proxobject.cluster.status.get()[0]['name'] #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, vm_ipv4, req)
grid.writedb(deploy)
ipv4_dict = {} ipv4_dict = {}
ipidx = 0 ipidx = 0
ioconfig.logger.info('slave[' + slave_name + ']> deploying %s on %s at %s with %s and %s', vm_id, slave_id , region_id, vm_ipv4, req)
for ip in vm_ipv4: for ip in vm_ipv4:
ipv4_dict[str(ipidx)] = str(ip) ipv4_dict[str(ipidx)] = str(ip)
ipidx += 1 ipidx += 1
response = { 'status':'CREATE', 'vmid':vm_id, 'name':vm_name, 'password':vm_pass, 'ipv4_0':vm_ipv4[0] } response = { 'status':'CREATE', 'cube':vm_id, 'name':vm_name, 'password':vm_pass, 'ipv4_0':vm_ipv4[0] }
description = vm_name + ' (' + vm_id + ')\n' + 'owned by ' + client_name + ' (' + client_id + ')\n' + 'master ip: ' + vm_ipv4[0] description = vm_name + ' (' + vm_id + ')\n' + 'owned by ' + client_name + ' (' + client_id + ')\n' + 'master ip: ' + vm_ipv4[0]
#create partition #create partition
@ -141,7 +144,7 @@ def vmcreate(req):
#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(vm_id) vmstart(cubeid)
return response return response