remove template desc, add way to resize disks

This commit is contained in:
Jordan Rodgers 2018-02-22 18:29:40 -05:00
parent cebad26e6b
commit e375e452e2
8 changed files with 104 additions and 13 deletions

View file

@ -269,6 +269,23 @@ def vm_mem(vmid, mem):
return '', 403 return '', 403
@app.route("/vm/<string:vmid>/disk/<string:disk>/<int:size>", methods=['POST'])
@auth.oidc_auth
def vm_disk(vmid, disk, size):
user = build_user_dict(session, db)
proxmox = connect_proxmox()
if user['rtp'] or int(vmid) in get_user_allowed_vms(
proxmox, db, user['username']):
cur_cores = get_vm_config(proxmox, vmid)['cores']
usage_check = check_user_usage(proxmox, db, user['username'], 0, 0, size)
if usage_check:
return usage_check
resize_vm_disk(proxmox, vmid, disk, size)
return '', 200
else:
return '', 403
@app.route("/vm/<string:vmid>/renew", methods=['POST']) @app.route("/vm/<string:vmid>/renew", methods=['POST'])
@auth.oidc_auth @auth.oidc_auth
def vm_renew(vmid): def vm_renew(vmid):

View file

@ -154,8 +154,8 @@ def get_templates(db):
template_dict = dict() template_dict = dict()
template_dict['id'] = template.id template_dict['id'] = template.id
template_dict['name'] = template.name template_dict['name'] = template.name
template_dict['desc'] = template.desc
template_dict['username'] = template.username template_dict['username'] = template.username
template_dict['password'] = template.password
template_dict['disk'] = template.disk template_dict['disk'] = template.disk
templates.append(template_dict) templates.append(template_dict)
return templates return templates
@ -167,7 +167,6 @@ def get_template(db, template_id):
template = db.query(Template).filter(Template.id == template_id).one() template = db.query(Template).filter(Template.id == template_id).one()
template_dict['id'] = template.id template_dict['id'] = template.id
template_dict['name'] = template.name template_dict['name'] = template.name
template_dict['desc'] = template.desc
template_dict['username'] = template.username template_dict['username'] = template.username
template_dict['password'] = template.password template_dict['password'] = template.password
template_dict['disk'] = template.disk template_dict['disk'] = template.disk

View file

@ -34,7 +34,6 @@ class Template(Base):
__tablename__ = 'template' __tablename__ = 'template'
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
name = Column(String(32), nullable=False) name = Column(String(32), nullable=False)
desc = Column(Text)
username = Column(Text, nullable=False) username = Column(Text, nullable=False)
password = Column(Text, nullable=False) password = Column(Text, nullable=False)
disk = Column(Integer, nullable=False) disk = Column(Integer, nullable=False)

View file

@ -317,3 +317,8 @@ def clone_vm(proxmox, template_id, name, pool):
retry += 1 retry += 1
time.sleep(3) time.sleep(3)
return newid, mac return newid, mac
def resize_vm_disk(proxmox, vmid, disk, size):
node = proxmox.nodes(get_vm_node(proxmox, vmid))
node.qemu(vmid).resize.put(disk=disk, size="+{}G".format(size))

View file

@ -128,3 +128,12 @@ table, th, td {
float: right; float: right;
padding-bottom: 2px; padding-bottom: 2px;
} }
.swal-button {
padding: 6px 16px;
font-family: inherit;
font-weight: normal;
font-size: 13px;
border-radius: 3px;
text-transform: uppercase;
}

View file

@ -319,7 +319,7 @@ $("#change-iso").click(function(){
select: { select: {
text: "Select", text: "Select",
closeModal: false, closeModal: false,
className: "swal-button--danger", className: "",
} }
}, },
dangerMode: true, dangerMode: true,
@ -503,7 +503,6 @@ $("#create-vm").click(function(){
$("#change-cores").click(function(){ $("#change-cores").click(function(){
const vmid = $(this).data('vmid'); const vmid = $(this).data('vmid');
const cur_cores = $(this).data('cores');
const usage = $(this).data('usage'); const usage = $(this).data('usage');
const limit = $(this).data('limit'); const limit = $(this).data('limit');
var core_list = document.createElement('select'); var core_list = document.createElement('select');
@ -561,7 +560,6 @@ $("#change-cores").click(function(){
$("#change-mem").click(function(){ $("#change-mem").click(function(){
const vmid = $(this).data('vmid'); const vmid = $(this).data('vmid');
const cur_mem = $(this).data('mem');
const usage = $(this).data('usage'); const usage = $(this).data('usage');
const limit = $(this).data('limit'); const limit = $(this).data('limit');
var mem_list = document.createElement('select'); var mem_list = document.createElement('select');
@ -844,3 +842,64 @@ $(".add-allowed-user").click(function(){
location.reload(); location.reload();
}); });
}); });
$(".resize-disk").click(function(){
const vmid = $(this).data('vmid');
const disk = $(this).data('disk');
const usage = $(this).data('usage');
const limit = $(this).data('limit');
swal({
title: 'Enter how many GB you would like to expand this disk by:',
content: {
element: 'input',
attributes: {
type: 'number',
},
},
buttons: {
cancel: {
text: "Cancel",
visible: true,
closeModal: true,
className: "",
},
confirm: {
text: "Select",
closeModal: false,
className: "swal-button",
}
},
})
.then((size) => {
if (size) {
if ((parseInt(usage) + parseInt(size)) <= parseInt(limit)) {
fetch(`/vm/${vmid}/disk/${disk}/${size}`, {
credentials: 'same-origin',
method: 'post'
}).then((response) => {
return swal(`Disk size has been increased!`, {
icon: "success",
buttons: {
ok: {
text: "OK",
closeModal: true,
className: "",
}
}
});
}).then(() => {
window.location = `/vm/${vmid}`;
});
} else {
swal("Uh oh...", `You don't have enough disk resources! Try again with a smaller size.`, "error");
}
}
}).catch(err => {
if (err) {
swal("Uh oh...", `Unable to resize the disk. Please try again later.`, "error");
} else {
swal.stopLoading();
swal.close();
}
});
});

View file

@ -16,7 +16,6 @@
<th>Name</th> <th>Name</th>
<th>Username</th> <th>Username</th>
<th>Disk Size (GB)</th> <th>Disk Size (GB)</th>
<th>Description</th>
<th>Delete</th> <th>Delete</th>
</tr> </tr>
</thead> </thead>
@ -27,7 +26,6 @@
<td>{{ template['name'] }}</td> <td>{{ template['name'] }}</td>
<td>{{ template['username'] }}</td> <td>{{ template['username'] }}</td>
<td>{{ template['disk'] }}</td> <td>{{ template['disk'] }}</td>
<td>{{ template['desc'] }}</td>
<td> <td>
<button class="btn btn-sm btn-danger delete-template" data-template_id="{{ template['id'] }}"> <button class="btn btn-sm btn-danger delete-template" data-template_id="{{ template['id'] }}">
<span class="glyphicon glyphicon-remove"></span> <span class="glyphicon glyphicon-remove"></span>

View file

@ -49,7 +49,12 @@
{% 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
<button class="btn btn-default proxstar-changebtn resize-disk" id="resize-disk" name="resize" data-vmid="{{ vm['vmid'] }}" data-disk="{{ disk[0] }}" data-usage="{{ usage['disk'] }}" data-limit="{{ limits['disk'] }}">
<span class="glyphicon glyphicon-cog"></span>
</button>
</li>
{% endfor %} {% endfor %}
<li class="nav-header">ISO</li> <li class="nav-header">ISO</li>
<li> <li>
@ -88,11 +93,11 @@
<dd> <dd>
{{ vm['config']['cores'] * vm['config'].get('sockets', 1) }} {{ vm['config']['cores'] * vm['config'].get('sockets', 1) }}
{% if vm['qmpstatus'] == 'running' or vm['qmpstatus'] == 'paused' %} {% if vm['qmpstatus'] == 'running' or vm['qmpstatus'] == 'paused' %}
<button class="btn btn-default proxstar-changebtn" id="change-cores" data-vmid="{{ vm['vmid'] }}" data-cores="{{ vm['config']['cores'] * vm['config'].get('sockets', 1) }}" data-usage="{{ usage['cpu'] - (vm['config']['cores'] * vm['config'].get('sockets', 1)) }}" data-limit="{{ limits['cpu'] }}"> <button class="btn btn-default proxstar-changebtn" id="change-cores" data-vmid="{{ vm['vmid'] }}" data-usage="{{ usage['cpu'] - (vm['config']['cores'] * vm['config'].get('sockets', 1)) }}" data-limit="{{ limits['cpu'] }}">
<span class="glyphicon glyphicon-cog"></span> <span class="glyphicon glyphicon-cog"></span>
</button> </button>
{% else %} {% else %}
<button class="btn btn-default proxstar-changebtn" id="change-cores" data-vmid="{{ vm['vmid'] }}" data-cores="{{ vm['config']['cores'] * vm['config'].get('sockets', 1) }}" data-usage=0 data-limit="{{ limits['cpu'] }}"> <button class="btn btn-default proxstar-changebtn" id="change-cores" data-vmid="{{ vm['vmid'] }}" data-usage=0 data-limit="{{ limits['cpu'] }}">
<span class="glyphicon glyphicon-cog"></span> <span class="glyphicon glyphicon-cog"></span>
</button> </button>
{% endif %} {% endif %}
@ -105,11 +110,11 @@
{{ vm['config']['memory'] // 1024 }}GB {{ vm['config']['memory'] // 1024 }}GB
{% endif %} {% endif %}
{% if vm['qmpstatus'] == 'running' or vm['qmpstatus'] == 'paused' %} {% 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'] }}"> <button class="btn btn-default proxstar-changebtn" id="change-mem" data-vmid="{{ vm['vmid'] }}" data-usage="{{ usage['mem'] - vm['config']['memory'] // 1024 }}" data-limit="{{ limits['mem'] }}">
<span class="glyphicon glyphicon-cog"></span> <span class="glyphicon glyphicon-cog"></span>
</button> </button>
{% else %} {% else %}
<button class="btn btn-default proxstar-changebtn" id="change-mem" data-vmid="{{ vm['vmid'] }}" data-cores="{{ vm['config']['memory'] // 1024 }}" data-usage=0 data-limit="{{ limits['mem'] }}"> <button class="btn btn-default proxstar-changebtn" id="change-mem" data-vmid="{{ vm['vmid'] }}" data-usage=0 data-limit="{{ limits['mem'] }}">
<span class="glyphicon glyphicon-cog"></span> <span class="glyphicon glyphicon-cog"></span>
</button> </button>
{% endif %} {% endif %}