- 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.
122 lines
4.0 KiB
PHP
122 lines
4.0 KiB
PHP
<?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);
|
|
}
|
|
}
|