You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/app/Controllers/CloudAdminHostInventoryCont...

59 lines
2.8 KiB
PHTML

<?php
namespace App\Controllers;
use App\Services\Cloud\CloudAccess;
use App\Services\Cloud\CloudEngineClient;
use App\Services\Cloud\CloudError;
use App\Services\Cloud\CloudHostInventoryDiagnostics;
use App\Services\Cloud\CloudInventoryRequestError;
/** Read-only inventory history. Reading a record never starts a host scan. */
final class CloudAdminHostInventoryController
{
public function index($request, $response)
{
return $response->withJson(CloudHostInventoryDiagnostics::page(
$request->getAttribute('cloud_actor') ?? CloudAccess::actor(false),
$request->getQueryParams()
))->withHeader('Cache-Control', 'private, no-store');
}
public function detail($request, $response, $args)
{
return $response->withJson(CloudHostInventoryDiagnostics::detail(
$request->getAttribute('cloud_actor') ?? CloudAccess::actor(false),
(string) ($args['id'] ?? '')
))->withHeader('Cache-Control', 'private, no-store');
}
public function engine($request, $response, $args)
{
$actor = $request->getAttribute('cloud_actor') ?? CloudAccess::actor(false);
$attemptId = (string) ($args['id'] ?? '');
// This authorizes the read and binds its host to a persisted attempt.
// Never accept an arbitrary host or call the capacity/network endpoints.
$detail = CloudHostInventoryDiagnostics::detail($actor, $attemptId);
try {
$result = (new CloudEngineClient(null, 1.0))->inventoryDiagnostics(
(int) $detail['attempt']['host_id'], $actor, $attemptId
);
$available = ($result['diagnostics_available'] ?? true) === true;
$result = ['available' => $available, 'attempt_id' => $attemptId,
'traces' => $result['traces'],
'message' => $available
? '仅查询引擎已记录的线索;不会发起盘点,也不会改变面板同步结果。'
: '引擎诊断存储暂不可用;无法取得内部阶段线索,不代表宿主机离线。'];
} catch (CloudInventoryRequestError $exception) {
$result = ['available' => false, 'attempt_id' => $attemptId,
'traces' => [], 'error_code' => $exception->diagnosticCode,
'message' => '引擎线索暂不可读取或尚未记录;无法据此判断宿主机是否正常。'];
} catch (CloudError $exception) {
$result = ['available' => false, 'attempt_id' => $attemptId,
'traces' => [], 'error_code' => 'diagnostics_unavailable',
'message' => '引擎线索暂不可读取;请检查引擎版本、认证及连接配置。'];
}
return $response->withJson($result)->withHeader('Cache-Control', 'private, no-store');
}
}