separate cpu/mem/hdd tuple
This commit is contained in:
parent
4ce4eea855
commit
8c91b9dee6
3 changed files with 20 additions and 40 deletions
|
@ -8,9 +8,10 @@ format:
|
||||||
'region': 'izba',
|
'region': 'izba',
|
||||||
'slave': 'warrior',
|
'slave': 'warrior',
|
||||||
'vmid': 4500,
|
'vmid': 4500,
|
||||||
'cpu_mem_hdd': (vps_cpu, vps_mem, vps_hdd),
|
'cpu': vps_cpu,
|
||||||
|
'mem': vps_mem,
|
||||||
|
'hdd': vps_hdd,
|
||||||
'clientid', 12,
|
'clientid', 12,
|
||||||
'clientname': 'Master',
|
'clientname': 'Master',
|
||||||
'clientemail':'info@domain.com',
|
'clientemail':'info@domain.com'
|
||||||
'os': 'ubuntu',
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#makes jsons human (and machine) readable
|
#makes jsons human (and machine) readable
|
||||||
|
|
||||||
for filename in db/*.json ; do
|
for filename in db/*.json ; do
|
||||||
cat $filename | python3 -m json.tool
|
echo $filename;
|
||||||
|
python3 -m json.tool $filename
|
||||||
|
read;
|
||||||
done;
|
done;
|
||||||
|
|
||||||
|
|
49
plugin.py
49
plugin.py
|
@ -30,22 +30,18 @@ def auth(slave_name):
|
||||||
# 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
|
||||||
|
|
||||||
|
|
||||||
def vmlist(proxobject):
|
def vmlist(proxobject):
|
||||||
""" get vmlist """
|
""" get vmlist """
|
||||||
#we keep a single node proxmoxes so node id = 0
|
|
||||||
|
|
||||||
#slave_name = proxobject.get('cluster/status')#'name']
|
#slave_name = proxobject.get('cluster/status')#'name']
|
||||||
|
#we keep a single node proxmoxes so node id = 0
|
||||||
slave_name = proxobject.cluster.status.get()[0]['name']
|
slave_name = proxobject.cluster.status.get()[0]['name']
|
||||||
#query_kvm = proxobject.get('nodes/%s/qemu' % slave_name)
|
#query_kvm = proxobject.get('nodes/%s/qemu' % slave_name)
|
||||||
query_kvm = proxobject.nodes(slave_name).qemu.get()
|
query_kvm = proxobject.nodes(slave_name).qemu.get()
|
||||||
query_lxc = proxobject.nodes(slave_name).lxc.get()
|
query_lxc = proxobject.nodes(slave_name).lxc.get()
|
||||||
|
|
||||||
for kvm_dict in query_kvm:
|
for kvm_dict in query_kvm:
|
||||||
kvm_dict['vmtype'] = 'kvm'
|
kvm_dict['vmtype'] = 'kvm'
|
||||||
for lxc_dict in query_lxc:
|
for lxc_dict in query_lxc:
|
||||||
|
@ -53,7 +49,6 @@ def vmlist(proxobject):
|
||||||
vmlist = query_kvm + query_lxc #merge machine list
|
vmlist = query_kvm + query_lxc #merge machine list
|
||||||
return vmlist
|
return vmlist
|
||||||
|
|
||||||
|
|
||||||
def vmcreate(req):
|
def vmcreate(req):
|
||||||
""" create vm. returns JSON with data """
|
""" create vm. returns JSON with data """
|
||||||
try:
|
try:
|
||||||
|
@ -65,48 +60,32 @@ def vmcreate(req):
|
||||||
vm_name_utf8 = req['hostname']
|
vm_name_utf8 = req['hostname']
|
||||||
vm_name = unidecode(vm_name_utf8)
|
vm_name = unidecode(vm_name_utf8)
|
||||||
try:
|
try:
|
||||||
vm_pass = req['vmpass']
|
vm_pass = req['rootpass']
|
||||||
except:
|
except:
|
||||||
vm_pass = 'kvm-no-pass'
|
vm_pass = 'datapoint'
|
||||||
|
|
||||||
#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'
|
||||||
|
#vm_id = 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_dict = {}
|
|
||||||
#ipidx = 0
|
|
||||||
#for ip in ipv4_list:
|
|
||||||
# ipv4_dict[str(ipidx)] = str(ip)
|
|
||||||
# ipidx += 1
|
|
||||||
#macaddr = grid.genmac(cubeid)
|
|
||||||
|
|
||||||
#metadata
|
|
||||||
deploy = { 'cube': int(cubeid),
|
deploy = { 'cube': int(cubeid),
|
||||||
'type': req['vps_type'],
|
|
||||||
'host': vm_name,
|
|
||||||
'region': region_fullname,
|
|
||||||
'slave': slave_name,
|
|
||||||
'vmid': vm_id,
|
|
||||||
'cpu_mem_hdd': (req['vps_cpu'], req['vps_mem'], req['vps_hdd']),
|
|
||||||
'clientid': req['clientid'],
|
'clientid': req['clientid'],
|
||||||
'clientname': req['clientname'],
|
'clientname': req['clientname'],
|
||||||
'clientemail': req['clientemail'],
|
'clientemail': req['clientemail'],
|
||||||
'recipe': req['vps_recipe'],
|
'hostname': vm_name,
|
||||||
'iso9660': 'ubuntu-16.04.1-server-amd64.iso',
|
'region': region_fullname,
|
||||||
'ip0': req['vps_ipv4'],
|
'slave': slave_name,
|
||||||
'mac0': req['vps_mac'] }
|
'vmid': vm_id,
|
||||||
|
'cpu': req['cpu'],
|
||||||
|
'mem': req['mem'],
|
||||||
|
'hdd': req['hdd']
|
||||||
|
}
|
||||||
proxobject = auth(slave_name)
|
proxobject = auth(slave_name)
|
||||||
real_slave_name = proxobject.cluster.status.get()[0]['name']
|
real_slave_name = proxobject.cluster.status.get()[0]['name']
|
||||||
#print(real_slave_name)
|
#print(real_slave_name)
|
||||||
|
|
||||||
description = vm_name + ' (' + str(cubeid) + '/' + str(vm_id) + ')\n' + 'owned by ' + req['clientname'] + ' (' + req['clientid'] + ')\n' + 'master ip: ' + req['vps_ipv4'] + '\nmac address: ' + req['vps_mac']
|
description = vm_name + ' (' + str(cubeid) + '/' + str(vm_id) + ')\n' + 'owned by ' + req['clientname'] + ' (' + req['clientid'] + ')\n'
|
||||||
|
|
||||||
if req['vps_type'] == 'kvm':
|
if req['vps_type'] == 'kvm':
|
||||||
#create partition
|
#create partition
|
||||||
|
@ -126,8 +105,6 @@ def vmcreate(req):
|
||||||
cores=req['vps_cpu'],
|
cores=req['vps_cpu'],
|
||||||
memory=req['vps_mem'],
|
memory=req['vps_mem'],
|
||||||
virtio0='file=lvm:' + image_name,
|
virtio0='file=lvm:' + image_name,
|
||||||
ide1='backup:iso/' + deploy['iso9660'] + ',media=cdrom',
|
|
||||||
net0='virtio,bridge=vmbr0,macaddr=' + req['macaddr'],
|
|
||||||
onboot=1,
|
onboot=1,
|
||||||
description=description)
|
description=description)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue