feat: initialize Infra Manager with React, Tailwind CSS, and Inertia.js
- Added main application entry point (app.jsx) and bootstrap file for React setup. - Created Wiki index page (Index.jsx) for documentation and file management. - Implemented utility functions for formatting and status handling in utils.js. - Set up Blade template (app.blade.php) for Inertia.js integration. - Defined API routes for metrics and terminal access in api.php. - Established console commands for scheduled tasks in console.php. - Created web routes for various application features including authentication, hypervisors, containers, cloud accounts, security, backups, and wiki management in web.php. - Developed setup scripts for Windows (setup.ps1) and Linux (setup.sh) environments. - Configured Tailwind CSS for styling with custom themes and animations in tailwind.config.js. - Set up Vite for asset bundling and development server in vite.config.js.
This commit is contained in:
121
app/Http/Controllers/Hypervisor/HypervisorController.php
Normal file
121
app/Http/Controllers/Hypervisor/HypervisorController.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Hypervisor;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Hypervisor;
|
||||
use App\Services\Hypervisor\HypervisorManager;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class HypervisorController extends Controller
|
||||
{
|
||||
public function __construct(private HypervisorManager $manager) {}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$hypervisors = Hypervisor::withCount('virtualMachines')
|
||||
->orderByDesc('created_at')
|
||||
->paginate(20);
|
||||
|
||||
return Inertia::render('Hypervisor/Index', ['hypervisors' => $hypervisors]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return Inertia::render('Hypervisor/Create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:100',
|
||||
'type' => 'required|in:vcenter,esxi,proxmox,hyper-v,xen,kvm',
|
||||
'host' => 'required|string',
|
||||
'port' => 'required|integer|between:1,65535',
|
||||
'username' => 'required|string',
|
||||
'password' => 'required|string',
|
||||
'ssl_verify' => 'boolean',
|
||||
'datacenter' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$hypervisor = Hypervisor::create([
|
||||
...$validated,
|
||||
'created_by' => auth()->id(),
|
||||
'status' => 'unknown',
|
||||
]);
|
||||
|
||||
activity()->causedBy(auth()->user())->performedOn($hypervisor)->log('Hypervisor created');
|
||||
|
||||
return redirect()->route('hypervisors.show', $hypervisor)
|
||||
->with('success', 'Hypervisor added successfully.');
|
||||
}
|
||||
|
||||
public function show(Hypervisor $hypervisor)
|
||||
{
|
||||
$hypervisor->load('virtualMachines');
|
||||
$vmStats = $hypervisor->virtualMachines()
|
||||
->selectRaw('status, COUNT(*) as count')
|
||||
->groupBy('status')
|
||||
->pluck('count', 'status');
|
||||
|
||||
return Inertia::render('Hypervisor/Show', [
|
||||
'hypervisor' => $hypervisor,
|
||||
'vm_stats' => $vmStats,
|
||||
'vms' => $hypervisor->virtualMachines()->orderBy('name')->paginate(50),
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit(Hypervisor $hypervisor)
|
||||
{
|
||||
return Inertia::render('Hypervisor/Edit', ['hypervisor' => $hypervisor->makeVisible('password')]);
|
||||
}
|
||||
|
||||
public function update(Request $request, Hypervisor $hypervisor)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:100',
|
||||
'host' => 'required|string',
|
||||
'port' => 'required|integer|between:1,65535',
|
||||
'username' => 'required|string',
|
||||
'password' => 'nullable|string',
|
||||
'ssl_verify' => 'boolean',
|
||||
'datacenter' => 'nullable|string',
|
||||
]);
|
||||
|
||||
if (empty($validated['password'])) {
|
||||
unset($validated['password']);
|
||||
}
|
||||
|
||||
$hypervisor->update($validated);
|
||||
activity()->causedBy(auth()->user())->performedOn($hypervisor)->log('Hypervisor updated');
|
||||
|
||||
return redirect()->route('hypervisors.show', $hypervisor)
|
||||
->with('success', 'Hypervisor updated.');
|
||||
}
|
||||
|
||||
public function destroy(Hypervisor $hypervisor)
|
||||
{
|
||||
$hypervisor->delete();
|
||||
activity()->causedBy(auth()->user())->log("Hypervisor '{$hypervisor->name}' deleted");
|
||||
|
||||
return redirect()->route('hypervisors.index')->with('success', 'Hypervisor removed.');
|
||||
}
|
||||
|
||||
public function sync(Hypervisor $hypervisor)
|
||||
{
|
||||
try {
|
||||
$this->manager->driver($hypervisor)->sync();
|
||||
return back()->with('success', 'Sync completed successfully.');
|
||||
} catch (\Throwable $e) {
|
||||
$hypervisor->update(['status' => 'error', 'last_error' => $e->getMessage()]);
|
||||
return back()->with('error', 'Sync failed: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testConnection(Request $request, Hypervisor $hypervisor)
|
||||
{
|
||||
$result = $this->manager->testConnection($hypervisor);
|
||||
return response()->json($result);
|
||||
}
|
||||
}
|
||||
77
app/Http/Controllers/Hypervisor/TemplateController.php
Normal file
77
app/Http/Controllers/Hypervisor/TemplateController.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Hypervisor;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Hypervisor;
|
||||
use App\Models\VmTemplate;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class TemplateController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return Inertia::render('Hypervisor/Templates', [
|
||||
'templates' => VmTemplate::with('hypervisor')->orderBy('name')->paginate(20),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return Inertia::render('Hypervisor/TemplateCreate', [
|
||||
'hypervisors' => Hypervisor::where('status', 'online')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:100',
|
||||
'hypervisor_id' => 'nullable|exists:hypervisors,id',
|
||||
'os_type' => 'required|string',
|
||||
'cpu_count' => 'integer|min:1',
|
||||
'memory_mb' => 'integer|min:512',
|
||||
'disk_gb' => 'integer|min:1',
|
||||
'customization' => 'nullable|array',
|
||||
'provision_script' => 'nullable|string',
|
||||
]);
|
||||
VmTemplate::create([...$validated, 'created_by' => auth()->id()]);
|
||||
return redirect()->route('templates.index')->with('success', 'Template created.');
|
||||
}
|
||||
|
||||
public function show(VmTemplate $template)
|
||||
{
|
||||
return Inertia::render('Hypervisor/TemplateShow', ['template' => $template->load('hypervisor')]);
|
||||
}
|
||||
|
||||
public function edit(VmTemplate $template)
|
||||
{
|
||||
return Inertia::render('Hypervisor/TemplateEdit', [
|
||||
'template' => $template,
|
||||
'hypervisors' => Hypervisor::where('status', 'online')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, VmTemplate $template)
|
||||
{
|
||||
$template->update($request->except('_token'));
|
||||
return redirect()->route('templates.show', $template)->with('success', 'Template updated.');
|
||||
}
|
||||
|
||||
public function destroy(VmTemplate $template)
|
||||
{
|
||||
$template->delete();
|
||||
return redirect()->route('templates.index')->with('success', 'Template deleted.');
|
||||
}
|
||||
|
||||
public function deploy(Request $request, VmTemplate $template)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'vm_name' => 'required|string',
|
||||
'hypervisor_id' => 'required|exists:hypervisors,id',
|
||||
]);
|
||||
// Dispatch deploy job
|
||||
return back()->with('success', 'Deployment queued.');
|
||||
}
|
||||
}
|
||||
60
app/Http/Controllers/Hypervisor/VirtualMachineController.php
Normal file
60
app/Http/Controllers/Hypervisor/VirtualMachineController.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Hypervisor;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\VirtualMachine;
|
||||
use App\Services\Hypervisor\HypervisorManager;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class VirtualMachineController extends Controller
|
||||
{
|
||||
public function __construct(private HypervisorManager $manager) {}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return Inertia::render('Hypervisor/VMs', [
|
||||
'vms' => VirtualMachine::with('hypervisor')->orderBy('name')->paginate(50),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(VirtualMachine $vm)
|
||||
{
|
||||
return Inertia::render('Hypervisor/VMShow', ['vm' => $vm->load('hypervisor')]);
|
||||
}
|
||||
|
||||
public function power(Request $request, VirtualMachine $vm)
|
||||
{
|
||||
$action = $request->validate(['action' => 'required|in:start,stop,reboot,suspend'])['action'];
|
||||
$driver = $this->manager->driver($vm->hypervisor);
|
||||
|
||||
match ($action) {
|
||||
'start' => $driver->powerOn($vm->remote_id),
|
||||
'stop' => $driver->powerOff($vm->remote_id),
|
||||
'reboot' => $driver->reboot($vm->remote_id),
|
||||
'suspend' => $driver->suspend($vm->remote_id),
|
||||
};
|
||||
|
||||
return back()->with('success', "VM {$action} initiated.");
|
||||
}
|
||||
|
||||
public function snapshot(Request $request, VirtualMachine $vm)
|
||||
{
|
||||
$data = $request->validate(['name' => 'required|string', 'description' => 'nullable|string']);
|
||||
$this->manager->driver($vm->hypervisor)->createSnapshot($vm->remote_id, $data['name'], $data['description'] ?? '');
|
||||
return back()->with('success', 'Snapshot created.');
|
||||
}
|
||||
|
||||
public function clone(Request $request, VirtualMachine $vm)
|
||||
{
|
||||
$data = $request->validate(['name' => 'required|string']);
|
||||
$this->manager->driver($vm->hypervisor)->cloneVM($vm->remote_id, $data['name'], []);
|
||||
return back()->with('success', 'Clone initiated.');
|
||||
}
|
||||
|
||||
public function migrate(Request $request, VirtualMachine $vm)
|
||||
{
|
||||
return back()->with('info', 'Migration not yet implemented for this hypervisor type.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user