add ability to change vm memory, remove space between amount and unit

This commit is contained in:
Jordan Rodgers 2017-12-10 23:58:29 -05:00
parent 9fa6bf051d
commit 75ef5a98d1
4 changed files with 102 additions and 3 deletions

23
app.py
View file

@ -99,8 +99,8 @@ def vm_cpu(vmid, cores):
app.config['PROXMOX_PASS'])
if int(vmid) in get_user_allowed_vms(proxmox, user):
cur_cores = get_vm_config(proxmox, vmid)['cores']
status = get_vm(proxmox, vmid)['qmpstatus']
if cores >= cur_cores:
status = get_vm(proxmox, vmid)['qmpstatus']
if status == 'running' or status == 'paused':
usage_check = check_user_usage(proxmox, user, cores - cur_cores, 0, 0)
else:
@ -113,6 +113,27 @@ def vm_cpu(vmid, cores):
return '', 403
@app.route("/vm/<string:vmid>/mem/<int:mem>", methods=['POST'])
def vm_mem(vmid, mem):
proxmox = connect_proxmox(app.config['PROXMOX_HOST'],
app.config['PROXMOX_USER'],
app.config['PROXMOX_PASS'])
if int(vmid) in get_user_allowed_vms(proxmox, user):
cur_mem = get_vm_config(proxmox, vmid)['memory'] // 1024
if mem >= cur_mem:
status = get_vm(proxmox, vmid)['qmpstatus']
if status == 'running' or status == 'paused':
usage_check = check_user_usage(proxmox, user, 0, mem - cur_mem, 0)
else:
usage_check = check_user_usage(proxmox, user, 0, mem, 0)
if usage_check:
return usage_check
change_vm_mem(proxmox, vmid, mem * 1024)
return '', 200
else:
return '', 403
@app.route("/vm/<string:vmid>/renew", methods=['POST'])
def vm_renew(vmid):
proxmox = connect_proxmox(app.config['PROXMOX_HOST'],