From 31750fe663235c481023a13cb6bf1bd9fae89bb1 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 22 Oct 2024 18:26:51 +0200 Subject: [PATCH] refs #649. Integration ogBoot.Demo --- config/api_platform/Client.yaml | 9 +++- src/Controller/OgAgent/StatusAction.php | 12 +++--- .../OgBoot/PxeBootFile/GetAction.php | 43 +++++++++++++++++++ 3 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 src/Controller/OgBoot/PxeBootFile/GetAction.php diff --git a/config/api_platform/Client.yaml b/config/api_platform/Client.yaml index ee2b36c..d1e1d84 100644 --- a/config/api_platform/Client.yaml +++ b/config/api_platform/Client.yaml @@ -35,13 +35,20 @@ resources: controller: App\Controller\ChangeOrganizationalUnitAction agent_status: - provider: App\State\Provider\ClientProvider class: ApiPlatform\Metadata\Post method: POST input: false uriTemplate: /clients/{uuid}/agent/status 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: App\Entity\Client: id: diff --git a/src/Controller/OgAgent/StatusAction.php b/src/Controller/OgAgent/StatusAction.php index 8de1498..b11af50 100644 --- a/src/Controller/OgAgent/StatusAction.php +++ b/src/Controller/OgAgent/StatusAction.php @@ -7,6 +7,7 @@ use App\Model\OgLiveStatus; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpClient\HttpClient; +use Symfony\Component\HttpClient\Internal\ClientState; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; @@ -43,19 +44,20 @@ class StatusAction extends AbstractController throw new ValidatorException('IP is required'); } - try { $response = $this->httpClient->request('POST', 'https://'.$client->getIp().':8000/ogAdmClient/status'); + $client->setStatus('off'); + $this->entityManager->persist($client); + $this->entityManager->flush(); } catch (TransportExceptionInterface $e) { return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); } - $data = json_decode($response->getContent(), true); - $client->setAgentJobId($data['job_id']); - $this->entityManager->persist($data); + $client->setStatus('active'); + $this->entityManager->persist($client); $this->entityManager->flush(); - return new JsonResponse(data: $data, status: Response::HTTP_OK); + return new JsonResponse(status: Response::HTTP_OK); } } \ No newline at end of file diff --git a/src/Controller/OgBoot/PxeBootFile/GetAction.php b/src/Controller/OgBoot/PxeBootFile/GetAction.php new file mode 100644 index 0000000..7f51e2b --- /dev/null +++ b/src/Controller/OgBoot/PxeBootFile/GetAction.php @@ -0,0 +1,43 @@ +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); + } +} \ No newline at end of file