Skip to content

Commit f53a991

Browse files
authored
Merge pull request #188 from jabbate19/master
Add more customization options
2 parents 95fbfce + 0f739ac commit f53a991

File tree

4 files changed

+313
-95
lines changed

4 files changed

+313
-95
lines changed

proxstar/__init__.py

Lines changed: 95 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,41 @@ def vm_mem(vmid, mem):
393393
return '', 403
394394

395395

396-
@app.route('/vm/<string:vmid>/disk/<string:disk>/<int:size>', methods=['POST'])
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+
412+
@app.route('/vm/<string:vmid>/disk/create/<int:size>', methods=['POST'])
413+
@auth.oidc_auth
414+
def create_disk(vmid, size):
415+
user = User(session['userinfo']['preferred_username'])
416+
connect_proxmox()
417+
if user.rtp or int(vmid) in user.allowed_vms:
418+
vm = VM(vmid)
419+
usage_check = user.check_usage(0, 0, size)
420+
if usage_check:
421+
return usage_check
422+
vm.create_disk(size)
423+
return '', 200
424+
else:
425+
return '', 403
426+
427+
428+
@app.route('/vm/<string:vmid>/disk/<string:disk>/resize/<int:size>', methods=['POST'])
397429
@auth.oidc_auth
398-
def vm_disk(vmid, disk, size):
430+
def resize_disk(vmid, disk, size):
399431
user = User(session['userinfo']['preferred_username'])
400432
connect_proxmox()
401433
if user.rtp or int(vmid) in user.allowed_vms:
@@ -409,44 +441,93 @@ def vm_disk(vmid, disk, size):
409441
return '', 403
410442

411443

412-
@app.route('/vm/<string:vmid>/renew', methods=['POST'])
444+
@app.route('/vm/<string:vmid>/disk/<string:disk>/delete', methods=['POST'])
413445
@auth.oidc_auth
414-
def vm_renew(vmid):
446+
def delete_disk(vmid, disk):
415447
user = User(session['userinfo']['preferred_username'])
416448
connect_proxmox()
417449
if user.rtp or int(vmid) in user.allowed_vms:
418450
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])
451+
vm.delete_disk(disk)
423452
return '', 200
424453
else:
425454
return '', 403
426455

427456

428-
@app.route('/vm/<string:vmid>/eject', methods=['POST'])
457+
@app.route('/vm/<string:vmid>/iso/create', methods=['POST'])
429458
@auth.oidc_auth
430-
def iso_eject(vmid):
459+
def iso_create(vmid):
431460
user = User(session['userinfo']['preferred_username'])
432461
connect_proxmox()
433462
if user.rtp or int(vmid) in user.allowed_vms:
434463
vm = VM(vmid)
435-
vm.eject_iso()
464+
vm.add_iso_drive()
436465
return '', 200
437466
else:
438467
return '', 403
439468

440469

441-
@app.route('/vm/<string:vmid>/mount/<string:iso>', methods=['POST'])
470+
@app.route('/vm/<string:vmid>/iso/<string:iso_drive>/delete', methods=['POST'])
442471
@auth.oidc_auth
443-
def iso_mount(vmid, iso):
472+
def iso_delete(vmid, iso_drive):
473+
user = User(session['userinfo']['preferred_username'])
474+
connect_proxmox()
475+
if user.rtp or int(vmid) in user.allowed_vms:
476+
vm = VM(vmid)
477+
vm.delete_iso_drive(iso_drive)
478+
return '', 200
479+
else:
480+
return '', 403
481+
482+
483+
@app.route('/vm/<string:vmid>/iso/<string:iso_drive>/eject', methods=['POST'])
484+
@auth.oidc_auth
485+
def iso_eject(vmid, iso_drive):
486+
user = User(session['userinfo']['preferred_username'])
487+
connect_proxmox()
488+
if user.rtp or int(vmid) in user.allowed_vms:
489+
vm = VM(vmid)
490+
vm.eject_iso(iso_drive)
491+
return '', 200
492+
else:
493+
return '', 403
494+
495+
496+
@app.route('/vm/<string:vmid>/iso/<string:iso_drive>/mount/<string:iso>', methods=['POST'])
497+
@auth.oidc_auth
498+
def iso_mount(vmid, iso_drive, iso):
444499
user = User(session['userinfo']['preferred_username'])
445500
connect_proxmox()
446501
if user.rtp or int(vmid) in user.allowed_vms:
447502
iso = '{}:iso/{}'.format(app.config['PROXMOX_ISO_STORAGE'], iso)
448503
vm = VM(vmid)
449-
vm.mount_iso(iso)
504+
vm.mount_iso(iso_drive, iso)
505+
return '', 200
506+
else:
507+
return '', 403
508+
509+
510+
@app.route('/vm/<string:vmid>/net/create', methods=['POST'])
511+
@auth.oidc_auth
512+
def create_net_interface(vmid):
513+
user = User(session['userinfo']['preferred_username'])
514+
connect_proxmox()
515+
if user.rtp or int(vmid) in user.allowed_vms:
516+
vm = VM(vmid)
517+
vm.create_net('virtio')
518+
return '', 200
519+
else:
520+
return '', 403
521+
522+
523+
@app.route('/vm/<string:vmid>/net/<string:netid>/delete', methods=['POST'])
524+
@auth.oidc_auth
525+
def delete_net_interface(vmid, netid):
526+
user = User(session['userinfo']['preferred_username'])
527+
connect_proxmox()
528+
if user.rtp or int(vmid) in user.allowed_vms:
529+
vm = VM(vmid)
530+
vm.delete_net(netid)
450531
return '', 200
451532
else:
452533
return '', 403

0 commit comments

Comments
 (0)