refs #649. Integration ogBoot.Demo
testing/ogcore-api/pipeline/head There was a failure building this commit Details

develop-jenkins
Manuel Aranda Rosales 2024-10-22 18:26:51 +02:00
parent 3f933db43e
commit 31750fe663
3 changed files with 58 additions and 6 deletions

View File

@ -35,13 +35,20 @@ resources:
controller: App\Controller\ChangeOrganizationalUnitAction controller: App\Controller\ChangeOrganizationalUnitAction
agent_status: agent_status:
provider: App\State\Provider\ClientProvider
class: ApiPlatform\Metadata\Post class: ApiPlatform\Metadata\Post
method: POST method: POST
input: false input: false
uriTemplate: /clients/{uuid}/agent/status uriTemplate: /clients/{uuid}/agent/status
controller: App\Controller\OgAgent\StatusAction controller: App\Controller\OgAgent\StatusAction
get_pxe:
class: ApiPlatform\Metadata\Post
method: POST
input: false
uriTemplate: /clients/server/{uuid}/get-pxe
controller: App\Controller\OgBoot\PxeBootFile\GetAction
properties: properties:
App\Entity\Client: App\Entity\Client:
id: id:

View File

@ -7,6 +7,7 @@ use App\Model\OgLiveStatus;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpClient\HttpClient; use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpClient\Internal\ClientState;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\HttpKernel\Attribute\AsController;
@ -43,19 +44,20 @@ class StatusAction extends AbstractController
throw new ValidatorException('IP is required'); throw new ValidatorException('IP is required');
} }
try { try {
$response = $this->httpClient->request('POST', 'https://'.$client->getIp().':8000/ogAdmClient/status'); $response = $this->httpClient->request('POST', 'https://'.$client->getIp().':8000/ogAdmClient/status');
$client->setStatus('off');
$this->entityManager->persist($client);
$this->entityManager->flush();
} catch (TransportExceptionInterface $e) { } catch (TransportExceptionInterface $e) {
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
} }
$data = json_decode($response->getContent(), true);
$client->setAgentJobId($data['job_id']); $client->setStatus('active');
$this->entityManager->persist($data); $this->entityManager->persist($client);
$this->entityManager->flush(); $this->entityManager->flush();
return new JsonResponse(data: $data, status: Response::HTTP_OK); return new JsonResponse(status: Response::HTTP_OK);
} }
} }

View File

@ -0,0 +1,43 @@
<?php
namespace App\Controller\OgBoot\PxeBootFile;
use App\Controller\OgBoot\AbstractOgBootController;
use App\Entity\Client;
use App\Entity\PxeTemplate;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
#[AsController]
class GetAction extends AbstractOgBootController
{
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function __invoke(Client $client, HttpClientInterface $httpClient): JsonResponse
{
try {
$response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/pxes/'.$client->getMac(), [
'headers' => [
'accept' => 'application/json',
],
]);
} catch (TransportExceptionInterface $e) {
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
}
$data = json_decode($response->getContent(), true);
return new JsonResponse( data: $data, status: Response::HTTP_OK);
}
}