Improvements in ogBoot API
testing/ogcore-api/pipeline/head There was a failure building this commit Details

pull/13/head
Manuel Aranda Rosales 2024-11-20 18:16:29 +01:00
parent 81da6b7a34
commit b0efe07977
3 changed files with 14 additions and 18 deletions

View File

@ -38,6 +38,7 @@ resources:
class: ApiPlatform\Metadata\Post
method: POST
input: false
output: false
uriTemplate: /clients/{uuid}/agent/status
controller: App\Controller\OgAgent\StatusAction

View File

@ -43,21 +43,21 @@ class StatusAction extends AbstractController
throw new ValidatorException('IP is required');
}
if ($client->getStatus() === ClientStatus::OG_LIVE) {
$this->getOgLiveStatus($client);
if ($client->getStatus() === ClientStatus::OG_LIVE || $client->getStatus() === ClientStatus::OFF) {
$response = $this->getOgLiveStatus($client);
}
if ($client->getStatus() === ClientStatus::LINUX) {
$this->getSOStatus($client);
$response = $this->getSOStatus($client);
}
return new JsonResponse(
data: ['status' => $client->getStatus()],
status: Response::HTTP_OK
data: ['status' => $response],
status: $response === Response::HTTP_OK ? Response::HTTP_OK : Response::HTTP_INTERNAL_SERVER_ERROR
);
}
public function getOgLiveStatus (Client $client): JsonResponse
public function getOgLiveStatus (Client $client): JsonResponse|int
{
try {
$response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/ogAdmClient/status', [
@ -75,10 +75,7 @@ class StatusAction extends AbstractController
} catch (TransportExceptionInterface $e) {
$client->setStatus(ClientStatus::OFF);
return new JsonResponse(
data: ['error' => $e->getMessage()],
status: Response::HTTP_INTERNAL_SERVER_ERROR
);
return Response::HTTP_INTERNAL_SERVER_ERROR;
}
$data = json_decode($response->getContent(), true);
@ -90,10 +87,10 @@ class StatusAction extends AbstractController
$this->entityManager->persist($client);
$this->entityManager->flush();
return new JsonResponse(status: Response::HTTP_OK);
return Response::HTTP_OK;
}
public function getSOStatus (Client $client): JsonResponse
public function getSOStatus (Client $client): JsonResponse|int
{
try {
$response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/opengnsys/status', [
@ -111,10 +108,7 @@ class StatusAction extends AbstractController
} catch (TransportExceptionInterface $e) {
$client->setStatus(ClientStatus::OFF);
return new JsonResponse(
data: ['error' => $e->getMessage()],
status: Response::HTTP_INTERNAL_SERVER_ERROR
);
return Response::HTTP_INTERNAL_SERVER_ERROR;
}
$data = json_decode($response->getContent(), true);
@ -126,6 +120,6 @@ class StatusAction extends AbstractController
$this->entityManager->persist($client);
$this->entityManager->flush();
return new JsonResponse(status: Response::HTTP_OK);
return Response::HTTP_OK;
}
}

View File

@ -19,6 +19,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
#[AsController]
class SyncAction extends AbstractOgBootController
{
const string OG_BOOT_DIRECTORY = '/opt/opengnsys/ogboot/tftpboot//';
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
@ -53,7 +54,7 @@ class SyncAction extends AbstractOgBootController
*/
private function extracted(OgLive|null $ogLiveEntity, mixed $ogLive): void
{
$ogLiveEntity->setName($ogLive['directory']);
$ogLiveEntity->setName(str_replace(self::OG_BOOT_DIRECTORY, '', $ogLive['directory']));
$ogLiveEntity->setInstalled(true);
$ogLiveEntity->setArchitecture($ogLive['architecture']);
$ogLiveEntity->setDistribution($ogLive['distribution']);