Files
Virtnet.bond/extensions/Servers/Proxmox/Models/Node.php
Joseph.Rawlings 5f2e591c6e feat: add LXC container support to Proxmox extension
- Add is_lxc boolean column to ext_proxmox_nodes (default false, existing nodes unaffected)
- Add LXC checkbox to admin node creation form (disabled on edit)
- Dynamic API path selection via Node::vmType() (returns 'lxc' or 'qemu')
- LXC deployment: syncLxcSettings() for cores, memory, swap, hostname, rootfs, net config
- LXC network uses name=eth0 format with applyLxcPoolSettings() for VLAN/firewall/MTU
- All lifecycle operations LXC-aware: install, suspend, unsuspend, terminate, upgrade, reinstall
- VNC/xterm console uses correct type (lxc vs kvm)
- All 20+ Livewire components use vmType() for Proxmox API paths
- LXC user interface shows basic-only view (no advanced toggle, no KVM-specific tabs)
- Basic tabs for LXC: Overview, Network Configuration, Backups, Console
2026-03-02 07:11:25 -05:00

97 lines
2.5 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',
'is_lxc',
];
protected $casts = [
'is_lxc' => 'boolean',
];
/**
* Get the Proxmox API type path segment for this node (qemu or lxc).
*/
public function vmType(): string
{
return $this->is_lxc ? 'lxc' : 'qemu';
}
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;
}
}