Skip to content

Commit

Permalink
Potential fix for disk resize timeout?
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwang401 committed Jan 30, 2024
1 parent 272f6c0 commit 486d019
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
24 changes: 12 additions & 12 deletions app/Repositories/Proxmox/Server/ProxmoxDiskRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

namespace Convoy\Repositories\Proxmox\Server;

use Convoy\Models\Server;
use Webmozart\Assert\Assert;
use Convoy\Enums\Server\DiskInterface;
use Convoy\Models\Server;
use Convoy\Repositories\Proxmox\ProxmoxRepository;
use Webmozart\Assert\Assert;

class ProxmoxDiskRepository extends ProxmoxRepository
{
public function resizeDisk(DiskInterface $disk, int $bytes)
{
Assert::isInstanceOf($this->server, Server::class);

$gigabytes = $bytes / 1073741824;
$kibibytes = floor($bytes / 1024);

$response = $this->getHttpClient()
->withUrlParameters([
'node' => $this->node->cluster,
'server' => $this->server->vmid,
])
->put('/api2/json/nodes/{node}/qemu/{server}/resize', [
'disk' => $disk->value,
'size' => "+{$gigabytes}G",
])
->json();
->withUrlParameters([
'node' => $this->node->cluster,
'server' => $this->server->vmid,
])
->put('/api2/json/nodes/{node}/qemu/{server}/resize', [
'disk' => $disk->value,
'size' => "{$kibibytes}K",
])
->json();

return $this->getData($response);
}
Expand Down
36 changes: 21 additions & 15 deletions app/Services/Servers/SyncBuildService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@

namespace Convoy\Services\Servers;

use Convoy\Models\Server;
use Illuminate\Support\Arr;
use Convoy\Enums\Server\DiskInterface;
use Convoy\Data\Server\Proxmox\Config\DiskData;
use Convoy\Repositories\Proxmox\Server\ProxmoxDiskRepository;
use Convoy\Repositories\Proxmox\Server\ProxmoxPowerRepository;
use Convoy\Enums\Server\DiskInterface;
use Convoy\Models\Server;
use Convoy\Repositories\Proxmox\Server\ProxmoxConfigRepository;
use Convoy\Repositories\Proxmox\Server\ProxmoxDiskRepository;
use Illuminate\Support\Arr;

class SyncBuildService
{
public function __construct(
private AllocationService $allocationService,
private CloudinitService $cloudinitService,
private NetworkService $networkService,
private ServerDetailService $detailService,
private ProxmoxPowerRepository $powerRepository,
private AllocationService $allocationService,
private CloudinitService $cloudinitService,
private NetworkService $networkService,
private ServerDetailService $detailService,
private ProxmoxConfigRepository $allocationRepository,
private ProxmoxDiskRepository $diskRepository,
) {
private ProxmoxDiskRepository $diskRepository,
)
{
}

public function handle(Server $server)
Expand All @@ -41,16 +40,23 @@ public function handle(Server $server)

// find a disk that has a corresponding disk in the deployment
$disksArray = collect($disks->toArray())->pluck('interface')->all();
$bootOrder = array_filter(collect($bootOrder->filter(fn (DiskData $disk) => ! $disk->is_media)->toArray())->pluck('interface')->toArray(), fn ($disk) => in_array($disk, $disksArray));
$bootOrder = array_filter(
collect($bootOrder->filter(fn (DiskData $disk) => !$disk->is_media)->toArray())->pluck(
'interface',
)->toArray(), fn ($disk) => in_array($disk, $disksArray),
);

if (count($bootOrder) > 0) {
/** @var DiskData $disk */
$disk = $disks->where('interface', '=', DiskInterface::from(Arr::first($bootOrder)))->first();
$disk = $disks->where('interface', '=', DiskInterface::from(Arr::first($bootOrder)))
->first();

$diff = $server->disk - $disk->size;

if ($diff > 0) {
$this->diskRepository->setServer($server)->resizeDisk($disk->interface, $diff);
$this->diskRepository->setServer($server)->resizeDisk(
$disk->interface, $server->disk,
);
}
}
}
Expand Down

0 comments on commit 486d019

Please sign in to comment.