Add datastore_id to OS model and related functionality; update validation and relationships
This commit is contained in:
@@ -17,6 +17,7 @@ class OsController extends Controller
|
||||
'os_group_id' => 'required|integer|exists:os_group,id',
|
||||
'template_id' => 'nullable|string|max:255',
|
||||
'module_host_id' => 'nullable|integer|exists:module_host,id',
|
||||
'datastore_id' => 'nullable|integer|exists:module_datastore,id',
|
||||
'is_active' => 'boolean',
|
||||
]);
|
||||
|
||||
@@ -25,6 +26,7 @@ class OsController extends Controller
|
||||
'os_group_id' => $validated['os_group_id'],
|
||||
'template_id' => $validated['template_id'] ?? null,
|
||||
'module_host_id' => $validated['module_host_id'] ?? null,
|
||||
'datastore_id' => $validated['datastore_id'] ?? null,
|
||||
'status' => ($validated['is_active'] ?? true) ? 1 : 0,
|
||||
]);
|
||||
|
||||
@@ -48,6 +50,7 @@ class OsController extends Controller
|
||||
'os_group_id' => 'sometimes|integer|exists:os_group,id',
|
||||
'template_id' => 'nullable|string|max:255',
|
||||
'module_host_id' => 'nullable|integer|exists:module_host,id',
|
||||
'datastore_id' => 'nullable|integer|exists:module_datastore,id',
|
||||
'is_active' => 'boolean',
|
||||
]);
|
||||
|
||||
@@ -56,6 +59,7 @@ class OsController extends Controller
|
||||
'os_group_id' => $validated['os_group_id'] ?? $os->os_group_id,
|
||||
'template_id' => array_key_exists('template_id', $validated) ? $validated['template_id'] : $os->template_id,
|
||||
'module_host_id' => array_key_exists('module_host_id', $validated) ? $validated['module_host_id'] : $os->module_host_id,
|
||||
'datastore_id' => array_key_exists('datastore_id', $validated) ? $validated['datastore_id'] : $os->datastore_id,
|
||||
'status' => isset($validated['is_active']) ? ($validated['is_active'] ? 1 : 0) : $os->status,
|
||||
]);
|
||||
|
||||
@@ -83,8 +87,9 @@ class OsController extends Controller
|
||||
|
||||
private function formatOs(Os $os): array
|
||||
{
|
||||
$os->loadMissing('host.datacenter.vCenter');
|
||||
$os->loadMissing('host.datacenter.vCenter', 'datastore');
|
||||
$host = $os->host;
|
||||
$datastore = $os->datastore;
|
||||
|
||||
return [
|
||||
'id' => $os->id,
|
||||
@@ -93,6 +98,8 @@ class OsController extends Controller
|
||||
'is_active' => (bool) $os->status,
|
||||
'os_group_id' => $os->os_group_id,
|
||||
'module_host_id' => $os->module_host_id,
|
||||
'datastore_id' => $os->datastore_id,
|
||||
'datastore_name' => $datastore?->name,
|
||||
'host_name' => $host ? $host->name : null,
|
||||
'datacenter_name' => $host?->datacenter?->name,
|
||||
'vcenter_name' => $host?->datacenter?->vCenter?->host,
|
||||
|
||||
Reference in New Issue
Block a user