Add datastore_id to OS model and related functionality; update validation and relationships
This commit is contained in:
@@ -109,18 +109,19 @@ class IpPoolController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk create: ip_address may be comma-separated (e.g. "10.0.0.1,10.0.0.2").
|
||||
* Bulk create: ip_address may be separated by commas and/or whitespace (e.g. "10.0.0.1, 10.0.0.2 10.0.0.3").
|
||||
*/
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'ip_address' => 'required|string',
|
||||
'module_network_id' => 'required|integer|exists:module_network,id',
|
||||
'gateway' => 'nullable|string|max:45',
|
||||
]);
|
||||
|
||||
$networkId = (int) $request->module_network_id;
|
||||
$rawIps = $request->ip_address;
|
||||
$ips = array_filter(array_map('trim', explode(',', $rawIps)));
|
||||
$ips = array_filter(array_map('trim', preg_split('/[\s,]+/', $rawIps)));
|
||||
|
||||
if (empty($ips)) {
|
||||
return response()->json(['error' => true, 'message' => 'Không có địa chỉ IP hợp lệ'], 422);
|
||||
@@ -161,6 +162,7 @@ class IpPoolController extends Controller
|
||||
$created[] = IpPool::create([
|
||||
'ip_address' => $ip,
|
||||
'module_network_id' => $networkId,
|
||||
'gateway' => $request->gateway,
|
||||
]);
|
||||
}
|
||||
DB::commit();
|
||||
@@ -183,6 +185,7 @@ class IpPoolController extends Controller
|
||||
$request->validate([
|
||||
'ip_address' => 'required|string|max:45',
|
||||
'module_network_id' => 'required|integer|exists:module_network,id',
|
||||
'gateway' => 'nullable|string|max:45',
|
||||
]);
|
||||
|
||||
if (!filter_var($request->ip_address, FILTER_VALIDATE_IP)) {
|
||||
@@ -204,7 +207,7 @@ class IpPoolController extends Controller
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$pool->update($request->only(['ip_address', 'module_network_id']));
|
||||
$pool->update($request->only(['ip_address', 'module_network_id', 'gateway']));
|
||||
DB::commit();
|
||||
|
||||
return response()->json(['error' => false, 'data' => $pool->fresh('network')]);
|
||||
@@ -278,7 +281,8 @@ class IpPoolController extends Controller
|
||||
|
||||
public function networks(): JsonResponse
|
||||
{
|
||||
$networks = ModuleNetwork::select(['id', 'name', 'type', 'network'])
|
||||
$networks = ModuleNetwork::select(['id', 'name', 'type', 'network', 'module_host_id'])
|
||||
->with(['host:id,name,module_datacenter_id', 'host.datacenter:id,name'])
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -18,6 +18,8 @@ use Illuminate\Http\Request;
|
||||
|
||||
class VCenterController extends Controller
|
||||
{
|
||||
private const CONSOLE_HOST = 'console.tgs.com.vn';
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
@@ -77,7 +79,11 @@ class VCenterController extends Controller
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => $ticket['data'],
|
||||
'data' => preg_replace(
|
||||
'#^wss://[^/]+#',
|
||||
'wss://' . self::CONSOLE_HOST,
|
||||
$ticket['data']
|
||||
),
|
||||
'host' => $vcenter->host,
|
||||
'vmware-api-session-id' => $serviceVCenter->token,
|
||||
])->cookie('vmware-api-session-id', $serviceVCenter->token, 60, '/', null, false, false);
|
||||
|
||||
Reference in New Issue
Block a user