Add stubs for various Laravel components and scaffolding

- Created stubs for JavaScript and SASS assets.
- Added stubs for channel, command, component, controller, event, factory, job, listener, mail, middleware, migration, model, notification, observer, policy, request, resource, route provider, seeder, and validation rule.
- Implemented scaffolding for configuration, service provider, and Vite integration.
- Included example views for module structure.
- Introduced a module loader for Vite to handle asset paths dynamically.
This commit is contained in:
baodev0
2026-05-29 09:28:08 +07:00
parent fccb0c353a
commit 6bb4a47bfb
89 changed files with 3355 additions and 4560 deletions
@@ -1,245 +0,0 @@
<?php
namespace App\Jobs\VirtualMachine\Create;
use App\Http\Services\Telegram;
use App\Http\Services\vCenter;
use App\Models\ModuleVmware;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Http;
class AssignIPJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public string $vmId;
public int $moduleVmwareId;
public string $availableIP;
/**
* Create a new job instance.
*/
public function __construct(string $vmId, int $moduleVmwareId, string $availableIP)
{
$this->vmId = $vmId;
$this->moduleVmwareId = $moduleVmwareId;
$this->availableIP = $availableIP;
}
/**
* Execute the job.
*/
public function handle(vCenter $vCenter, Telegram $telegram)
{
try {
Log::info('🔧 Bắt đầu AssignIPJob', [
'vm_id' => $this->vmId,
'module_vmware_id' => $this->moduleVmwareId,
'assigned_ip' => $this->availableIP
]);
// Lấy thông tin ModuleVmware
$moduleVmware = ModuleVmware::with(['ipAddress.host.datacenter.vCenter'])->find($this->moduleVmwareId);
if (!$moduleVmware || !$moduleVmware->ipAddress) {
Log::error('❌ Không tìm thấy ModuleVmware hoặc IP address', [
'vm_id' => $this->vmId,
'module_vmware_id' => $this->moduleVmwareId
]);
$telegram->SendErrorMessage([
'error' => 'ModuleVmware or IP address not found',
'vm_id' => $this->vmId,
'module_vmware_id' => $this->moduleVmwareId
], 'AssignIPJob - Data Not Found');
return;
}
// Login vào vCenter
$vcenter = $moduleVmware->ipAddress->host->datacenter->vCenter;
if (!$vCenter->loginServer($vcenter)) {
Log::error('❌ Không thể login vào vCenter cho AssignIP', [
'vm_id' => $this->vmId,
'vcenter_host' => $vcenter->host
]);
$telegram->SendErrorMessage([
'error' => 'Cannot login to vCenter',
'vm_id' => $this->vmId,
'vcenter_host' => $vcenter->host
], 'AssignIPJob - vCenter Login Failed');
return;
}
// Kiểm tra OS family và assign IP
$this->handleIPAssignment($vCenter, $this->vmId, $moduleVmware, $this->availableIP, $telegram);
} catch (\Throwable $e) {
Log::error('❌ Lỗi trong AssignIPJob: ' . $e->getMessage(), [
'vm_id' => $this->vmId,
'module_vmware_id' => $this->moduleVmwareId,
'error' => $e->getMessage(),
'trace' => $e->getTraceAsString()
]);
$telegram->SendErrorMessage([
'error' => $e->getMessage(),
'vm_id' => $this->vmId,
'module_vmware_id' => $this->moduleVmwareId,
'file' => $e->getFile(),
'line' => $e->getLine()
], 'AssignIPJob - Exception');
}
}
/**
* Handle IP assignment based on OS family
*/
private function handleIPAssignment(vCenter $vCenter, string $vmId, ModuleVmware $moduleVmware, string $availableIP, Telegram $telegram): void
{
try {
// Kiểm tra OS family trước khi assign IP
$osFamily = $this->checkVMOSFamily($vCenter, $vmId);
if ($osFamily === 'WINDOWS') {
Log::info('✅ Phát hiện Windows VM, bắt đầu assign IP', [
'vm_id' => $vmId,
'os_family' => $osFamily,
'assigned_ip' => $availableIP
]);
// Assign IP cho Windows VM
$assignIPResult = $vCenter->assignIPWindows($moduleVmware, $vmId);
if (is_array($assignIPResult) && !$assignIPResult['error']) {
Log::info('✅ Assign IP Windows thành công', [
'vm_id' => $vmId,
'result' => $assignIPResult['data']
]);
$telegram->SendJobRunInfo(
'AssignIPWindows',
'success',
[
'vm_id' => $vmId,
'assigned_ip' => $availableIP,
'result' => $assignIPResult['data']
]
);
} else {
Log::warning('⚠️ Assign IP Windows thất bại', [
'vm_id' => $vmId,
'error' => $assignIPResult['data'] ?? 'Unknown error'
]);
$telegram->SendErrorMessage([
'error' => 'Assign IP Windows failed',
'vm_id' => $vmId,
'details' => $assignIPResult['data'] ?? 'Unknown error'
], 'AssignIPWindows - Failed');
}
} elseif ($osFamily === 'LINUX' || $osFamily === 'OTHER') {
Log::info('ℹ️ Phát hiện non-Windows VM, hệ thống đang nâng cấp', [
'vm_id' => $vmId,
'os_family' => $osFamily
]);
$telegram->SendJobRunInfo(
'AssignIP',
'upgrade',
[
'vm_id' => $vmId,
'os_family' => $osFamily,
'message' => 'Hệ thống đang nâng cấp để hỗ trợ IP assignment cho ' . $osFamily
]
);
} else {
Log::warning('⚠️ Không thể xác định OS family', [
'vm_id' => $vmId,
'os_family' => $osFamily
]);
$telegram->SendErrorMessage([
'error' => 'Cannot determine OS family',
'vm_id' => $vmId,
'os_family' => $osFamily
], 'AssignIP - Unknown OS');
}
} catch (\Exception $e) {
Log::error('❌ Lỗi khi handle IP assignment: ' . $e->getMessage(), [
'vm_id' => $vmId,
'error' => $e->getMessage()
]);
$telegram->SendErrorMessage([
'error' => 'IP Assignment handling failed',
'vm_id' => $vmId,
'details' => $e->getMessage()
], 'HandleIPAssignment - Exception');
}
}
/**
* Check VM OS family using vCenter API
*/
private function checkVMOSFamily(vCenter $vCenter, string $vmId): string
{
try {
// Kiểm tra session còn valid không
$check = $vCenter->checkApiExits();
if (!$check) {
Log::warning('vCenter session expired, cannot check OS family');
return 'UNKNOWN';
}
// Gọi API để lấy guest identity
$response = Http::withoutVerifying()
->withHeaders([
'vmware-api-session-id' => $vCenter->token
])
->get("https://{$vCenter->apiUri}/rest/vcenter/vm/{$vmId}/guest/identity");
if ($response->successful()) {
$data = $response->json();
if (isset($data['value']['family'])) {
$family = strtoupper($data['value']['family']);
Log::info('✅ Phát hiện OS family', [
'vm_id' => $vmId,
'family' => $family,
'full_name' => $data['value']['full_name'] ?? 'Unknown'
]);
return $family;
} else {
Log::warning('⚠️ Không tìm thấy family trong response', [
'vm_id' => $vmId,
'response' => $data
]);
return 'UNKNOWN';
}
} else {
Log::warning('⚠️ API call thất bại khi check OS family', [
'vm_id' => $vmId,
'status' => $response->status(),
'response' => $response->body()
]);
return 'UNKNOWN';
}
} catch (\Exception $e) {
Log::error('❌ Exception khi check OS family: ' . $e->getMessage(), [
'vm_id' => $vmId,
'error' => $e->getMessage()
]);
return 'UNKNOWN';
}
}
}
+5 -6
View File
@@ -38,21 +38,20 @@ class SyncFolder implements ShouldQueue
public function handle()
{
foreach ($this->data as $item) {
$this->vCenter->apiUri = $item->host;
if (!$item->token) {
$token = $this->vCenter->loginServer($item);
if ($token) {
vCenter::where('id', $item->id)->update(['token' => $token]);
$this->vCenter->token = $token;
$item->token = $token;
}
}
$this->vCenter->token = $item->token;
if (!$this->vCenter->token) {
if (!$item->token) {
continue;
}
$this->vCenter->setConnection($item->host, $item->token);
$dataCenter = ModuleDatacenter::where('vcenter_id', $item->id)->select('id', 'datacenter_id')->get();
foreach ($dataCenter as $_item) {
$folder = $this->vCenter->getAllFolder($_item['datacenter_id']);
@@ -61,7 +60,7 @@ class SyncFolder implements ShouldQueue
$token = $this->vCenter->loginServer($item);
if ($token) {
vCenter::where('id', $item->id)->update(['token' => $token]);
$this->vCenter->token = $token;
$this->vCenter->setConnection($item->host, $token);
}
$folder = $this->vCenter->getAllFolder($_item['datacenter_id']);
}