Update source into github
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Module;
|
||||
|
||||
use App\Http\Services\vCenter;
|
||||
use App\Repositories\vCenter\vCenterRepositoryInterface;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class OsServerVersion extends Component
|
||||
{
|
||||
public function __construct(
|
||||
public $model = null,
|
||||
public vCenter $vCenter,
|
||||
public vCenterRepositoryInterface $vCenterRepository
|
||||
) {
|
||||
}
|
||||
|
||||
public function render(): View|Closure|string
|
||||
{
|
||||
$versions = $this->fetchVersions();
|
||||
return view('components.module.os-server-version', compact('versions'));
|
||||
}
|
||||
|
||||
protected function fetchVersions()
|
||||
{
|
||||
$vCenter = optional($this->model?->osGroup?->host?->datacenter?->vCenter);
|
||||
|
||||
if (!$vCenter || !$vCenter->host) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->vCenter->token = $vCenter->token ?? '';
|
||||
$this->vCenter->apiUri = $vCenter->host ?? '';
|
||||
|
||||
$templateId = $this->model?->osGroup?->host?->template;
|
||||
|
||||
$versions = $this->vCenter->getAllVersion($templateId);
|
||||
|
||||
if ($versions === "Login_Again") {
|
||||
$token = $this->vCenter->loginServer($vCenter);
|
||||
if ($token) {
|
||||
$this->vCenterRepository->update($vCenter->id, ['token' => $token]);
|
||||
$this->vCenter->token = $token;
|
||||
$versions = $this->vCenter->getAllVersion($templateId);
|
||||
}
|
||||
}
|
||||
|
||||
return $versions;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user