Add all files
This commit is contained in:
36
extensions/Servers/Proxmox/Models/IPAddress.php
Normal file
36
extensions/Servers/Proxmox/Models/IPAddress.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Servers\Proxmox\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class IPAddress extends Model
|
||||
{
|
||||
protected $table = 'ext_proxmox_ip_addresses';
|
||||
|
||||
protected $fillable = [
|
||||
'ip',
|
||||
'gateway',
|
||||
'bridge',
|
||||
'netmask',
|
||||
'mac_address',
|
||||
'server_id',
|
||||
'type',
|
||||
'ip_pool_id',
|
||||
'subdomain',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'subdomain' => 'array',
|
||||
];
|
||||
|
||||
public function server()
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
||||
public function ipPool()
|
||||
{
|
||||
return $this->belongsTo(IPPool::class, 'ip_pool_id');
|
||||
}
|
||||
}
|
||||
29
extensions/Servers/Proxmox/Models/IPPool.php
Normal file
29
extensions/Servers/Proxmox/Models/IPPool.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Servers\Proxmox\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class IPPool extends Model
|
||||
{
|
||||
protected $table = 'ext_proxmox_ip_pools';
|
||||
|
||||
protected $fillable = [
|
||||
// Shows to customer
|
||||
'name',
|
||||
'network_interface',
|
||||
'mtu',
|
||||
'vlan',
|
||||
'firewall',
|
||||
];
|
||||
|
||||
public function nodes()
|
||||
{
|
||||
return $this->belongsToMany(Node::class, 'ext_proxmox_ip_pool_nodes', 'ip_pool_id', 'node_id');
|
||||
}
|
||||
|
||||
public function ipAddresses()
|
||||
{
|
||||
return $this->hasMany(IPAddress::class, 'ip_pool_id', 'id');
|
||||
}
|
||||
}
|
||||
17
extensions/Servers/Proxmox/Models/IPPoolNode.php
Normal file
17
extensions/Servers/Proxmox/Models/IPPoolNode.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Servers\Proxmox\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class IPPoolNode extends Model
|
||||
{
|
||||
protected $table = 'ext_proxmox_ip_pool_nodes';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'ip_pool_id',
|
||||
'node_id',
|
||||
];
|
||||
}
|
||||
25
extensions/Servers/Proxmox/Models/Location.php
Normal file
25
extensions/Servers/Proxmox/Models/Location.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Servers\Proxmox\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Location extends Model
|
||||
{
|
||||
protected $table = 'ext_proxmox_locations';
|
||||
|
||||
protected $fillable = [
|
||||
// Shows to customer
|
||||
'name',
|
||||
];
|
||||
|
||||
public function nodes()
|
||||
{
|
||||
return $this->hasMany(Node::class, 'location_id');
|
||||
}
|
||||
|
||||
public function os()
|
||||
{
|
||||
return $this->hasMany(OS::class);
|
||||
}
|
||||
}
|
||||
82
extensions/Servers/Proxmox/Models/Node.php
Normal file
82
extensions/Servers/Proxmox/Models/Node.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?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',
|
||||
'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;
|
||||
}
|
||||
}
|
||||
16
extensions/Servers/Proxmox/Models/OS.php
Normal file
16
extensions/Servers/Proxmox/Models/OS.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Servers\Proxmox\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OS extends Model
|
||||
{
|
||||
protected $table = 'ext_proxmox_oses';
|
||||
|
||||
protected $fillable = [
|
||||
// Shows to customer
|
||||
'name',
|
||||
'vm_id',
|
||||
];
|
||||
}
|
||||
59
extensions/Servers/Proxmox/Models/Server.php
Normal file
59
extensions/Servers/Proxmox/Models/Server.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Servers\Proxmox\Models;
|
||||
|
||||
use App\Models\Service;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Server extends Model
|
||||
{
|
||||
protected $table = 'ext_proxmox_servers';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'node_id',
|
||||
'os_id',
|
||||
'service_id',
|
||||
'vm_id',
|
||||
'primary_ipv4',
|
||||
'primary_ipv6',
|
||||
'status',
|
||||
'hostname',
|
||||
'password',
|
||||
];
|
||||
|
||||
public function node()
|
||||
{
|
||||
return $this->belongsTo(Node::class);
|
||||
}
|
||||
|
||||
public function os()
|
||||
{
|
||||
return $this->belongsTo(OS::class);
|
||||
}
|
||||
|
||||
public function ipAddresses()
|
||||
{
|
||||
return $this->hasMany(IPAddress::class);
|
||||
}
|
||||
|
||||
public function service()
|
||||
{
|
||||
return $this->belongsTo(Service::class);
|
||||
}
|
||||
|
||||
public function primaryIpv4()
|
||||
{
|
||||
return $this->belongsTo(IPAddress::class, 'primary_ipv4');
|
||||
}
|
||||
|
||||
public function primaryIpv6()
|
||||
{
|
||||
return $this->belongsTo(IPAddress::class, 'primary_ipv6');
|
||||
}
|
||||
|
||||
public function statistics()
|
||||
{
|
||||
return $this->hasMany(ServerStatistics::class);
|
||||
}
|
||||
}
|
||||
52
extensions/Servers/Proxmox/Models/ServerStatistics.php
Normal file
52
extensions/Servers/Proxmox/Models/ServerStatistics.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Servers\Proxmox\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ServerStatistics extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
|
||||
protected $table = 'ext_proxmox_servers_statistics';
|
||||
|
||||
protected $fillable = [
|
||||
'server_id',
|
||||
'netin',
|
||||
'netout',
|
||||
'diskread',
|
||||
'diskwrite',
|
||||
'diskused',
|
||||
'diskmax',
|
||||
'memoryused',
|
||||
'memorymax',
|
||||
'cpuused',
|
||||
'cpumax',
|
||||
'uptime',
|
||||
'vmstatus',
|
||||
'DateTime',
|
||||
'is_automatic',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'DateTime' => 'datetime',
|
||||
'netin' => 'integer',
|
||||
'netout' => 'integer',
|
||||
'diskread' => 'integer',
|
||||
'diskwrite' => 'integer',
|
||||
'diskused' => 'integer',
|
||||
'diskmax' => 'integer',
|
||||
'memoryused' => 'integer',
|
||||
'memorymax' => 'integer',
|
||||
'cpuused' => 'decimal:4',
|
||||
'cpumax' => 'decimal:4',
|
||||
'uptime' => 'integer',
|
||||
'is_automatic' => 'boolean',
|
||||
];
|
||||
|
||||
public function server()
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user