- Added methods to ResourceService for fetching resource pools and updated existing methods to include datacenter filtering. - Modified CreateVirtualMachine to accept folder and resource pool parameters from product data. - Updated various jobs to synchronize resource pools and include them in the provisioning process. - Introduced new ModuleResourcePool model and migration for resource pool management. - Enhanced existing models (ModuleDatastore, ModuleNetwork, Os) to include relationships with vCenter and resource pools. - Added netmask field to IpPool and updated related logic for IP reservation. - Improved error handling and logging in VM creation and IP reservation processes. - Updated API routes to include sync functionality for vCenter.
82 lines
1.9 KiB
PHP
82 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Os extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'os';
|
|
|
|
protected $fillable = [
|
|
'version',
|
|
'os_group_id',
|
|
'template_id',
|
|
'module_host_id',
|
|
'datastore_id',
|
|
'module_network_id',
|
|
'resource_pool_id',
|
|
'folder_id',
|
|
'status',
|
|
];
|
|
|
|
public function osGroup()
|
|
{
|
|
return $this->belongsTo(\App\Models\OsGroup::class);
|
|
}
|
|
|
|
public function host()
|
|
{
|
|
return $this->belongsTo(\App\Models\ModuleHost::class, 'module_host_id');
|
|
}
|
|
|
|
public function datastore()
|
|
{
|
|
return $this->belongsTo(\App\Models\ModuleDatastore::class, 'datastore_id');
|
|
}
|
|
|
|
public function network()
|
|
{
|
|
return $this->belongsTo(\App\Models\ModuleNetwork::class, 'module_network_id');
|
|
}
|
|
|
|
public function resourcePool()
|
|
{
|
|
return $this->belongsTo(\App\Models\ModuleResourcePool::class, 'resource_pool_id');
|
|
}
|
|
|
|
public function folder()
|
|
{
|
|
return $this->belongsTo(\App\Models\ModuleFolder::class, 'folder_id');
|
|
}
|
|
public function getStatus()
|
|
{
|
|
return match ($this->attributes['status']){
|
|
1 => '<span class="badge bg-success">Active</span>',
|
|
default => '<span class="badge bg-danger">De-Active</span>'
|
|
};
|
|
}
|
|
/**
|
|
* Many-to-many relationship với Products (new table: os_product)
|
|
*/
|
|
public function products()
|
|
{
|
|
return $this->belongsToMany(\App\Models\Product::class, 'os_product', 'os_id', 'product_id')
|
|
->withTimestamps();
|
|
}
|
|
|
|
/**
|
|
* Get display name with OS Group
|
|
*/
|
|
public function getNameAttribute()
|
|
{
|
|
if ($this->osGroup) {
|
|
return $this->osGroup->name . ' ' . $this->version;
|
|
}
|
|
return $this->version;
|
|
}
|
|
}
|