Enhance Proxmox components with input validation, error handling, and UI improvements
This commit is contained in:
@@ -376,7 +376,11 @@ class Proxmox extends ClassServer
|
||||
|
||||
public function getCheckoutConfig(Product $product)
|
||||
{
|
||||
$oses = Location::findOrFail($product->settings()->where('key', 'location_id')->first()->value)->os()->get();
|
||||
$locationSetting = $product->settings()->where('key', 'location_id')->first();
|
||||
if (!$locationSetting) {
|
||||
return [['name' => 'notice', 'type' => 'placeholder', 'label' => new \Illuminate\Support\HtmlString('<span class="text-red-500">Product is missing a location_id setting. Please contact support.</span>')]];
|
||||
}
|
||||
$oses = Location::findOrFail($locationSetting->value)->os()->get();
|
||||
|
||||
return [
|
||||
[
|
||||
@@ -442,8 +446,9 @@ class Proxmox extends ClassServer
|
||||
private function generateMacAddress(): string
|
||||
{
|
||||
$mac = [];
|
||||
$bytes = random_bytes(6);
|
||||
for ($i = 0; $i < 6; $i++) {
|
||||
$mac[] = str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT);
|
||||
$mac[] = str_pad(dechex(ord($bytes[$i])), 2, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
// Get the first octet as an integer
|
||||
@@ -527,13 +532,18 @@ class Proxmox extends ClassServer
|
||||
|
||||
// Get current disk type
|
||||
$disk = $this->request('/nodes/' . $server->node->name . '/qemu/' . $server->vm_id . '/config')->json()['data'] ?? [];
|
||||
// As the disk type can be different, we need to check if it is scsi or virtio or sata or ide
|
||||
$diskType = 'scsi0';
|
||||
if (isset($disk['virtio0'])) {
|
||||
$diskType = 'virtio0';
|
||||
} elseif (isset($disk['sata0'])) {
|
||||
$diskType = 'sata0';
|
||||
// Find the primary disk across all bus types and slot numbers
|
||||
$diskType = null;
|
||||
foreach (['scsi', 'virtio', 'sata', 'ide'] as $bus) {
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
$key = $bus . $i;
|
||||
if (isset($disk[$key]) && !str_contains($disk[$key], 'media=cdrom') && !str_contains(strtolower($disk[$key]), 'cloudinit')) {
|
||||
$diskType = $key;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
$diskType = $diskType ?? 'scsi0';
|
||||
|
||||
// Update disk
|
||||
$this->requestAndWait('/nodes/' . $server->node->name . '/qemu/' . $server->vm_id . '/resize', 'put', [
|
||||
@@ -788,7 +798,7 @@ class Proxmox extends ClassServer
|
||||
'verify' => $this->config('verify_ssl') ? true : false,
|
||||
])->post(rtrim($this->config('host'), '/') . '/api2/json/nodes/' . $server->node->name . '/qemu/' . $server->vm_id . '/vncproxy', [
|
||||
'websocket' => 1,
|
||||
])->json()['data'] ?? [];
|
||||
])->throw()->json()['data'] ?? [];
|
||||
|
||||
// Current
|
||||
$paymenterDomain = rtrim(config('settings.app_url'), '/');
|
||||
@@ -974,6 +984,16 @@ class Proxmox extends ClassServer
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($server->node) {
|
||||
try {
|
||||
$this->requestAndWait('/nodes/' . $server->node->name . '/qemu/' . $server->vm_id . '/status/start', 'post', [
|
||||
'vmid' => $server->vm_id,
|
||||
], $server->node->name);
|
||||
} catch (\Throwable $e) {
|
||||
\Log::warning('Failed to start VM on unsuspend', ['server' => $server->id, 'error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
$server->status = 'active';
|
||||
$server->save();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user