Refactor VM provisioning pipeline into focused services and add IP pool

management
This commit is contained in:
baodev0
2026-05-29 12:03:35 +07:00
parent 6bb4a47bfb
commit 7ae237ee9d
32 changed files with 1170 additions and 1200 deletions
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace App\Services\VirtualMachine;
use App\Models\OrderItem;
class VmAddonResolver
{
/**
* @return array{cpu:int,ram:int,disk:int}
*/
public function resolve(OrderItem $item): array
{
$totals = ['cpu' => 0, 'ram' => 0, 'disk' => 0];
if (!$item->addons) {
return $totals;
}
foreach ($item->addons as $orderAddon) {
$addon = $orderAddon->addonItems;
if (!$addon) {
continue;
}
$name = strtolower(trim((string) $addon->name));
$qty = (int) $orderAddon->qty;
switch ($name) {
case 'cpu':
$totals['cpu'] += $qty;
break;
case 'ram':
$totals['ram'] += $qty;
break;
case 'disk':
case 'ssd':
$totals['disk'] += $qty;
break;
}
}
return $totals;
}
}