Files
Virtnet.bond/extensions/Servers/Proxmox/Models/Node.php
Joseph.Rawlings f394483daa feat: Update Proxmox extension with various improvements and bug fixes
- Change listStates method to accept nullable integer for limit parameter.
- Modify TechnitiumDns class to return structured error messages on failure.
- Enhance VNC and xterm popup routes with user authorization checks.
- Update backups view to improve loading states and add unique keys for dynamic elements.
- Refactor cloud-init view to ensure proper data binding and improve user experience.
- Add wire:key attributes to various elements in views for better Livewire performance.
- Improve error handling and user feedback in the firewall view.
- Update server overview and statistics views to handle potential null values gracefully.
- Add new migration files to extend database schema with user-set icons and notes for Proxmox nodes.
2026-02-23 17:23:01 -05:00

84 lines
2.2 KiB
PHP

<?php
namespace Paymenter\Extensions\Servers\Proxmox\Models;
use Illuminate\Database\Eloquent\Model;
class Node extends Model
{
protected $table = 'ext_proxmox_nodes';
protected $fillable = [
// Shows to customer
'name',
'notes',
'memory',
'disk',
'cpu',
'location_id',
'storage_location',
'backup_location',
'vnc_enabled',
];
public function servers()
{
return $this->hasMany(Server::class);
}
public function ipAddresses()
{
return $this->hasMany(IPAddress::class);
}
public function ipPools()
{
return $this->belongsToMany(IPPool::class, 'ext_proxmox_ip_pool_nodes', 'node_id', 'ip_pool_id');
}
public function location()
{
return $this->belongsTo(Location::class);
}
public function resourcesAvailable()
{
$servers = $this->servers()->with('service.product')->get();
$totalMemory = $this->memory;
$totalDisk = $this->disk;
$totalCpu = $this->cpu;
$usedMemory = 0;
$usedDisk = 0;
$usedCpu = 0;
foreach ($servers as $server) {
$usedMemory += (int) ($server->service->product->settings()->where('key', 'memory')->first()?->value ?? 0);
$usedDisk += (int) ($server->service->product->settings()->where('key', 'disk')->first()?->value ?? 0);
$usedCpu += (int) ($server->service->product->settings()->where('key', 'cpu')->first()?->value ?? 0);
}
return [
'memory' => $totalMemory == 0 ? null : $totalMemory - $usedMemory,
'disk' => $totalDisk == 0 ? null : $totalDisk - $usedDisk,
'cpu' => $totalCpu == 0 ? null : $totalCpu - $usedCpu,
];
}
public function canStoreServer($memory, $disk, $cpu)
{
$resources = $this->resourcesAvailable();
if ($resources['memory'] !== null && $resources['memory'] < $memory) {
return false;
}
if ($resources['disk'] !== null && $resources['disk'] < $disk) {
return false;
}
if ($resources['cpu'] !== null && $resources['cpu'] < $cpu) {
return false;
}
return true;
}
}