From 9be2f5fd9b1e428f4b002f6230de6b1befab6c0e Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Fri, 23 May 2025 09:23:41 +0200 Subject: [PATCH] refs #2085. Boot OS --- config/api_platform/Client.yaml | 6 +++--- src/Controller/OgAgent/LoginAction.php | 18 ++++++++++++------ src/Controller/OgAgent/RebootAction.php | 2 +- src/Dto/Input/BootClientsInput.php | 19 ++++++++++++++++--- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/config/api_platform/Client.yaml b/config/api_platform/Client.yaml index ad274d0..fb4a8c3 100644 --- a/config/api_platform/Client.yaml +++ b/config/api_platform/Client.yaml @@ -50,11 +50,11 @@ resources: uriTemplate: /clients/server/{uuid}/get-pxe controller: App\Controller\OgBoot\PxeBootFile\GetAction - login_client: + boot_client: class: ApiPlatform\Metadata\Post method: POST - input: App\Dto\Input\MultipleClientsInput - uriTemplate: /clients/server/login-client + input: App\Dto\Input\BootClientsInput + uriTemplate: /clients/server/boot-client controller: App\Controller\OgAgent\LoginAction reboot_client: diff --git a/src/Controller/OgAgent/LoginAction.php b/src/Controller/OgAgent/LoginAction.php index a6d798f..260f02f 100644 --- a/src/Controller/OgAgent/LoginAction.php +++ b/src/Controller/OgAgent/LoginAction.php @@ -4,10 +4,12 @@ declare(strict_types=1); namespace App\Controller\OgAgent; +use App\Dto\Input\BootClientsInput; use App\Dto\Input\MultipleClientsInput; use App\Entity\Client; use App\Entity\Command; use App\Entity\Image; +use App\Entity\Partition; use App\Entity\Trace; use App\Model\ClientStatus; use App\Model\CommandTypes; @@ -35,8 +37,11 @@ class LoginAction extends AbstractOgAgentController * @throws RedirectionExceptionInterface * @throws ClientExceptionInterface */ - public function __invoke(MultipleClientsInput $input): JsonResponse + public function __invoke(BootClientsInput $input): JsonResponse { + /** @var Partition $partition */ + $partition = $input->partition->getEntity(); + foreach ($input->clients as $clientEntity) { /** @var Client $client */ $client = $clientEntity->getEntity(); @@ -52,17 +57,18 @@ class LoginAction extends AbstractOgAgentController $data = [ 'nfn' => 'IniciarSesion', - 'dsk' => '1', - 'par' => '1', + 'dsk' => (string) $partition->getDiskNumber(), + 'par' => (string) $partition->getPartitionNumber(), 'ids' => '0' ]; $response = $this->createRequest( method: 'POST', - url: 'http://'.$client->getIp().':8000/opengnsys/IniciarSesion', + url: 'https://'.$client->getIp().':8000/opengnsys/IniciarSesion', params: [ 'json' => $data, - ] + ], + token: $client->getToken(), ); if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) { @@ -77,7 +83,7 @@ class LoginAction extends AbstractOgAgentController $this->entityManager->persist($client); $this->entityManager->flush(); - $this->createService->__invoke($client, CommandTypes::REBOOT, TraceStatus::SUCCESS, $jobId, []); + $this->createService->__invoke($client, CommandTypes::LOGIN, TraceStatus::SUCCESS, $jobId, []); } return new JsonResponse(data: [], status: Response::HTTP_OK); diff --git a/src/Controller/OgAgent/RebootAction.php b/src/Controller/OgAgent/RebootAction.php index b83af31..410bba6 100644 --- a/src/Controller/OgAgent/RebootAction.php +++ b/src/Controller/OgAgent/RebootAction.php @@ -55,7 +55,7 @@ class RebootAction extends AbstractOgAgentController $response = $this->createRequest( method: 'POST', - url: 'http://'.$client->getIp().':8000/'.$endpoint, + url: 'https://'.$client->getIp().':8000/'.$endpoint, params: [ 'json' => $data, ], diff --git a/src/Dto/Input/BootClientsInput.php b/src/Dto/Input/BootClientsInput.php index 4bc68b0..a430967 100644 --- a/src/Dto/Input/BootClientsInput.php +++ b/src/Dto/Input/BootClientsInput.php @@ -2,7 +2,20 @@ namespace App\Dto\Input; -class BootClientInput -{ +use App\Dto\Output\ClientOutput; +use App\Dto\Output\PartitionOutput; +use Symfony\Component\Serializer\Annotation\Groups; + +final class BootClientsInput +{ + /** + * @var ClientOutput[] + */ + #[Groups(['client:write'])] + public array $clients = []; + + + #[Groups(['client:write'])] + public ?PartitionOutput $partition = null; +} -} \ No newline at end of file