From 8fae5521bee0268c7bb4debad9ac50cb82513591 Mon Sep 17 00:00:00 2001 From: Joe Abbate Date: Fri, 27 Jan 2023 12:30:37 -0500 Subject: [PATCH 1/4] Add more customization options --- proxstar/__init__.py | 123 +++++++++++++++++++----- proxstar/static/js/script.js | 146 +++++++++++++++++++---------- proxstar/templates/vm_details.html | 45 +++++++-- proxstar/vm.py | 88 ++++++++++++++--- 4 files changed, 305 insertions(+), 97 deletions(-) diff --git a/proxstar/__init__.py b/proxstar/__init__.py index 7e3181a..5517b05 100644 --- a/proxstar/__init__.py +++ b/proxstar/__init__.py @@ -269,6 +269,7 @@ def vm_details(vmid): if user.rtp or int(vmid) in user.allowed_vms: vm = VM(vmid) usage_check = user.check_usage(vm.cpu, vm.mem, 0) + print(vm.boot_order) return render_template( 'vm_details.html', user=user, @@ -392,23 +393,6 @@ def vm_mem(vmid, mem): else: return '', 403 - -@app.route('/vm//disk//', methods=['POST']) -@auth.oidc_auth -def vm_disk(vmid, disk, size): - user = User(session['userinfo']['preferred_username']) - connect_proxmox() - if user.rtp or int(vmid) in user.allowed_vms: - vm = VM(vmid) - usage_check = user.check_usage(0, 0, size) - if usage_check: - return usage_check - vm.resize_disk(disk, size) - return '', 200 - else: - return '', 403 - - @app.route('/vm//renew', methods=['POST']) @auth.oidc_auth def vm_renew(vmid): @@ -424,29 +408,120 @@ def vm_renew(vmid): else: return '', 403 - -@app.route('/vm//eject', methods=['POST']) +@app.route('/vm//disk/create/', methods=['POST']) @auth.oidc_auth -def iso_eject(vmid): +def create_disk(vmid, size): user = User(session['userinfo']['preferred_username']) connect_proxmox() if user.rtp or int(vmid) in user.allowed_vms: vm = VM(vmid) - vm.eject_iso() + usage_check = user.check_usage(0, 0, size) + if usage_check: + return usage_check + vm.create_disk(size) + return '', 200 + else: + return '', 403 + +@app.route('/vm//disk//resize/', methods=['POST']) +@auth.oidc_auth +def resize_disk(vmid, disk, size): + user = User(session['userinfo']['preferred_username']) + connect_proxmox() + if user.rtp or int(vmid) in user.allowed_vms: + vm = VM(vmid) + usage_check = user.check_usage(0, 0, size) + if usage_check: + return usage_check + vm.resize_disk(disk, size) + return '', 200 + else: + return '', 403 + +@app.route('/vm//disk//delete', methods=['POST']) +@auth.oidc_auth +def delete_disk(vmid, disk): + user = User(session['userinfo']['preferred_username']) + connect_proxmox() + if user.rtp or int(vmid) in user.allowed_vms: + vm = VM(vmid) + vm.delete_disk(disk) + return '', 200 + else: + return '', 403 + +@app.route('/vm//iso/create', methods=['POST']) +@auth.oidc_auth +def iso_create(vmid): + user = User(session['userinfo']['preferred_username']) + connect_proxmox() + if user.rtp or int(vmid) in user.allowed_vms: + vm = VM(vmid) + vm.add_iso_drive() + return '', 200 + else: + return '', 403 + +@app.route('/vm//iso//delete', methods=['POST']) +@auth.oidc_auth +def iso_delete(vmid, iso_drive): + user = User(session['userinfo']['preferred_username']) + connect_proxmox() + if user.rtp or int(vmid) in user.allowed_vms: + vm = VM(vmid) + vm.delete_iso_drive(iso_drive) + return '', 200 + else: + return '', 403 + +@app.route('/vm//iso//eject', methods=['POST']) +@auth.oidc_auth +def iso_eject(vmid, iso_drive): + user = User(session['userinfo']['preferred_username']) + connect_proxmox() + if user.rtp or int(vmid) in user.allowed_vms: + vm = VM(vmid) + vm.eject_iso(iso_drive) return '', 200 else: return '', 403 -@app.route('/vm//mount/', methods=['POST']) +@app.route('/vm//iso//mount/', methods=['POST']) @auth.oidc_auth -def iso_mount(vmid, iso): +def iso_mount(vmid, iso_drive, iso): user = User(session['userinfo']['preferred_username']) connect_proxmox() if user.rtp or int(vmid) in user.allowed_vms: iso = '{}:iso/{}'.format(app.config['PROXMOX_ISO_STORAGE'], iso) vm = VM(vmid) - vm.mount_iso(iso) + vm.mount_iso(iso_drive, iso) + return '', 200 + else: + return '', 403 + + +@app.route('/vm//net/create', methods=['POST']) +@auth.oidc_auth +def create_net_interface(vmid): + user = User(session['userinfo']['preferred_username']) + connect_proxmox() + if user.rtp or int(vmid) in user.allowed_vms: + vm = VM(vmid) + vm.create_net('virtio') + return '', 200 + else: + return '', 403 + + +@app.route('/vm//net//delete', methods=['POST']) +@auth.oidc_auth +def delete_net_interface(vmid, netid): + user = User(session['userinfo']['preferred_username']) + connect_proxmox() + if user.rtp or int(vmid) in user.allowed_vms: + vm = VM(vmid) + vm.delete_net(netid) return '', 200 else: return '', 403 diff --git a/proxstar/static/js/script.js b/proxstar/static/js/script.js index 0d9cdd5..0d1b9d5 100644 --- a/proxstar/static/js/script.js +++ b/proxstar/static/js/script.js @@ -115,59 +115,14 @@ $("#resume-vm").click(function(){ }); }); -$("#eject-iso").click(function(){ +$(".eject-iso").click(function(){ const iso = $(this).data('iso'); - swal({ - title: `Are you sure you want to eject ${iso}?`, - icon: "warning", - buttons: { - cancel: { - text: "Cancel", - visible: true, - closeModal: true, - className: "", - }, - eject: { - text: "Eject", - closeModal: false, - className: "swal-button--danger", - } - }, - dangerMode: true, - }) - .then((willEject) => { - if (willEject) { - const vmid = $(this).data('vmid'); - fetch(`/vm/${vmid}/eject`, { - credentials: 'same-origin', - method: 'post' - }).then((response) => { - return swal(`${iso} is now ejecting!`, { - icon: "success", - buttons: { - ok: { - text: "OK", - closeModal: true, - className: "", - } - } - }); - }).then(() => { - window.location = `/vm/${vmid}`; - }).catch(err => { - if (err) { - swal("Uh oh...", `Unable to eject ${iso}. Please try again later.`, "error"); - } else { - swal.stopLoading(); - swal.close(); - } - }); - } - }); + const vmid = $(this).data('vmid'); + 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}`) }); -$("#change-iso").click(function(){ +$(".change-iso").click(function(){ fetch(`/isos`, { credentials: 'same-origin', }).then((response) => { @@ -197,8 +152,9 @@ $("#change-iso").click(function(){ .then((willChange) => { if (willChange) { const vmid = $(this).data('vmid'); + const iso_drive = $(this).data('iso'); const iso = $(iso_list).val(); - fetch(`/vm/${vmid}/mount/${iso}`, { + fetch(`/vm/${vmid}/iso/${iso_drive}/mount/${iso}`, { credentials: 'same-origin', method: 'post' }).then((response) => { @@ -861,7 +817,7 @@ $(".resize-disk").click(function(){ .then((size) => { if (size) { if ((parseInt(usage) + parseInt(size)) <= parseInt(limit)) { - fetch(`/vm/${vmid}/disk/${disk}/${size}`, { + fetch(`/vm/${vmid}/disk/${disk}/resize/${size}`, { credentials: 'same-origin', method: 'post' }).then((response) => { @@ -1110,3 +1066,91 @@ $(document).on('focus click', "[id^=boot-order-]", function() { } }); }); + +$("#create-net").click(function(){ + const vmid = $(this).data('vmid') + 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}`) +}); + +$(".delete-net").click(function(){ + const vmid = $(this).data('vmid') + const interface = $(this).data('interface') + 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}`) +}); + +$("#create-iso").click(function(){ + const vmid = $(this).data('vmid') + 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}`) +}); + +$(".delete-iso").click(function(){ + const vmid = $(this).data('vmid') + const iso = $(this).data('iso') + 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}`) +}); + +$("#create-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 make this disk:', + content: { + element: 'input', + attributes: { + type: 'number', + }, + }, + buttons: { + cancel: { + text: "Cancel", + visible: true, + closeModal: true, + className: "", + }, + confirm: { + text: "Select", + closeModal: false, + } + }, + }) + .then((size) => { + if (size) { + if ((parseInt(usage) + parseInt(size)) <= parseInt(limit)) { + fetch(`/vm/${vmid}/disk/create/${size}`, { + credentials: 'same-origin', + method: 'post' + }).then((response) => { + return swal(`Disk has been created!`, { + 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 create the disk. Please try again later.`, "error"); + } else { + swal.stopLoading(); + swal.close(); + } + }); +}); + +$(".delete-disk").click(function(){ + const vmid = $(this).data('vmid') + const disk = $(this).data('disk') + 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}`) +}); \ No newline at end of file diff --git a/proxstar/templates/vm_details.html b/proxstar/templates/vm_details.html index 6dd2861..ee191f4 100644 --- a/proxstar/templates/vm_details.html +++ b/proxstar/templates/vm_details.html @@ -19,29 +19,56 @@ {% for interface in vm.interfaces %} -
  • {{ interface[0] }}: {{ interface[2] }}
  • +
  • {{ interface[0] }}: {{ interface[2] }} + +
  • {% endfor %} - +
  • + +
  • + {% for disk in vm.disks %}
  • {{ disk[0] }}: {{ disk[1] }}GB +
  • +
  • + +
  • {% endfor %} -
  • - {{ vm.iso }} - {% if vm.iso != 'None' %} - + {% if iso[1] != 'None' %} + {% endif %} - +
  • + {% endfor %} +
  • + +
  • diff --git a/proxstar/vm.py b/proxstar/vm.py index 30624a0..d73b147 100644 --- a/proxstar/vm.py +++ b/proxstar/vm.py @@ -210,6 +210,32 @@ class VM: interfaces = sorted(interfaces, key=lambda x: x[0]) return interfaces + @retry(wait=wait_fixed(2), stop=stop_after_attempt(5)) + def create_net(self, int_type): + valid_int_types = ['virtio', 'e1000', 'rtl8139', 'vmxnet3'] + if int_type not in valid_int_types: + return False + i = 0 + while True: + name = f'net{i}' + if name not in self.config: + proxmox=connect_proxmox() + try: + proxmox.nodes(self.node).qemu(self.id).config.post(**{name: int_type}) + return True + except Exception as e: + print(e) + raise e + i += 1 + + @retry(wait=wait_fixed(2), stop=stop_after_attempt(5)) + def delete_net(self, net_id): + if net_id in self.config: + proxmox=connect_proxmox() + proxmox.nodes(self.node).qemu(self.id).config.post(delete=net_id) + return True + return False + def get_mac(self, interface='net0'): mac = self.config[interface].split(',') if 'virtio' in mac[0]: @@ -252,30 +278,66 @@ class VM: return cdroms @lazy_property - def iso(self): - if self.config.get('ide2'): - if self.config['ide2'].split(',')[0] == 'none': - iso = 'None' + def isos(self): + isos = [] + for iso in filter(lambda interface: 'ide' in interface, self.config.keys()): + iso_info = self.config[iso] + if iso_info: + if iso_info.split(',')[0] == 'none': + isos.append((iso, 'None')) + else: + isos.append((iso, iso_info.split(',')[0].split('/')[1])) else: - iso = self.config['ide2'].split(',')[0].split('/')[1] - else: - iso = 'None' - return iso + isos.append((iso, 'None')) + return isos @retry(wait=wait_fixed(2), stop=stop_after_attempt(5)) - def eject_iso(self): - proxmox = connect_proxmox() - proxmox.nodes(self.node).qemu(self.id).config.post(ide2='none,media=cdrom') + def add_iso_drive(self): + iso_drives = list(filter(lambda interface: 'ide' in interface, self.config.keys())) + for i in range(1,5): + ide_name = f'ide{i}' + if ide_name not in iso_drives: + proxmox = connect_proxmox() + proxmox.nodes(self.node).qemu(self.id).config.post(**{ide_name:'none,media=cdrom'}) + return True + return False @retry(wait=wait_fixed(2), stop=stop_after_attempt(5)) - def mount_iso(self, iso): + def delete_iso_drive(self, iso_drive): proxmox = connect_proxmox() - proxmox.nodes(self.node).qemu(self.id).config.post(ide2='{},media=cdrom'.format(iso)) + proxmox.nodes(self.node).qemu(self.id).config.post(delete=iso_drive) + @retry(wait=wait_fixed(2), stop=stop_after_attempt(5)) + def eject_iso(self, iso_drive): + proxmox = connect_proxmox() + proxmox.nodes(self.node).qemu(self.id).config.post(**{iso_drive:'none,media=cdrom'}) + + @retry(wait=wait_fixed(2), stop=stop_after_attempt(5)) + def mount_iso(self, iso_drive, iso): + proxmox = connect_proxmox() + proxmox.nodes(self.node).qemu(self.id).config.post(**{iso_drive:'{},media=cdrom'.format(iso)}) + + @retry(wait=wait_fixed(2), stop=stop_after_attempt(5)) + def create_disk(self, size): + drives = list(filter(lambda interface: 'virtio' in interface, self.config.keys())) + for i in range(0,16): + disk_name = f'virtio{i}' + if disk_name not in drives: + proxmox = connect_proxmox() + proxmox.nodes(self.node).qemu(self.id).config.post(**{disk_name:f'ceph:{size}'}) + return True + return False + + @retry(wait=wait_fixed(2), stop=stop_after_attempt(5)) def resize_disk(self, disk, size): proxmox = connect_proxmox() proxmox.nodes(self.node).qemu(self.id).resize.put(disk=disk, size='+{}G'.format(size)) + @retry(wait=wait_fixed(2), stop=stop_after_attempt(5)) + def delete_disk(self, disk): + proxmox = connect_proxmox() + proxmox.nodes(self.node).qemu(self.id).config.post(delete=disk) + @lazy_property def expire(self): return get_vm_expire(db, self.id, app.config['VM_EXPIRE_MONTHS']) From 36e2a6c687f8cf3ed412695fb7653834fa40fdbf Mon Sep 17 00:00:00 2001 From: Joe Abbate Date: Fri, 27 Jan 2023 12:51:57 -0500 Subject: [PATCH 2/4] Linting --- proxstar/__init__.py | 7 +++++++ proxstar/vm.py | 18 ++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/proxstar/__init__.py b/proxstar/__init__.py index 5517b05..cf9e67c 100644 --- a/proxstar/__init__.py +++ b/proxstar/__init__.py @@ -393,6 +393,7 @@ def vm_mem(vmid, mem): else: return '', 403 + @app.route('/vm//renew', methods=['POST']) @auth.oidc_auth def vm_renew(vmid): @@ -408,6 +409,7 @@ def vm_renew(vmid): else: return '', 403 + @app.route('/vm//disk/create/', methods=['POST']) @auth.oidc_auth def create_disk(vmid, size): @@ -423,6 +425,7 @@ def create_disk(vmid, size): else: return '', 403 + @app.route('/vm//disk//resize/', methods=['POST']) @auth.oidc_auth def resize_disk(vmid, disk, size): @@ -438,6 +441,7 @@ def resize_disk(vmid, disk, size): else: return '', 403 + @app.route('/vm//disk//delete', methods=['POST']) @auth.oidc_auth def delete_disk(vmid, disk): @@ -450,6 +454,7 @@ def delete_disk(vmid, disk): else: return '', 403 + @app.route('/vm//iso/create', methods=['POST']) @auth.oidc_auth def iso_create(vmid): @@ -462,6 +467,7 @@ def iso_create(vmid): else: return '', 403 + @app.route('/vm//iso//delete', methods=['POST']) @auth.oidc_auth def iso_delete(vmid, iso_drive): @@ -474,6 +480,7 @@ def iso_delete(vmid, iso_drive): else: return '', 403 + @app.route('/vm//iso//eject', methods=['POST']) @auth.oidc_auth def iso_eject(vmid, iso_drive): diff --git a/proxstar/vm.py b/proxstar/vm.py index d73b147..76234e3 100644 --- a/proxstar/vm.py +++ b/proxstar/vm.py @@ -219,7 +219,7 @@ class VM: while True: name = f'net{i}' if name not in self.config: - proxmox=connect_proxmox() + proxmox = connect_proxmox() try: proxmox.nodes(self.node).qemu(self.id).config.post(**{name: int_type}) return True @@ -231,7 +231,7 @@ class VM: @retry(wait=wait_fixed(2), stop=stop_after_attempt(5)) def delete_net(self, net_id): if net_id in self.config: - proxmox=connect_proxmox() + proxmox = connect_proxmox() proxmox.nodes(self.node).qemu(self.id).config.post(delete=net_id) return True return False @@ -294,11 +294,11 @@ class VM: @retry(wait=wait_fixed(2), stop=stop_after_attempt(5)) def add_iso_drive(self): iso_drives = list(filter(lambda interface: 'ide' in interface, self.config.keys())) - for i in range(1,5): + for i in range(1, 5): ide_name = f'ide{i}' if ide_name not in iso_drives: proxmox = connect_proxmox() - proxmox.nodes(self.node).qemu(self.id).config.post(**{ide_name:'none,media=cdrom'}) + proxmox.nodes(self.node).qemu(self.id).config.post(**{ide_name: 'none,media=cdrom'}) return True return False @@ -310,21 +310,23 @@ class VM: @retry(wait=wait_fixed(2), stop=stop_after_attempt(5)) def eject_iso(self, iso_drive): proxmox = connect_proxmox() - proxmox.nodes(self.node).qemu(self.id).config.post(**{iso_drive:'none,media=cdrom'}) + proxmox.nodes(self.node).qemu(self.id).config.post(**{iso_drive: 'none,media=cdrom'}) @retry(wait=wait_fixed(2), stop=stop_after_attempt(5)) def mount_iso(self, iso_drive, iso): proxmox = connect_proxmox() - proxmox.nodes(self.node).qemu(self.id).config.post(**{iso_drive:'{},media=cdrom'.format(iso)}) + proxmox.nodes(self.node).qemu(self.id).config.post( + **{iso_drive: '{},media=cdrom'.format(iso)} + ) @retry(wait=wait_fixed(2), stop=stop_after_attempt(5)) def create_disk(self, size): drives = list(filter(lambda interface: 'virtio' in interface, self.config.keys())) - for i in range(0,16): + for i in range(0, 16): disk_name = f'virtio{i}' if disk_name not in drives: proxmox = connect_proxmox() - proxmox.nodes(self.node).qemu(self.id).config.post(**{disk_name:f'ceph:{size}'}) + proxmox.nodes(self.node).qemu(self.id).config.post(**{disk_name: f'ceph:{size}'}) return True return False From 609453633449228135779831e9c2e7cbea1e22e9 Mon Sep 17 00:00:00 2001 From: Joe Abbate Date: Fri, 27 Jan 2023 12:52:59 -0500 Subject: [PATCH 3/4] Oops debug statement --- proxstar/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/proxstar/__init__.py b/proxstar/__init__.py index cf9e67c..cd52971 100644 --- a/proxstar/__init__.py +++ b/proxstar/__init__.py @@ -269,7 +269,6 @@ def vm_details(vmid): if user.rtp or int(vmid) in user.allowed_vms: vm = VM(vmid) usage_check = user.check_usage(vm.cpu, vm.mem, 0) - print(vm.boot_order) return render_template( 'vm_details.html', user=user, From 0f739ac8e4edc0b40e9dfe5121ef7706a499e45a Mon Sep 17 00:00:00 2001 From: Joe Abbate Date: Fri, 27 Jan 2023 14:04:46 -0500 Subject: [PATCH 4/4] UI Changes --- proxstar/static/js/script.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/proxstar/static/js/script.js b/proxstar/static/js/script.js index 0d1b9d5..6f61324 100644 --- a/proxstar/static/js/script.js +++ b/proxstar/static/js/script.js @@ -4,7 +4,7 @@ $(document).ready(function(){ $('[data-toggle="tooltip"]').tooltip(); }); -function confirmDialog(url, confirm, confirmButton, complete, error, location) { +function confirmDialog(url, confirm, confirmButton, complete, error, location, danger) { swal({ title: confirm, icon: "warning", @@ -13,7 +13,7 @@ function confirmDialog(url, confirm, confirmButton, complete, error, location) { action: { text: confirmButton, closeModal: false, - className: "swal-button--danger", + className: danger ? "swal-button--danger" : "swal-button--confirm", } }, dangerMode: true, @@ -44,31 +44,31 @@ function confirmDialog(url, confirm, confirmButton, complete, error, location) { $("#delete-vm").click(function(){ const vmname = $(this).data('vmname'); const vmid = $(this).data('vmid') - confirmDialog(`/vm/${vmid}/delete`, `Are you sure you want to delete ${vmname}?`, "Delete", `${vmname} is now being deleted.`, `Unable to delete ${vmname}. Please try again later.`, '/') + confirmDialog(`/vm/${vmid}/delete`, `Are you sure you want to delete ${vmname}?`, "Delete", `${vmname} is now being deleted.`, `Unable to delete ${vmname}. Please try again later.`, '/', true) }); $("#stop-vm").click(function(){ const vmname = $(this).data('vmname'); const vmid = $(this).data('vmid') - confirmDialog(`/vm/${vmid}/power/stop`, `Are you sure you want to stop ${vmname}?`, "Stop", `${vmname} is now stopping!`, `Unable to stop ${vmname}. Please try again later.`, `/vm/${vmid}`) + confirmDialog(`/vm/${vmid}/power/stop`, `Are you sure you want to stop ${vmname}?`, "Stop", `${vmname} is now stopping!`, `Unable to stop ${vmname}. Please try again later.`, `/vm/${vmid}`, true) }); $("#reset-vm").click(function(){ const vmname = $(this).data('vmname'); const vmid = $(this).data('vmid') - confirmDialog(`/vm/${vmid}/power/reset`, `Are you sure you want to reset ${vmname}?`, "Reset", `${vmname} is now resetting!`, `Unable to reset ${vmname}. Please try again later.`, `/vm/${vmid}`) + confirmDialog(`/vm/${vmid}/power/reset`, `Are you sure you want to reset ${vmname}?`, "Reset", `${vmname} is now resetting!`, `Unable to reset ${vmname}. Please try again later.`, `/vm/${vmid}`, true) }); $("#shutdown-vm").click(function(){ const vmname = $(this).data('vmname'); const vmid = $(this).data('vmid') - confirmDialog(`/vm/${vmid}/power/shutdown`, `Are you sure you want to shutdown ${vmname}?`, "Shutdown", `${vmname} is now shutting down!`, `Unable to shutdown ${vmname}. Please try again later.`, `/vm/${vmid}`) + confirmDialog(`/vm/${vmid}/power/shutdown`, `Are you sure you want to shutdown ${vmname}?`, "Shutdown", `${vmname} is now shutting down!`, `Unable to shutdown ${vmname}. Please try again later.`, `/vm/${vmid}`, true) }); $("#suspend-vm").click(function(){ const vmname = $(this).data('vmname'); const vmid = $(this).data('vmid') - confirmDialog(`/vm/${vmid}/power/suspend`, `Are you sure you want to suspend ${vmname}?`, "Suspend", `${vmname} is now suspending!`, `Unable to suspend ${vmname}. Please try again later.`, `/vm/${vmid}`) + confirmDialog(`/vm/${vmid}/power/suspend`, `Are you sure you want to suspend ${vmname}?`, "Suspend", `${vmname} is now suspending!`, `Unable to suspend ${vmname}. Please try again later.`, `/vm/${vmid}`, true) }); $("#start-vm").click(function(){ @@ -118,7 +118,7 @@ $("#resume-vm").click(function(){ $(".eject-iso").click(function(){ const iso = $(this).data('iso'); const vmid = $(this).data('vmid'); - 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}`) + 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}`, true) }); @@ -794,7 +794,8 @@ $(".resize-disk").click(function(){ const usage = $(this).data('usage'); const limit = $(this).data('limit'); swal({ - title: 'Enter how many GB you would like to expand this disk by:', + title: 'Expand Disk', + text: 'Enter how many GB you would like to expand this disk by (GB)', content: { element: 'input', attributes: { @@ -809,7 +810,7 @@ $(".resize-disk").click(function(){ className: "", }, confirm: { - text: "Select", + text: "Expand", closeModal: false, } }, @@ -1069,24 +1070,24 @@ $(document).on('focus click', "[id^=boot-order-]", function() { $("#create-net").click(function(){ const vmid = $(this).data('vmid') - 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}`) + 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}`, false) }); $(".delete-net").click(function(){ const vmid = $(this).data('vmid') const interface = $(this).data('interface') - 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}`) + 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}`, true) }); $("#create-iso").click(function(){ const vmid = $(this).data('vmid') - 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}`) + 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}`, false) }); $(".delete-iso").click(function(){ const vmid = $(this).data('vmid') const iso = $(this).data('iso') - 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}`) + 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}`, true) }); $("#create-disk").click(function(){ @@ -1095,7 +1096,8 @@ $("#create-disk").click(function(){ const usage = $(this).data('usage'); const limit = $(this).data('limit'); swal({ - title: 'Enter how many GB you would like to make this disk:', + title: 'Create New Disk', + text: 'Enter new disk size (GB)', content: { element: 'input', attributes: { @@ -1110,7 +1112,7 @@ $("#create-disk").click(function(){ className: "", }, confirm: { - text: "Select", + text: "Create", closeModal: false, } }, @@ -1152,5 +1154,5 @@ $("#create-disk").click(function(){ $(".delete-disk").click(function(){ const vmid = $(this).data('vmid') const disk = $(this).data('disk') - 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}`) + 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}`, true) }); \ No newline at end of file