|
|
@@ -10,6 +10,20 @@ function getStateClass(state) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+async function loadIsos() {
|
|
|
+ try {
|
|
|
+ const response = await fetch(`${API_BASE}/isos`);
|
|
|
+ const data = await response.json();
|
|
|
+ const select = document.getElementById('iso');
|
|
|
+ select.innerHTML = '<option value="">Select ISO</option>';
|
|
|
+ data.isos.forEach(iso => {
|
|
|
+ select.innerHTML += `<option value="${iso.path}">${iso.name}</option>`;
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error loading ISOs:', error);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
async function loadVMs() {
|
|
|
try {
|
|
|
const response = await fetch(`${API_BASE}/vms`);
|
|
|
@@ -35,6 +49,7 @@ async function loadVMs() {
|
|
|
tbody.appendChild(row);
|
|
|
select.innerHTML += `<option value="${vm.name}">${vm.name}</option>`;
|
|
|
});
|
|
|
+ loadIsos(); // Load ISOs after loading VMs
|
|
|
} catch (error) {
|
|
|
console.error('Error loading VMs:', error);
|
|
|
alert('Error loading VMs');
|
|
|
@@ -100,13 +115,18 @@ document.getElementById('createVMForm').addEventListener('submit', async (e) =>
|
|
|
const response = await fetch(`${API_BASE}/vms?name=${name}&memory=${memory}&disk_size=${disk_size}&iso=${iso}`, {
|
|
|
method: 'POST'
|
|
|
});
|
|
|
- const result = await response.json();
|
|
|
+ let result;
|
|
|
+ try {
|
|
|
+ result = await response.json();
|
|
|
+ } catch {
|
|
|
+ result = { error: 'Unknown error' };
|
|
|
+ }
|
|
|
if (response.ok) {
|
|
|
alert(result.message);
|
|
|
loadVMs();
|
|
|
document.getElementById('createVMForm').reset();
|
|
|
} else {
|
|
|
- alert(result.error);
|
|
|
+ alert(result.error || 'Error creating VM');
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error('Error creating VM:', error);
|
|
|
@@ -142,5 +162,35 @@ document.getElementById('setBootOrderForm').addEventListener('submit', async (e)
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+document.getElementById('uploadIsoForm').addEventListener('submit', async (e) => {
|
|
|
+ e.preventDefault();
|
|
|
+ const fileInput = document.getElementById('isoFile');
|
|
|
+ const file = fileInput.files[0];
|
|
|
+ if (!file) {
|
|
|
+ alert('Please select a file');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append('file', file);
|
|
|
+
|
|
|
+ try {
|
|
|
+ const response = await fetch(`${API_BASE}/upload-iso`, {
|
|
|
+ method: 'POST',
|
|
|
+ body: formData
|
|
|
+ });
|
|
|
+ const result = await response.json();
|
|
|
+ if (response.ok) {
|
|
|
+ alert(result.message);
|
|
|
+ loadIsos(); // Refresh ISO list
|
|
|
+ document.getElementById('uploadIsoForm').reset();
|
|
|
+ } else {
|
|
|
+ alert(result.error || 'Error uploading ISO');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error uploading ISO:', error);
|
|
|
+ alert('Error uploading ISO');
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
// Load VMs on page load
|
|
|
loadVMs();
|