id; if (!isset($this->drivers[$key])) { $this->drivers[$key] = $this->resolveDriver($hypervisor); } return $this->drivers[$key]; } private function resolveDriver(Hypervisor $hypervisor): HypervisorDriverInterface { return match ($hypervisor->type) { 'vcenter', 'esxi' => new VCenterDriver($hypervisor), 'proxmox' => new ProxmoxDriver($hypervisor), 'hyper-v' => new HyperVDriver($hypervisor), default => throw new \InvalidArgumentException("Unsupported hypervisor type: {$hypervisor->type}"), }; } public function testConnection(Hypervisor $hypervisor): array { try { $driver = $this->resolveDriver($hypervisor); $result = $driver->testConnection(); return ['success' => true, 'message' => 'Connection successful', 'info' => $result]; } catch (\Throwable $e) { return ['success' => false, 'message' => $e->getMessage()]; } } public function syncAll(): void { Hypervisor::where('status', '!=', 'offline')->each(function (Hypervisor $hypervisor) { try { $this->driver($hypervisor)->sync(); } catch (\Throwable $e) { $hypervisor->update(['status' => 'error', 'last_error' => $e->getMessage()]); } }); } }