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',
|
||||
'slave': 'warrior',
|
||||
'vmid': 4500,
|
||||
'cpu_mem_hdd': (vps_cpu, vps_mem, vps_hdd),
|
||||
'cpu': vps_cpu,
|
||||
'mem': vps_mem,
|
||||
'hdd': vps_hdd,
|
||||
'clientid', 12,
|
||||
'clientname': 'Master',
|
||||
'clientemail':'info@domain.com',
|
||||
'os': 'ubuntu',
|
||||
'clientemail':'info@domain.com'
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#makes jsons human (and machine) readable
|
||||
|
||||
for filename in db/*.json ; do
|
||||
cat $filename | python3 -m json.tool
|
||||
echo $filename;
|
||||
python3 -m json.tool $filename
|
||||
read;
|
||||
done;
|
||||
|
||||
|
|
49
plugin.py
49
plugin.py
|
@ -30,22 +30,18 @@ def auth(slave_name):
|
|||
# connection = lib_proxmoxia.Connector(slaveip)
|
||||
# auth_token = connection.get_auth_token(adminuser, slavepass)
|
||||
# proxobject = lib_proxmoxia.Proxmox(connection)
|
||||
|
||||
if slavetype == 'proxmox':
|
||||
proxobject = ProxmoxAPI(slaveip, user=adminuser, password=slavepass, verify_ssl=False)
|
||||
return proxobject
|
||||
|
||||
|
||||
def vmlist(proxobject):
|
||||
""" get vmlist """
|
||||
#we keep a single node proxmoxes so node id = 0
|
||||
|
||||
#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']
|
||||
#query_kvm = proxobject.get('nodes/%s/qemu' % slave_name)
|
||||
query_kvm = proxobject.nodes(slave_name).qemu.get()
|
||||
query_lxc = proxobject.nodes(slave_name).lxc.get()
|
||||
|
||||
for kvm_dict in query_kvm:
|
||||
kvm_dict['vmtype'] = 'kvm'
|
||||
for lxc_dict in query_lxc:
|
||||
|
@ -53,7 +49,6 @@ def vmlist(proxobject):
|
|||
vmlist = query_kvm + query_lxc #merge machine list
|
||||
return vmlist
|
||||
|
||||
|
||||
def vmcreate(req):
|
||||
""" create vm. returns JSON with data """
|
||||
try:
|
||||
|
@ -65,48 +60,32 @@ def vmcreate(req):
|
|||
vm_name_utf8 = req['hostname']
|
||||
vm_name = unidecode(vm_name_utf8)
|
||||
try:
|
||||
vm_pass = req['vmpass']
|
||||
vm_pass = req['rootpass']
|
||||
except:
|
||||
vm_pass = 'kvm-no-pass'
|
||||
|
||||
#generators
|
||||
vm_pass = 'datapoint'
|
||||
#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'
|
||||
|
||||
#vmid = str(grid.generate_vmid()) #TODO: this should be between 100 and 65000
|
||||
#vm_id = str(grid.generate_vmid()) #TODO: this should be between 100 and 65000
|
||||
vm_id = random.randint(1000, 9999)
|
||||
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),
|
||||
'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'],
|
||||
'clientname': req['clientname'],
|
||||
'clientemail': req['clientemail'],
|
||||
'recipe': req['vps_recipe'],
|
||||
'iso9660': 'ubuntu-16.04.1-server-amd64.iso',
|
||||
'ip0': req['vps_ipv4'],
|
||||
'mac0': req['vps_mac'] }
|
||||
|
||||
'hostname': vm_name,
|
||||
'region': region_fullname,
|
||||
'slave': slave_name,
|
||||
'vmid': vm_id,
|
||||
'cpu': req['cpu'],
|
||||
'mem': req['mem'],
|
||||
'hdd': req['hdd']
|
||||
}
|
||||
proxobject = auth(slave_name)
|
||||
real_slave_name = proxobject.cluster.status.get()[0]['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':
|
||||
#create partition
|
||||
|
@ -126,8 +105,6 @@ def vmcreate(req):
|
|||
cores=req['vps_cpu'],
|
||||
memory=req['vps_mem'],
|
||||
virtio0='file=lvm:' + image_name,
|
||||
ide1='backup:iso/' + deploy['iso9660'] + ',media=cdrom',
|
||||
net0='virtio,bridge=vmbr0,macaddr=' + req['macaddr'],
|
||||
onboot=1,
|
||||
description=description)
|
||||
|
||||
|
|
Loading…
Reference in a new issue