fixing vmcreate

This commit is contained in:
deflax 2016-11-03 18:56:26 +02:00
parent 1bcda20659
commit 92e91aa631
2 changed files with 26 additions and 22 deletions

View file

@ -50,7 +50,7 @@ def writedb(src_data):
json.dump(src_data, dbf) json.dump(src_data, dbf)
dbf.close() dbf.close()
#TODO: send mail #TODO: send mail
logger.info('grid> {} <-- {}'.format(dbfile, src_data)) logger.info('grid> {} --> {}'.format(src_data, dbfile))
except Exception as e: except Exception as e:
logger.critical('grid> {}'.format(e)) logger.critical('grid> {}'.format(e))
pass pass

View file

@ -26,14 +26,13 @@ def auth(slave_name):
slavetype = ioconfig.parser.get(str(slave_name), 'type') slavetype = ioconfig.parser.get(str(slave_name), 'type')
#vendor specific #vendor specific
if slavetype == 'proxmoxia': #if slavetype == 'proxmoxia':
connection = lib_proxmoxia.Connector(slaveip) # connection = lib_proxmoxia.Connector(slaveip)
auth_token = connection.get_auth_token(adminuser, slavepass) # auth_token = connection.get_auth_token(adminuser, slavepass)
proxobject = lib_proxmoxia.Proxmox(connection) # proxobject = lib_proxmoxia.Proxmox(connection)
if slavetype == 'proxmox': if slavetype == 'proxmox':
proxobject = ProxmoxAPI(slaveip, user=adminuser, password=slavepass, verify_ssl=False) proxobject = ProxmoxAPI(slaveip, user=adminuser, password=slavepass, verify_ssl=False)
return proxobject return proxobject
@ -76,8 +75,15 @@ def vmcreate(req):
#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)
cubeid = int(time.time() * 10000 * 10000) cubeid = int(time.time() * 10000 * 10000)
### ipv4
ipv4_list = grid.generate_ipv4(req['region'], req['vps_ipv4']) ipv4_list = grid.generate_ipv4(req['region'], req['vps_ipv4'])
ipv4_dict = {}
ipidx = 0
for ip in ipv4_list:
ipv4_dict[str(ipidx)] = str(ip)
ipidx += 1
#TODO: aa:aa:aa <- generate from slave name to hex bb:bb:bb <- generate from cubeid to hex
macaddr = 'E2:C6:DE:BE:98:F2'
#metadata #metadata
deploy = { 'cube': int(cubeid), deploy = { 'cube': int(cubeid),
@ -90,20 +96,16 @@ def vmcreate(req):
'clientid': req['clientid'], 'clientid': req['clientid'],
'clientname': req['clientname'], 'clientname': req['clientname'],
'clientemail': req['clientemail'], 'clientemail': req['clientemail'],
'os': req['vps_os'], 'recipe': req['vps_recipe'],
'ipv4': ipv4_list } 'iso9660': req['vps_iso9660'],
'ipv4': ipv4_list,
'macaddr': macaddr }
proxobject = auth(slave_name) proxobject = auth(slave_name)
#slave_name = proxobject.cluster.status.get()[0]['name'] real_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, ipv4_list, req) #ioconfig.logger.info('slave[' + slave_name + ']> deploying %s on %s (%s) at %s with %s and %s', cubeid, slave_name, vm_id, region_id, ipv4_list, req)
grid.writedb(deploy) grid.writedb(deploy)
ipv4_dict = {}
ipidx = 0
for ip in ipv4_list:
ipv4_dict[str(ipidx)] = str(ip)
ipidx += 1
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] }
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]
@ -115,19 +117,19 @@ def vmcreate(req):
size=req['vps_hdd'] + 'G') size=req['vps_hdd'] + 'G')
if req['vps_type'] == 'kvm': if req['vps_type'] == 'kvm':
create_result = proxobject.nodes(slave_name).qemu.post(vmid=vm_id, create_result = proxobject.nodes(real_slave_name).qemu.post(vmid=str(vm_id),
name=vm_name, name=vm_name,
sockets=1, sockets=1,
cores=req['vps_cpu'], cores=req['vps_cpu'],
memory=req['vps_mem'], memory=req['vps_mem'],
virtio0='lvm:' + image_name, virtio0='vm:' + image_name,
ide1='skyblue:iso/' + req['vps_os'] + ',media=cdrom', ide1='skyblue:iso/' + req['vps_iso9660'] + ',media=cdrom',
net0='VirtIO,bridge=vmbr0', net0='virtio=' + macaddr + ' ,bridge=vmbr0',
onboot=1, onboot=1,
description=description) description=description)
if req['vps_type'] == 'lxc': if req['vps_type'] == 'lxc':
create_result = proxobject.nodes(slave_name).lxc.post(vmid=vm_id, create_result = proxobject.nodes(real_slave_name).lxc.post(vmid=str(vm_id),
hostname=vm_name, hostname=vm_name,
password=vm_pass, password=vm_pass,
sockets=1, sockets=1,
@ -138,6 +140,8 @@ def vmcreate(req):
onboot=1, onboot=1,
description=description) description=description)
#TODO: setup based onreq['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)