Refactor VM provisioning pipeline into focused services and add IP pool
management
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user