- Introduced a new method `resolveVCenterFromProduct` in `SnapshotService` to streamline vCenter resolution from product data. - Updated `CreateSnapshot`, `RemoveSnapshot`, and `RevertSnapshot` jobs to utilize the new vCenter resolution method. - Enhanced the `VmController` to support UUID-based service identification for VM operations. - Added new actions for changing VM IP and RDP port, encapsulating the logic for these operations. - Improved error handling and logging for VM operations, including detailed responses for API consumers. - Removed unnecessary relationships in model queries to optimize performance.
75 lines
1.8 KiB
PHP
75 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class ModuleVmware extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'module_vmware';
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'module_ip_address',
|
|
'port',
|
|
'order_id',
|
|
'first_payment',
|
|
'next_payment',
|
|
'next_due_date',
|
|
'next_invoice',
|
|
'user',
|
|
'password',
|
|
'hostname',
|
|
'vmware_id',
|
|
'vcenter_id',
|
|
'os_id',
|
|
'customer_id',
|
|
'status'
|
|
];
|
|
|
|
// NOTE: password must NOT use 'hashed' cast — it is a VM guest credential
|
|
// used in plaintext by PowerShell scripts (Invoke-VMScript) via SSH/PowerCLI.
|
|
protected $casts = [];
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo(\App\Models\Customer::class);
|
|
}
|
|
public function ipAddress()
|
|
{
|
|
return $this->belongsTo(\App\Models\ModuleIpAddress::class, 'module_ip_address', 'id');
|
|
}
|
|
public function vCenter()
|
|
{
|
|
return $this->belongsTo(\App\Models\vCenter::class, 'vcenter_id', 'id');
|
|
}
|
|
public function os()
|
|
{
|
|
return $this->belongsTo(\App\Models\Os::class);
|
|
}
|
|
public function osGroup()
|
|
{
|
|
return $this->belongsTo(\App\Models\OsGroup::class);
|
|
}
|
|
public function order()
|
|
{
|
|
return $this->belongsTo(\App\Models\Order::class);
|
|
}
|
|
|
|
public function services()
|
|
{
|
|
return $this->hasMany(\App\Models\Service::class, 'vm_id', 'vmware_id');
|
|
}
|
|
|
|
public function getStatus()
|
|
{
|
|
return match ($this->status) {
|
|
1 => '<span class="badge bg-success">Active</span>',
|
|
2 => '<span class="badge bg-secondary">Cancel</span>',
|
|
default => '<span class="badge bg-danger">Pending</span>',
|
|
};
|
|
}
|
|
}
|