Skip to content

Commit 8fae552

Browse files
committed
Add more customization options
1 parent 95fbfce commit 8fae552

File tree

4 files changed

+294
-86
lines changed

4 files changed

+294
-86
lines changed

proxstar/__init__.py

Lines changed: 89 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def vm_details(vmid):
269269
if user.rtp or int(vmid) in user.allowed_vms:
270270
vm = VM(vmid)
271271
usage_check = user.check_usage(vm.cpu, vm.mem, 0)
272+
print(vm.boot_order)
272273
return render_template(
273274
'vm_details.html',
274275
user=user,
@@ -392,10 +393,39 @@ def vm_mem(vmid, mem):
392393
else:
393394
return '', 403
394395

396+
@app.route('/vm/<string:vmid>/renew', methods=['POST'])
397+
@auth.oidc_auth
398+
def vm_renew(vmid):
399+
user = User(session['userinfo']['preferred_username'])
400+
connect_proxmox()
401+
if user.rtp or int(vmid) in user.allowed_vms:
402+
vm = VM(vmid)
403+
renew_vm_expire(db, vmid, app.config['VM_EXPIRE_MONTHS'])
404+
for interface in vm.interfaces:
405+
if interface[2] != 'No IP' and app.config['USE_STARRS']:
406+
renew_ip(starrs, interface[2])
407+
return '', 200
408+
else:
409+
return '', 403
410+
411+
@app.route('/vm/<string:vmid>/disk/create/<int:size>', methods=['POST'])
412+
@auth.oidc_auth
413+
def create_disk(vmid, size):
414+
user = User(session['userinfo']['preferred_username'])
415+
connect_proxmox()
416+
if user.rtp or int(vmid) in user.allowed_vms:
417+
vm = VM(vmid)
418+
usage_check = user.check_usage(0, 0, size)
419+
if usage_check:
420+
return usage_check
421+
vm.create_disk(size)
422+
return '', 200
423+
else:
424+
return '', 403
395425

396-
@app.route('/vm/<string:vmid>/disk/<string:disk>/<int:size>', methods=['POST'])
426+
@app.route('/vm/<string:vmid>/disk/<string:disk>/resize/<int:size>', methods=['POST'])
397427
@auth.oidc_auth
398-
def vm_disk(vmid, disk, size):
428+
def resize_disk(vmid, disk, size):
399429
user = User(session['userinfo']['preferred_username'])
400430
connect_proxmox()
401431
if user.rtp or int(vmid) in user.allowed_vms:
@@ -408,45 +438,90 @@ def vm_disk(vmid, disk, size):
408438
else:
409439
return '', 403
410440

441+
@app.route('/vm/<string:vmid>/disk/<string:disk>/delete', methods=['POST'])
442+
@auth.oidc_auth
443+
def delete_disk(vmid, disk):
444+
user = User(session['userinfo']['preferred_username'])
445+
connect_proxmox()
446+
if user.rtp or int(vmid) in user.allowed_vms:
447+
vm = VM(vmid)
448+
vm.delete_disk(disk)
449+
return '', 200
450+
else:
451+
return '', 403
411452

412-
@app.route('/vm/<string:vmid>/renew', methods=['POST'])
453+
@app.route('/vm/<string:vmid>/iso/create', methods=['POST'])
413454
@auth.oidc_auth
414-
def vm_renew(vmid):
455+
def iso_create(vmid):
415456
user = User(session['userinfo']['preferred_username'])
416457
connect_proxmox()
417458
if user.rtp or int(vmid) in user.allowed_vms:
418459
vm = VM(vmid)
419-
renew_vm_expire(db, vmid, app.config['VM_EXPIRE_MONTHS'])
420-
for interface in vm.interfaces:
421-
if interface[2] != 'No IP' and app.config['USE_STARRS']:
422-
renew_ip(starrs, interface[2])
460+
vm.add_iso_drive()
423461
return '', 200
424462
else:
425463
return '', 403
426464

465+
@app.route('/vm/<string:vmid>/iso/<string:iso_drive>/delete', methods=['POST'])
466+
@auth.oidc_auth
467+
def iso_delete(vmid, iso_drive):
468+
user = User(session['userinfo']['preferred_username'])
469+
connect_proxmox()
470+
if user.rtp or int(vmid) in user.allowed_vms:
471+
vm = VM(vmid)
472+
vm.delete_iso_drive(iso_drive)
473+
return '', 200
474+
else:
475+
return '', 403
427476

428-
@app.route('/vm/<string:vmid>/eject', methods=['POST'])
477+
@app.route('/vm/<string:vmid>/iso/<string:iso_drive>/eject', methods=['POST'])
429478
@auth.oidc_auth
430-
def iso_eject(vmid):
479+
def iso_eject(vmid, iso_drive):
431480
user = User(session['userinfo']['preferred_username'])
432481
connect_proxmox()
433482
if user.rtp or int(vmid) in user.allowed_vms:
434483
vm = VM(vmid)
435-
vm.eject_iso()
484+
vm.eject_iso(iso_drive)
436485
return '', 200
437486
else:
438487
return '', 403
439488

440489

441-
@app.route('/vm/<string:vmid>/mount/<string:iso>', methods=['POST'])
490+
@app.route('/vm/<string:vmid>/iso/<string:iso_drive>/mount/<string:iso>', methods=['POST'])
442491
@auth.oidc_auth
443-
def iso_mount(vmid, iso):
492+
def iso_mount(vmid, iso_drive, iso):
444493
user = User(session['userinfo']['preferred_username'])
445494
connect_proxmox()
446495
if user.rtp or int(vmid) in user.allowed_vms:
447496
iso = '{}:iso/{}'.format(app.config['PROXMOX_ISO_STORAGE'], iso)
448497
vm = VM(vmid)
449-
vm.mount_iso(iso)
498+
vm.mount_iso(iso_drive, iso)
499+
return '', 200
500+
else:
501+
return '', 403
502+
503+
504+
@app.route('/vm/<string:vmid>/net/create', methods=['POST'])
505+
@auth.oidc_auth
506+
def create_net_interface(vmid):
507+
user = User(session['userinfo']['preferred_username'])
508+
connect_proxmox()
509+
if user.rtp or int(vmid) in user.allowed_vms:
510+
vm = VM(vmid)
511+
vm.create_net('virtio')
512+
return '', 200
513+
else:
514+
return '', 403
515+
516+
517+
@app.route('/vm/<string:vmid>/net/<string:netid>/delete', methods=['POST'])
518+
@auth.oidc_auth
519+
def delete_net_interface(vmid, netid):
520+
user = User(session['userinfo']['preferred_username'])
521+
connect_proxmox()
522+
if user.rtp or int(vmid) in user.allowed_vms:
523+
vm = VM(vmid)
524+
vm.delete_net(netid)
450525
return '', 200
451526
else:
452527
return '', 403

proxstar/static/js/script.js

Lines changed: 95 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -115,59 +115,14 @@ $("#resume-vm").click(function(){
115115
});
116116
});
117117

118-
$("#eject-iso").click(function(){
118+
$(".eject-iso").click(function(){
119119
const iso = $(this).data('iso');
120-
swal({
121-
title: `Are you sure you want to eject ${iso}?`,
122-
icon: "warning",
123-
buttons: {
124-
cancel: {
125-
text: "Cancel",
126-
visible: true,
127-
closeModal: true,
128-
className: "",
129-
},
130-
eject: {
131-
text: "Eject",
132-
closeModal: false,
133-
className: "swal-button--danger",
134-
}
135-
},
136-
dangerMode: true,
137-
})
138-
.then((willEject) => {
139-
if (willEject) {
140-
const vmid = $(this).data('vmid');
141-
fetch(`/vm/${vmid}/eject`, {
142-
credentials: 'same-origin',
143-
method: 'post'
144-
}).then((response) => {
145-
return swal(`${iso} is now ejecting!`, {
146-
icon: "success",
147-
buttons: {
148-
ok: {
149-
text: "OK",
150-
closeModal: true,
151-
className: "",
152-
}
153-
}
154-
});
155-
}).then(() => {
156-
window.location = `/vm/${vmid}`;
157-
}).catch(err => {
158-
if (err) {
159-
swal("Uh oh...", `Unable to eject ${iso}. Please try again later.`, "error");
160-
} else {
161-
swal.stopLoading();
162-
swal.close();
163-
}
164-
});
165-
}
166-
});
120+
const vmid = $(this).data('vmid');
121+
confirmDialog(`/vm/${vmid}/iso/${iso}/eject`, `Are you sure you want to eject this ISO?`, "Eject", `Ejecting ISO!`, `Unable to eject ISO. Please try again later.`, `/vm/${vmid}`)
167122
});
168123

169124

170-
$("#change-iso").click(function(){
125+
$(".change-iso").click(function(){
171126
fetch(`/isos`, {
172127
credentials: 'same-origin',
173128
}).then((response) => {
@@ -197,8 +152,9 @@ $("#change-iso").click(function(){
197152
.then((willChange) => {
198153
if (willChange) {
199154
const vmid = $(this).data('vmid');
155+
const iso_drive = $(this).data('iso');
200156
const iso = $(iso_list).val();
201-
fetch(`/vm/${vmid}/mount/${iso}`, {
157+
fetch(`/vm/${vmid}/iso/${iso_drive}/mount/${iso}`, {
202158
credentials: 'same-origin',
203159
method: 'post'
204160
}).then((response) => {
@@ -861,7 +817,7 @@ $(".resize-disk").click(function(){
861817
.then((size) => {
862818
if (size) {
863819
if ((parseInt(usage) + parseInt(size)) <= parseInt(limit)) {
864-
fetch(`/vm/${vmid}/disk/${disk}/${size}`, {
820+
fetch(`/vm/${vmid}/disk/${disk}/resize/${size}`, {
865821
credentials: 'same-origin',
866822
method: 'post'
867823
}).then((response) => {
@@ -1110,3 +1066,91 @@ $(document).on('focus click', "[id^=boot-order-]", function() {
11101066
}
11111067
});
11121068
});
1069+
1070+
$("#create-net").click(function(){
1071+
const vmid = $(this).data('vmid')
1072+
confirmDialog(`/vm/${vmid}/net/create`, `Are you sure you want to create a new interface?`, "Create", `Creating new interface!`, `Unable to create interface. Please try again later.`, `/vm/${vmid}`)
1073+
});
1074+
1075+
$(".delete-net").click(function(){
1076+
const vmid = $(this).data('vmid')
1077+
const interface = $(this).data('interface')
1078+
confirmDialog(`/vm/${vmid}/net/${interface}/delete`, `Are you sure you want to delete ${interface}?`, "Delete", `Deleting ${interface}!`, `Unable to delete interface. Please try again later.`, `/vm/${vmid}`)
1079+
});
1080+
1081+
$("#create-iso").click(function(){
1082+
const vmid = $(this).data('vmid')
1083+
confirmDialog(`/vm/${vmid}/iso/create`, `Are you sure you want to create a new ISO drive?`, "Create", `Creating new ISO drive!`, `Unable to create ISO drive. Please try again later.`, `/vm/${vmid}`)
1084+
});
1085+
1086+
$(".delete-iso").click(function(){
1087+
const vmid = $(this).data('vmid')
1088+
const iso = $(this).data('iso')
1089+
confirmDialog(`/vm/${vmid}/iso/${iso}/delete`, `Are you sure you want to delete ${iso}?`, "Delete", `Deleting ${iso}!`, `Unable to delete ISO drive. Please try again later.`, `/vm/${vmid}`)
1090+
});
1091+
1092+
$("#create-disk").click(function(){
1093+
const vmid = $(this).data('vmid');
1094+
const disk = $(this).data('disk');
1095+
const usage = $(this).data('usage');
1096+
const limit = $(this).data('limit');
1097+
swal({
1098+
title: 'Enter how many GB you would like to make this disk:',
1099+
content: {
1100+
element: 'input',
1101+
attributes: {
1102+
type: 'number',
1103+
},
1104+
},
1105+
buttons: {
1106+
cancel: {
1107+
text: "Cancel",
1108+
visible: true,
1109+
closeModal: true,
1110+
className: "",
1111+
},
1112+
confirm: {
1113+
text: "Select",
1114+
closeModal: false,
1115+
}
1116+
},
1117+
})
1118+
.then((size) => {
1119+
if (size) {
1120+
if ((parseInt(usage) + parseInt(size)) <= parseInt(limit)) {
1121+
fetch(`/vm/${vmid}/disk/create/${size}`, {
1122+
credentials: 'same-origin',
1123+
method: 'post'
1124+
}).then((response) => {
1125+
return swal(`Disk has been created!`, {
1126+
icon: "success",
1127+
buttons: {
1128+
ok: {
1129+
text: "OK",
1130+
closeModal: true,
1131+
className: "",
1132+
}
1133+
}
1134+
});
1135+
}).then(() => {
1136+
window.location = `/vm/${vmid}`;
1137+
});
1138+
} else {
1139+
swal("Uh oh...", `You don't have enough disk resources! Try again with a smaller size.`, "error");
1140+
}
1141+
}
1142+
}).catch(err => {
1143+
if (err) {
1144+
swal("Uh oh...", `Unable to create the disk. Please try again later.`, "error");
1145+
} else {
1146+
swal.stopLoading();
1147+
swal.close();
1148+
}
1149+
});
1150+
});
1151+
1152+
$(".delete-disk").click(function(){
1153+
const vmid = $(this).data('vmid')
1154+
const disk = $(this).data('disk')
1155+
confirmDialog(`/vm/${vmid}/disk/${disk}/delete`, `Are you sure you want to delete ${disk}?`, "Delete", `Deleting ${disk}!`, `Unable to delete disk. Please try again later.`, `/vm/${vmid}`)
1156+
});

proxstar/templates/vm_details.html

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,56 @@ <h3 class="card-title">Resources</h3>
1919
</li>
2020
<li class="nav-header">Interfaces</li>
2121
{% for interface in vm.interfaces %}
22-
<li>{{ interface[0] }}: {{ interface[2] }}</li>
22+
<li>{{ interface[0] }}: {{ interface[2] }}
23+
<button class="btn btn-danger proxstar-vmbtn delete-net" id="delete-net" name="delete" data-vmid="{{ vm.id }}" data-interface="{{ interface[0] }}">
24+
<i class="fas fa-trash"></i>
25+
</button>
26+
</li>
2327
{% endfor %}
24-
<li class="nav-header">Disks</li>
28+
<li>
29+
<button class="btn btn-success proxstar-vmbtn" id="create-net" name="create" data-vmid="{{ vm.id }}">
30+
<i class="fas fa-plus"></i>
31+
</button>
32+
</li>
33+
<li class="nav-header">Disks</li>
2534
{% for disk in vm.disks %}
2635
<li>
2736
{{ disk[0] }}: {{ disk[1] }}GB
2837
<button class="btn btn-default proxstar-vmbtn resize-disk" id="resize-disk" name="resize" data-vmid="{{ vm.id }}" data-disk="{{ disk[0] }}" data-usage="{{ usage['disk'] }}" data-limit="{{ limits['disk'] }}">
2938
<i class="fas fa-cog"></i>
3039
</button>
40+
<button class="btn btn-danger proxstar-vmbtn delete-disk" id="delete-disk" name="delete" data-vmid="{{ vm.id }}" data-disk="{{ disk[0] }}">
41+
<i class="fas fa-trash"></i>
42+
</button>
3143
</li>
44+
<li>
45+
<button class="btn btn-success proxstar-vmbtn" id="create-disk" name="create" data-vmid="{{ vm.id }}" data-usage="{{ usage['disk'] }}" data-limit="{{ limits['disk'] }}">
46+
<i class="fas fa-plus"></i>
47+
</button>
48+
</li>
3249
{% endfor %}
3350
<li class="nav-header">ISO</li>
34-
<li>
35-
{{ vm.iso }}
36-
{% if vm.iso != 'None' %}
37-
<button class="btn btn-danger proxstar-vmbtn" id="eject-iso" name="eject" data-vmid="{{ vm.id }}" data-iso="{{ vm.iso }}">
51+
{% for iso in vm.isos %}
52+
<li>
53+
{{iso[0]}}: {{iso[1]}}
54+
<button class="btn btn-default proxstar-vmbtn change-iso" id="change-iso" name="change" data-vmid="{{ vm.id }}" data-iso="{{ iso[0] }}">
55+
<i class="fas fa-cog"></i>
56+
</button>
57+
{% if iso[1] != 'None' %}
58+
<button class="btn btn-warning proxstar-vmbtn eject-iso" id="eject-iso" name="eject" data-vmid="{{ vm.id }}" data-iso="{{ iso[0] }}">
3859
<i class="fas fa-eject"></i>
3960
</button>
4061
{% endif %}
41-
<button class="btn btn-default proxstar-vmbtn" id="change-iso" name="change" data-vmid="{{ vm.id }}" data-iso="{{ vm.iso }}">
42-
<i class="fas fa-cog"></i>
43-
</button>
62+
<button class="btn btn-danger proxstar-vmbtn delete-iso" id="delete-iso" name="delete" data-vmid="{{ vm.id }}" data-iso="{{ iso[0] }}">
63+
<i class="fas fa-trash"></i>
64+
</button>
4465
</li>
66+
{% endfor %}
67+
<li>
68+
<button class="btn btn-success proxstar-vmbtn" id="create-iso" name="create" data-vmid="{{ vm.id }}">
69+
<i class="fas fa-plus"></i>
70+
</button>
71+
</li>
4572
</ul>
4673
</div>
4774
</div>

0 commit comments

Comments
 (0)