mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
add ability to change vm memory, remove space between amount and unit
This commit is contained in:
parent
9fa6bf051d
commit
75ef5a98d1
4 changed files with 102 additions and 3 deletions
23
app.py
23
app.py
|
@ -99,8 +99,8 @@ def vm_cpu(vmid, cores):
|
||||||
app.config['PROXMOX_PASS'])
|
app.config['PROXMOX_PASS'])
|
||||||
if int(vmid) in get_user_allowed_vms(proxmox, user):
|
if int(vmid) in get_user_allowed_vms(proxmox, user):
|
||||||
cur_cores = get_vm_config(proxmox, vmid)['cores']
|
cur_cores = get_vm_config(proxmox, vmid)['cores']
|
||||||
status = get_vm(proxmox, vmid)['qmpstatus']
|
|
||||||
if cores >= cur_cores:
|
if cores >= cur_cores:
|
||||||
|
status = get_vm(proxmox, vmid)['qmpstatus']
|
||||||
if status == 'running' or status == 'paused':
|
if status == 'running' or status == 'paused':
|
||||||
usage_check = check_user_usage(proxmox, user, cores - cur_cores, 0, 0)
|
usage_check = check_user_usage(proxmox, user, cores - cur_cores, 0, 0)
|
||||||
else:
|
else:
|
||||||
|
@ -113,6 +113,27 @@ def vm_cpu(vmid, cores):
|
||||||
return '', 403
|
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'])
|
@app.route("/vm/<string:vmid>/renew", methods=['POST'])
|
||||||
def vm_renew(vmid):
|
def vm_renew(vmid):
|
||||||
proxmox = connect_proxmox(app.config['PROXMOX_HOST'],
|
proxmox = connect_proxmox(app.config['PROXMOX_HOST'],
|
||||||
|
|
|
@ -227,6 +227,11 @@ def change_vm_cpu(proxmox, vmid, cores):
|
||||||
node.qemu(vmid).config.put(cores=cores)
|
node.qemu(vmid).config.put(cores=cores)
|
||||||
|
|
||||||
|
|
||||||
|
def change_vm_mem(proxmox, vmid, mem):
|
||||||
|
node = proxmox.nodes(get_vm_node(proxmox, vmid))
|
||||||
|
node.qemu(vmid).config.put(memory=mem)
|
||||||
|
|
||||||
|
|
||||||
def get_isos(proxmox, storage):
|
def get_isos(proxmox, storage):
|
||||||
isos = []
|
isos = []
|
||||||
for iso in proxmox.nodes('proxmox01').storage(storage).content.get():
|
for iso in proxmox.nodes('proxmox01').storage(storage).content.get():
|
||||||
|
|
|
@ -510,3 +510,61 @@ $("#change-cores").click(function(){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#change-mem").click(function(){
|
||||||
|
const vmid = $(this).data('vmid')
|
||||||
|
const cur_mem = $(this).data('mem')
|
||||||
|
const usage = $(this).data('usage')
|
||||||
|
const limit = $(this).data('limit')
|
||||||
|
var mem_list = document.createElement('select');
|
||||||
|
mem_list.setAttribute('style', 'width: 45px');
|
||||||
|
for (i = 1; i < limit - usage + 1; i++) {
|
||||||
|
mem_list.appendChild(new Option(`${i}GB`, i));
|
||||||
|
}
|
||||||
|
swal({
|
||||||
|
title: 'Select how much memory you would like to allocate to this VM:',
|
||||||
|
content: mem_list,
|
||||||
|
buttons: {
|
||||||
|
cancel: {
|
||||||
|
text: "Cancel",
|
||||||
|
visible: true,
|
||||||
|
closeModal: true,
|
||||||
|
className: "",
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
text: "Select",
|
||||||
|
closeModal: false,
|
||||||
|
className: "swal-button",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((willChange) => {
|
||||||
|
if (willChange) {
|
||||||
|
const mem = $(mem_list).val()
|
||||||
|
fetch(`/proxstar/vm/${vmid}/mem/${mem}`, {
|
||||||
|
credentials: 'same-origin',
|
||||||
|
method: 'post'
|
||||||
|
}).then((response) => {
|
||||||
|
return swal(`Now applying the change to the amount of memory!`, {
|
||||||
|
icon: "success",
|
||||||
|
buttons: {
|
||||||
|
ok: {
|
||||||
|
text: "OK",
|
||||||
|
closeModal: true,
|
||||||
|
className: "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).then(() => {
|
||||||
|
window.location = `/proxstar/vm/${vmid}`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
if (err) {
|
||||||
|
swal("Uh oh...", `Unable to change the amount of memory. Please try again later.`, "error");
|
||||||
|
} else {
|
||||||
|
swal.stopLoading();
|
||||||
|
swal.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<li class="nav-header">Disks</li>
|
<li class="nav-header">Disks</li>
|
||||||
{% for disk in vm['disks'] %}
|
{% for disk in vm['disks'] %}
|
||||||
<li>{{ disk[0] }}: {{ disk[1] }} GB</li>
|
<li>{{ disk[0] }}: {{ disk[1] }}GB</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<li class="nav-header">ISO</li>
|
<li class="nav-header">ISO</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -67,6 +67,8 @@
|
||||||
<dl class="dl-horizontal">
|
<dl class="dl-horizontal">
|
||||||
<dt>Name</dt>
|
<dt>Name</dt>
|
||||||
<dd>{{ vm['name'] }}</dd>
|
<dd>{{ vm['name'] }}</dd>
|
||||||
|
<dt>DNS Name</dt>
|
||||||
|
<dd>{{ vm['name'] }}.csh.rit.edu</dd>
|
||||||
<dt>ID</dt>
|
<dt>ID</dt>
|
||||||
<dd>{{ vm['vmid'] }}</dd>
|
<dd>{{ vm['vmid'] }}</dd>
|
||||||
<dt>Status</dt>
|
<dt>Status</dt>
|
||||||
|
@ -87,7 +89,20 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</dd>
|
</dd>
|
||||||
<dt>Memory</dt>
|
<dt>Memory</dt>
|
||||||
<dd>{{ vm['config']['memory'] // 1024}} GB</dd>
|
<dd>
|
||||||
|
{{ vm['config']['memory'] // 1024 }}GB
|
||||||
|
{% if limits['mem'] - usage['mem'] > 0 %}
|
||||||
|
{% if vm['qmpstatus'] == 'running' or vm['qmpstatus'] == 'paused' %}
|
||||||
|
<button class="btn btn-default proxstar-changebtn" id="change-mem" data-vmid="{{ vm['vmid'] }}" data-mem="{{ vm['config']['memory'] // 1024 }}" data-usage="{{ usage['mem'] - vm['config']['memory'] // 1024 }}" data-limit="{{ limits['mem'] }}">
|
||||||
|
<span class="glyphicon glyphicon-cog"></span>
|
||||||
|
</button>
|
||||||
|
{% else %}
|
||||||
|
<button class="btn btn-default proxstar-changebtn" id="change-mem" data-vmid="{{ vm['vmid'] }}" data-cores="{{ vm['config']['memory'] // 1024 }}" data-usage="{{ usage['mem'] }}" data-limit="{{ limits['mem'] }}">
|
||||||
|
<span class="glyphicon glyphicon-cog"></span>
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
</dd>
|
||||||
<dt>Expiration</dt>
|
<dt>Expiration</dt>
|
||||||
<dd>
|
<dd>
|
||||||
{{ vm['expire'] }}
|
{{ vm['expire'] }}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue