From 2f89e5bc578d9decc0c1f44d7382561d0dd0c567 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Wed, 20 Nov 2024 16:00:44 +0100 Subject: [PATCH] Updated APIS, and general improvements --- config/api_platform/Image.yaml | 17 +++-- env.json | 5 +- migrations/Version20241120050107.php | 35 +++++++++ src/Controller/DeployImageAction.php | 36 ++-------- src/Controller/OgAgent/CreateImageAction.php | 7 +- src/Controller/OgAgent/DeployImageAction.php | 8 ++- src/Controller/OgAgent/StatusAction.php | 71 ++++++++++++------- .../OgAgent/Webhook/AgentController.php | 26 ++----- .../OgAgent/Webhook/ClientsController.php | 46 ++++++++++-- .../OgBoot/AbstractOgBootController.php | 2 + src/Controller/OgBoot/OgLive/GetAction.php | 2 +- .../OgBoot/OgLive/GetCollectionAction.php | 2 +- .../OgBoot/OgLive/GetDefaultAction.php | 2 +- .../OgBoot/OgLive/GetIsosAction.php | 2 +- .../OgBoot/OgLive/InstallAction.php | 2 +- .../OgBoot/OgLive/SetDefaultAction.php | 2 +- src/Controller/OgBoot/OgLive/SyncAction.php | 2 +- .../OgBoot/OgLive/UninstallAction.php | 2 +- .../OgBoot/PxeBootFile/GetAction.php | 2 +- .../PxeBootFile/GetCollectionAction.php | 2 +- .../OgBoot/PxeBootFile/PostAction.php | 17 ++--- .../OgBoot/PxeTemplate/DeleteAction.php | 2 +- .../OgBoot/PxeTemplate/GetAction.php | 2 +- .../PxeTemplate/GetCollectionAction.php | 2 +- .../OgBoot/PxeTemplate/PostAction.php | 2 +- .../OgBoot/PxeTemplate/SyncAction.php | 2 +- .../OgDhcp/AbstractOgDhcpController.php | 2 +- src/Controller/OgDhcp/Subnet/DeleteAction.php | 2 +- .../OgDhcp/Subnet/DeleteHostAction.php | 2 +- src/Controller/OgDhcp/Subnet/GetAction.php | 2 +- .../OgDhcp/Subnet/GetCollectionAction.php | 2 +- .../OgDhcp/Subnet/GetHostsAction.php | 2 +- src/Controller/OgDhcp/Subnet/PostAction.php | 2 +- .../OgDhcp/Subnet/PostHostAction.php | 2 +- src/Controller/OgDhcp/Subnet/PutAction.php | 2 +- .../OgDhcp/Subnet/PutHostAction.php | 2 +- src/Controller/OgDhcp/Subnet/SyncAction.php | 2 +- .../Image/CreateAuxFilesAction.php | 4 +- .../Image/DeletePermanentAction.php | 2 +- .../OgRepository/Image/DeleteTrashAction.php | 2 +- .../OgRepository/Image/DeployImageAction.php | 6 +- .../OgRepository/Image/RecoverAction.php | 51 +++++++++++++ src/Dto/Input/NetworkSettingsInput.php | 10 +++ src/Dto/Output/NetworkSettingsOutput.php | 8 +++ src/Dto/Output/TraceOutput.php | 4 +- src/Entity/Trace.php | 9 ++- src/Model/CommandTypes.php | 38 ++++++++++ src/Model/ImageStatus.php | 2 + src/Service/CreatePartitionService.php | 50 +++++++++++++ src/Service/Trace/CreateService.php | 4 +- src/State/Processor/ImageProcessor.php | 2 +- translations/validators.en.yaml | 1 + translations/validators.es.yaml | 1 + 53 files changed, 375 insertions(+), 141 deletions(-) create mode 100644 migrations/Version20241120050107.php create mode 100644 src/Controller/OgRepository/Image/RecoverAction.php create mode 100644 src/Model/CommandTypes.php create mode 100644 src/Service/CreatePartitionService.php diff --git a/config/api_platform/Image.yaml b/config/api_platform/Image.yaml index a338c1e..8aea897 100644 --- a/config/api_platform/Image.yaml +++ b/config/api_platform/Image.yaml @@ -51,8 +51,8 @@ resources: trash_delete_image_ogrepository: shortName: OgRepository Server description: Delete Image in OgRepository - class: ApiPlatform\Metadata\Delete - method: DELETE + class: ApiPlatform\Metadata\Post + method: POST input: false uriTemplate: /images/server/{uuid}/delete-trash controller: App\Controller\OgRepository\Image\DeleteTrashAction @@ -60,12 +60,21 @@ resources: permanent_delete_image_ogrepository: shortName: OgRepository Server description: Delete Image in OgRepository - class: ApiPlatform\Metadata\Delete - method: DELETE + class: ApiPlatform\Metadata\Post + method: POST input: false uriTemplate: /images/server/{uuid}/delete-permanent controller: App\Controller\OgRepository\Image\DeletePermanentAction + recover_image_ogrepository: + shortName: OgRepository Server + description: Recover Image in OgRepository + class: ApiPlatform\Metadata\Post + method: POST + input: false + uriTemplate: /images/server/{uuid}/recover + controller: App\Controller\OgRepository\Image\RecoverAction + properties: App\Entity\Image: id: diff --git a/env.json b/env.json index 1a246ee..d5d8034 100644 --- a/env.json +++ b/env.json @@ -1,7 +1,8 @@ { "vars": { - "OG_BOOT_API_URL": "http:\/\/192.168.18.48", - "OG_DHCP_API_URL": "http:\/\/192.168.18.48:81", + "OG_BOOT_API_URL": "192.168.68.58", + "OG_DHCP_API_URL": "192.168.68.58:81", + "OG_CORE_IP": "192.168.68.62", "UDS_AUTH_LOGIN": "Usuarios locales", "UDS_AUTH_USERNAME": "natiqindel", "UDS_AUTH_PASSWORD": "correct horse battery staple", diff --git a/migrations/Version20241120050107.php b/migrations/Version20241120050107.php new file mode 100644 index 0000000..3b0b972 --- /dev/null +++ b/migrations/Version20241120050107.php @@ -0,0 +1,35 @@ +addSql('ALTER TABLE trace DROP FOREIGN KEY FK_315BD5A133E1689A'); + $this->addSql('DROP INDEX IDX_315BD5A133E1689A ON trace'); + $this->addSql('ALTER TABLE trace ADD command VARCHAR(255) DEFAULT NULL, DROP command_id'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE trace ADD command_id INT NOT NULL, DROP command'); + $this->addSql('ALTER TABLE trace ADD CONSTRAINT FK_315BD5A133E1689A FOREIGN KEY (command_id) REFERENCES command (id)'); + $this->addSql('CREATE INDEX IDX_315BD5A133E1689A ON trace (command_id)'); + } +} diff --git a/src/Controller/DeployImageAction.php b/src/Controller/DeployImageAction.php index e61f4f3..7b8cf9e 100644 --- a/src/Controller/DeployImageAction.php +++ b/src/Controller/DeployImageAction.php @@ -8,6 +8,7 @@ use App\Dto\Input\DeployImageInput; use App\Entity\Command; use App\Entity\Image; use App\Entity\OrganizationalUnit; +use App\Model\CommandTypes; use App\Model\DeployMethodTypes; use App\Model\TraceStatus; use App\Service\Trace\CreateService; @@ -32,8 +33,6 @@ class DeployImageAction extends AbstractController public function __invoke(DeployImageInput $input, Image $image): JsonResponse { - $command = $this->entityManager->getRepository(Command::class)->findOneBy(['name' => 'Restaurar Imagen']); - $partitionInfo = json_decode($image->getPartitionInfo(), true); $inputData = [ @@ -52,43 +51,18 @@ class DeployImageAction extends AbstractController switch ($input->method){ case DeployMethodTypes::UNICAST: - $data = [ - 'dsk' => (string) $partitionInfo['numDisk'], - 'par' => (string) $partitionInfo['numPartition'], - 'ifs' => "1", - 'cpt' => "83", - 'idi' => $image->getUuid(), - 'nci' => $image->getName(), - 'ipr' => $image->getRepository()->getIp(), - 'nfn' => 'RestaurarImagen', - 'ptc' => DeployMethodTypes::UNICAST, - 'ids' => '0' - ]; - - $agentJobId = $this->deployImageOgAgentAction->__invoke($image, $command, $input->client->getEntity()); - $this->createService->__invoke($input->client->getEntity(), $command, TraceStatus::IN_PROGRESS, $agentJobId, $inputData); + $agentJobId = $this->deployImageOgAgentAction->__invoke($image, $input, DeployMethodTypes::UNICAST); + $this->createService->__invoke($input->client->getEntity(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, $agentJobId, $inputData); break; case DeployMethodTypes::MULTICAST: - $data = [ - 'dsk' => (string) $image->getPartitionInfo()['numDisk'], - 'par' => (string) $image->getPartitionInfo()['numPartition'], - 'cpt' => "83", - 'idi' => $image->getUuid(), - 'nci' => $image->getName(), - 'ipr' => $image->getRepository()->getIp(), - 'nfn' => 'CrearImagen', - 'ids' => '0' - ]; - - $agentJobId = $this->deployImageOgAgentAction->__invoke($image, $command); - $this->createService->__invoke($image->getClient(), $command, TraceStatus::IN_PROGRESS, $agentJobId, $inputData); + $agentJobId = $this->deployImageOgAgentAction->__invoke($image, $input, DeployMethodTypes::MULTICAST); + $this->createService->__invoke($image->getClient(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, $agentJobId, $inputData); break; } - return new JsonResponse(data: [], status: Response::HTTP_OK); } } diff --git a/src/Controller/OgAgent/CreateImageAction.php b/src/Controller/OgAgent/CreateImageAction.php index abdec18..4e01293 100644 --- a/src/Controller/OgAgent/CreateImageAction.php +++ b/src/Controller/OgAgent/CreateImageAction.php @@ -9,6 +9,8 @@ use App\Entity\Command; use App\Entity\Image; use App\Entity\Trace; use App\Model\ClientStatus; +use App\Model\CommandTypes; +use App\Model\ImageStatus; use App\Model\TraceStatus; use App\Service\Trace\CreateService; use Doctrine\ORM\EntityManagerInterface; @@ -71,14 +73,15 @@ class CreateImageAction extends AbstractController $jobId = json_decode($response->getContent(), true)['job_id']; - $command = $this->entityManager->getRepository(Command::class)->findOneBy(['name' => 'Crear Imagen']); + $image->setStatus(ImageStatus::IN_PROGRESS); + $this->entityManager->persist($image); $client = $image->getClient(); $client->setStatus(ClientStatus::BUSY); $this->entityManager->persist($client); $this->entityManager->flush(); - $this->createService->__invoke($image->getClient(), $command, TraceStatus::IN_PROGRESS, $jobId, []); + $this->createService->__invoke($image->getClient(), CommandTypes::CREATE_IMAGE, TraceStatus::IN_PROGRESS, $jobId, []); return new JsonResponse(data: $image, status: Response::HTTP_OK); } diff --git a/src/Controller/OgAgent/DeployImageAction.php b/src/Controller/OgAgent/DeployImageAction.php index 0d3e7d3..c8e2d01 100644 --- a/src/Controller/OgAgent/DeployImageAction.php +++ b/src/Controller/OgAgent/DeployImageAction.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Controller\OgAgent; +use App\Dto\Input\DeployImageInput; use App\Entity\Client; use App\Entity\Command; use App\Entity\Image; @@ -34,7 +35,7 @@ class DeployImageAction extends AbstractController } - public function __invoke(Image $image, Command $command, Client $client) + public function __invoke(Image $image, DeployImageInput $input, string $method) { if (!$image->getClient()->getIp()) { throw new ValidatorException('IP is required'); @@ -42,6 +43,9 @@ class DeployImageAction extends AbstractController $partitionInfo = json_decode($image->getPartitionInfo(), true); + /** @var Client $client */ + $client = $input->client->getEntity(); + $data = [ 'dsk' => (string) $partitionInfo['numDisk'], 'par' => (string) $partitionInfo['numPartition'], @@ -50,7 +54,7 @@ class DeployImageAction extends AbstractController 'nci' => $image->getName(), 'ipr' => $image->getRepository()->getIp(), 'nfn' => 'RestaurarImagen', - 'ptc' => 'unicast', + 'ptc' => $method, 'ids' => '0' ]; diff --git a/src/Controller/OgAgent/StatusAction.php b/src/Controller/OgAgent/StatusAction.php index 5428a33..a8f7211 100644 --- a/src/Controller/OgAgent/StatusAction.php +++ b/src/Controller/OgAgent/StatusAction.php @@ -7,6 +7,7 @@ use App\Entity\OperativeSystem; use App\Entity\Partition; use App\Model\ClientStatus; use App\Model\OgLiveStatus; +use App\Service\CreatePartitionService; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpClient\HttpClient; @@ -26,7 +27,8 @@ class StatusAction extends AbstractController { public function __construct( protected readonly EntityManagerInterface $entityManager, - protected readonly HttpClientInterface $httpClient + protected readonly HttpClientInterface $httpClient, + protected readonly CreatePartitionService $createPartitionService ) {} /** @@ -41,6 +43,17 @@ class StatusAction extends AbstractController throw new ValidatorException('IP is required'); } + if ($client->getStatus() === ClientStatus::OG_LIVE) { + $this->getOgLiveStatus($client); + } + + if ($client->getStatus() === ClientStatus::LINUX) { + $this->getSOStatus($client); + } + } + + public function getOgLiveStatus (Client $client): JsonResponse + { try { $response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/ogAdmClient/status', [ 'verify_peer' => false, @@ -66,33 +79,43 @@ class StatusAction extends AbstractController $data = json_decode($response->getContent(), true); if (isset($data['cfg'])) { - foreach ($data['cfg'] as $cfg) { - $partitionEntity = $this->entityManager->getRepository(Partition::class) - ->findOneBy(['client' => $client, 'diskNumber' => $cfg['disk'], 'partitionNumber' => $cfg['par']]); + $this->createPartitionService->__invoke($data, $client); + } - if (!$partitionEntity) { - $partitionEntity = new Partition(); - } + $this->entityManager->persist($client); + $this->entityManager->flush(); - if (isset($cfg['soi']) && $cfg['soi'] !== '') { - $operativeSystem = $this->entityManager->getRepository(OperativeSystem::class) - ->findOneBy(['name' => $cfg['soi']]); + return new JsonResponse(status: Response::HTTP_OK); + } - if (!$operativeSystem) { - $operativeSystem = new OperativeSystem(); - $operativeSystem->setName($cfg['soi']); - $this->entityManager->persist($operativeSystem); - } - $partitionEntity->setOperativeSystem($operativeSystem); - } + public function getSOStatus (Client $client): JsonResponse + { + try { + $response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/opengnsys/status', [ + 'verify_peer' => false, + 'verify_host' => false, + 'timeout' => 10, + 'headers' => [ + 'Content-Type' => 'application/json', + ], + 'json' => [], + ]); + $statusCode = $response->getStatusCode(); + $client->setStatus($statusCode === Response::HTTP_OK ? ClientStatus::LINUX : ClientStatus::OFF); - $partitionEntity->setClient($client); - $partitionEntity->setDiskNumber($cfg['disk']); - $partitionEntity->setPartitionNumber($cfg['par']); - $partitionEntity->setSize($cfg['tam']); - $partitionEntity->setMemoryUsage(((int) $cfg['uso']) * 100); - $this->entityManager->persist($partitionEntity); - } + } catch (TransportExceptionInterface $e) { + $client->setStatus(ClientStatus::OFF); + + return new JsonResponse( + data: ['error' => $e->getMessage()], + status: Response::HTTP_INTERNAL_SERVER_ERROR + ); + } + + $data = json_decode($response->getContent(), true); + + if (isset($data['cfg'])) { + $this->createPartitionService->__invoke($data, $client); } $this->entityManager->persist($client); diff --git a/src/Controller/OgAgent/Webhook/AgentController.php b/src/Controller/OgAgent/Webhook/AgentController.php index 0d459ed..4ed9f5d 100644 --- a/src/Controller/OgAgent/Webhook/AgentController.php +++ b/src/Controller/OgAgent/Webhook/AgentController.php @@ -7,6 +7,7 @@ namespace App\Controller\OgAgent\Webhook; use App\Entity\Client; use App\Entity\OrganizationalUnit; use App\Entity\Partition; +use App\Service\CreatePartitionService; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; @@ -19,7 +20,8 @@ use Symfony\Component\Routing\Attribute\Route; class AgentController extends AbstractController { public function __construct( - protected readonly EntityManagerInterface $entityManager + protected readonly EntityManagerInterface $entityManager, + protected readonly CreatePartitionService $createPartitionService ) { } @@ -42,26 +44,10 @@ class AgentController extends AbstractController return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND); } - foreach ($data['cfg'] as $cfg) { - if (isset($cfg['disk']) && isset($cfg['par'])) { - $partitionEntity = $this->entityManager->getRepository(Partition::class) - ->findOneBy(['client' => $clientEntity, 'diskNumber' => $cfg['disk'], 'partitionNumber' => $cfg['par']]); - - if (!$partitionEntity) { - $partitionEntity = new Partition(); - } - - $partitionEntity->setClient($clientEntity); - $partitionEntity->setDiskNumber((int)$cfg['disk']); - $partitionEntity->setPartitionNumber((int) $cfg['par']); - $partitionEntity->setSize((int) $cfg['tam'] ?? null); - $partitionEntity->setMemoryUsage((int) $cfg['uso'] * 100 ?? null); - $partitionEntity->setFileSystem($cfg['fsi'] ?? null); - - $this->entityManager->persist($partitionEntity); - } + if (isset($data['cfg'])) { + $this->createPartitionService->__invoke($data, $clientEntity); } - + $this->entityManager->flush(); $center = $this->entityManager->getRepository(OrganizationalUnit::class)->find($clientEntity->getOrganizationalUnit()->getId()); diff --git a/src/Controller/OgAgent/Webhook/ClientsController.php b/src/Controller/OgAgent/Webhook/ClientsController.php index eb79d72..2ceb9ee 100644 --- a/src/Controller/OgAgent/Webhook/ClientsController.php +++ b/src/Controller/OgAgent/Webhook/ClientsController.php @@ -6,10 +6,14 @@ use App\Controller\OgRepository\Image\CreateAuxFilesAction; use App\Entity\Image; use App\Entity\OperativeSystem; use App\Entity\Partition; +use App\Entity\Software; +use App\Entity\SoftwareProfile; use App\Entity\Trace; use App\Model\ClientStatus; use App\Model\ImageStatus; +use App\Model\SoftwareTypes; use App\Model\TraceStatus; +use App\Service\CreatePartitionService; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; @@ -28,7 +32,8 @@ class ClientsController extends AbstractController { public function __construct( protected readonly EntityManagerInterface $entityManager, - public readonly CreateAuxFilesAction $createAuxFilesAction + public readonly CreateAuxFilesAction $createAuxFilesAction, + protected readonly CreatePartitionService $createPartitionService ) { } @@ -55,18 +60,24 @@ class ClientsController extends AbstractController $trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]); $image = $this->entityManager->getRepository(Image::class)->findOneBy(['uuid' => $data['idi']]); + if (!$image) { + return new JsonResponse(['message' => 'Image not found'], Response::HTTP_NOT_FOUND); + } + if ($data['res'] === 1) { $trace->setStatus(TraceStatus::SUCCESS); $trace->setFinishedAt(new \DateTime()); - $image->setStatus(ImageStatus::PENDING); + $image->setStatus(ImageStatus::AUX_FILES_PENDING); $image->setCreated(true); + if (isset($data['cfg'])) { + $this->createPartitionService->__invoke($data, $image->getClient()); + } + $this->createSoftwareProfile($data['inv_sft'], $image); $this->createAuxFilesAction->__invoke($image); - } else { $trace->setStatus(TraceStatus::FAILED); $trace->setFinishedAt(new \DateTime()); $trace->setOutput($data['der']); - $image->setCreated(false); } $this->entityManager->persist($image); @@ -99,4 +110,31 @@ class ClientsController extends AbstractController return new JsonResponse([], Response::HTTP_OK); } + + public function createSoftwareProfile (string $base64Data, Image $image): void + { + $decodedData = base64_decode($base64Data); + + $softwareList = explode("\n", $decodedData); + + $softwareProfile = new SoftwareProfile(); + $softwareProfile->setDescription('Perfil : '.$image->getName()); + $softwareProfile->setOrganizationalUnit($image->getClient()->getOrganizationalUnit()); + + foreach ($softwareList as $software) { + $software = trim($software); + $softwareEntity = $this->entityManager->getRepository(Software::class)->findOneBy(['name' => $software]); + if (!$softwareEntity) { + $softwareEntity = new Software(); + $softwareEntity->setName($software); + $softwareEntity->setType(SoftwareTypes::APPLICATION); + $this->entityManager->persist($softwareEntity); + } + + $softwareEntity->addSoftwareProfile($softwareProfile); + } + + $this->entityManager->persist($softwareProfile); + $this->entityManager->flush(); + } } \ No newline at end of file diff --git a/src/Controller/OgBoot/AbstractOgBootController.php b/src/Controller/OgBoot/AbstractOgBootController.php index eef632b..ee8b178 100644 --- a/src/Controller/OgBoot/AbstractOgBootController.php +++ b/src/Controller/OgBoot/AbstractOgBootController.php @@ -23,6 +23,8 @@ abstract class AbstractOgBootController extends AbstractController public function __construct( #[Autowire(env: 'OG_BOOT_API_URL')] protected string $ogBootApiUrl, + #[Autowire(env: 'OG_CORE_IP')] + protected string $ogCoreIP, protected readonly EntityManagerInterface $entityManager ) { diff --git a/src/Controller/OgBoot/OgLive/GetAction.php b/src/Controller/OgBoot/OgLive/GetAction.php index 8635aee..54ebe45 100644 --- a/src/Controller/OgBoot/OgLive/GetAction.php +++ b/src/Controller/OgBoot/OgLive/GetAction.php @@ -29,7 +29,7 @@ class GetAction extends AbstractOgBootController throw new ValidatorException('Checksum is required'); } - $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum()); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum()); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/OgLive/GetCollectionAction.php b/src/Controller/OgBoot/OgLive/GetCollectionAction.php index 930b237..41cacdf 100644 --- a/src/Controller/OgBoot/OgLive/GetCollectionAction.php +++ b/src/Controller/OgBoot/OgLive/GetCollectionAction.php @@ -24,7 +24,7 @@ class GetCollectionAction extends AbstractOgBootController */ public function __invoke(HttpClientInterface $httpClient): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/oglives'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives'); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/OgLive/GetDefaultAction.php b/src/Controller/OgBoot/OgLive/GetDefaultAction.php index 94f3456..3c77859 100644 --- a/src/Controller/OgBoot/OgLive/GetDefaultAction.php +++ b/src/Controller/OgBoot/OgLive/GetDefaultAction.php @@ -23,7 +23,7 @@ class GetDefaultAction extends AbstractOgBootController */ public function __invoke(HttpClientInterface $httpClient): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/default'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/default'); return new JsonResponse(status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/OgLive/GetIsosAction.php b/src/Controller/OgBoot/OgLive/GetIsosAction.php index 90ddb19..1acdbd2 100644 --- a/src/Controller/OgBoot/OgLive/GetIsosAction.php +++ b/src/Controller/OgBoot/OgLive/GetIsosAction.php @@ -24,7 +24,7 @@ class GetIsosAction extends AbstractOgBootController */ public function __invoke(HttpClientInterface $httpClient): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/isos'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/isos'); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/OgLive/InstallAction.php b/src/Controller/OgBoot/OgLive/InstallAction.php index e2bbe17..07b68ac 100644 --- a/src/Controller/OgBoot/OgLive/InstallAction.php +++ b/src/Controller/OgBoot/OgLive/InstallAction.php @@ -38,7 +38,7 @@ class InstallAction extends AbstractOgBootController ] ]; - $content = $this->createRequest($httpClient, 'POST', $this->ogBootApiUrl.'/ogboot/v1/oglives/install', $params); + $content = $this->createRequest($httpClient, 'POST', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/install', $params); $data->setStatus(OgLiveStatus::PENDING); $entityManager->persist($data); diff --git a/src/Controller/OgBoot/OgLive/SetDefaultAction.php b/src/Controller/OgBoot/OgLive/SetDefaultAction.php index 3cf7184..896ac3b 100644 --- a/src/Controller/OgBoot/OgLive/SetDefaultAction.php +++ b/src/Controller/OgBoot/OgLive/SetDefaultAction.php @@ -36,7 +36,7 @@ class SetDefaultAction extends AbstractOgBootController ] ]; - $content = $this->createRequest($httpClient, 'PUT', $this->ogBootApiUrl.'/ogboot/v1/oglives/default', $params); + $content = $this->createRequest($httpClient, 'PUT', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/default', $params); $oldDefaultOgLive = $this->entityManager->getRepository(OgLive::class)->findBy(['isDefault' => true]); diff --git a/src/Controller/OgBoot/OgLive/SyncAction.php b/src/Controller/OgBoot/OgLive/SyncAction.php index 0c036a2..791dba5 100644 --- a/src/Controller/OgBoot/OgLive/SyncAction.php +++ b/src/Controller/OgBoot/OgLive/SyncAction.php @@ -27,7 +27,7 @@ class SyncAction extends AbstractOgBootController */ public function __invoke(HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl . '/ogboot/v1/oglives'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl . '/ogboot/v1/oglives'); foreach ($content['message']['installed_ogLives'] as $ogLive) { $ogLiveEntity = $this->entityManager->getRepository(OgLive::class)->findOneBy(['checksum' => $ogLive['id']]); diff --git a/src/Controller/OgBoot/OgLive/UninstallAction.php b/src/Controller/OgBoot/OgLive/UninstallAction.php index d0ea542..70b3c0b 100644 --- a/src/Controller/OgBoot/OgLive/UninstallAction.php +++ b/src/Controller/OgBoot/OgLive/UninstallAction.php @@ -31,7 +31,7 @@ class UninstallAction extends AbstractOgBootController throw new ValidatorException('Checksum is required'); } - $content = $this->createRequest($httpClient, 'DELETE', $this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum()); + $content = $this->createRequest($httpClient, 'DELETE', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum()); $entityManager->remove($data); $entityManager->flush(); diff --git a/src/Controller/OgBoot/PxeBootFile/GetAction.php b/src/Controller/OgBoot/PxeBootFile/GetAction.php index 7f51e2b..4f4fb02 100644 --- a/src/Controller/OgBoot/PxeBootFile/GetAction.php +++ b/src/Controller/OgBoot/PxeBootFile/GetAction.php @@ -27,7 +27,7 @@ class GetAction extends AbstractOgBootController public function __invoke(Client $client, HttpClientInterface $httpClient): JsonResponse { try { - $response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/pxes/'.$client->getMac(), [ + $response = $httpClient->request('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxes/'.$client->getMac(), [ 'headers' => [ 'accept' => 'application/json', ], diff --git a/src/Controller/OgBoot/PxeBootFile/GetCollectionAction.php b/src/Controller/OgBoot/PxeBootFile/GetCollectionAction.php index f870364..3d53a9f 100644 --- a/src/Controller/OgBoot/PxeBootFile/GetCollectionAction.php +++ b/src/Controller/OgBoot/PxeBootFile/GetCollectionAction.php @@ -26,7 +26,7 @@ class GetCollectionAction extends AbstractOgBootController */ public function __invoke(HttpClientInterface $httpClient): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/pxes'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxes'); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/PxeBootFile/PostAction.php b/src/Controller/OgBoot/PxeBootFile/PostAction.php index 01dd970..1bc03ba 100644 --- a/src/Controller/OgBoot/PxeBootFile/PostAction.php +++ b/src/Controller/OgBoot/PxeBootFile/PostAction.php @@ -36,19 +36,20 @@ class PostAction extends AbstractOgBootController 'mac' => strtolower($client->getMac()), 'lang' => 'es_ES.UTF_8', 'ip' => $client->getIp(), - //'server_ip' => '192.168.2.4', //rootServer (ogCore) + 'server_ip' => $this->ogBootApiUrl, 'router' => $client->getOrganizationalUnit()->getNetworkSettings()->getRouter(), 'netmask' => $client->getOrganizationalUnit()->getNetworkSettings() ? $client->getOrganizationalUnit()->getNetworkSettings()->getNetmask() : '255.255.255.0', 'computer_name' => $client->getName(), 'netiface' => $client->getNetiface(), 'group' => $client->getOrganizationalUnit()->getName(), - 'ogrepo' => $client->getRepository() ? $client->getRepository()->getIp() : '192.168.2.4', - //'ogcore' => 'parametro_consola', - //'oglive' => '192.168.2.4', - 'oglog' => '192.168.2.4', - //'ogshare' => '192.168.2.4', + 'ogrepo' => $client->getRepository()->getIp() , + 'ogcore' => $this->ogCoreIP, + 'oglive' => $this->ogBootApiUrl, + 'oglog' => $client->getOrganizationalUnit()->getNetworkSettings()?->getOgLog(), + 'ogshare' => $client->getOrganizationalUnit()->getNetworkSettings()?->getOgShare() + ? $client->getOrganizationalUnit()->getNetworkSettings()?->getOgShare(): $this->ogBootApiUrl, 'oglivedir' => $client->getOgLive()->getFilename(), - 'ogprof' => 'false', // cliente del profesor + 'ogprof' => 'false', 'hardprofile' => $client->getHardwareProfile() ? $client->getHardwareProfile()->getDescription() : 'default', 'ogntp' => $client->getOrganizationalUnit()->getNetworkSettings()?->getNtp(), //optional 'ogdns' => $client->getOrganizationalUnit()->getNetworkSettings()?->getDns(), //optional @@ -58,7 +59,7 @@ class PostAction extends AbstractOgBootController ]; try { - $response = $httpClient->request('POST', $this->ogBootApiUrl.'/ogboot/v1/pxes', [ + $response = $httpClient->request('POST', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxes', [ 'headers' => [ 'accept' => 'application/json', 'Content-Type' => 'application/json', diff --git a/src/Controller/OgBoot/PxeTemplate/DeleteAction.php b/src/Controller/OgBoot/PxeTemplate/DeleteAction.php index ba6c49d..eb42411 100644 --- a/src/Controller/OgBoot/PxeTemplate/DeleteAction.php +++ b/src/Controller/OgBoot/PxeTemplate/DeleteAction.php @@ -27,7 +27,7 @@ class DeleteAction extends AbstractOgBootController public function __invoke(PxeTemplate $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse { try { - $response = $httpClient->request('DELETE', $this->ogBootApiUrl.'/ogboot/v1/pxe-templates/'.$data->getName(), [ + $response = $httpClient->request('DELETE', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates/'.$data->getName(), [ 'headers' => [ 'accept' => 'application/json', ], diff --git a/src/Controller/OgBoot/PxeTemplate/GetAction.php b/src/Controller/OgBoot/PxeTemplate/GetAction.php index 5bbc2c0..6a61c17 100644 --- a/src/Controller/OgBoot/PxeTemplate/GetAction.php +++ b/src/Controller/OgBoot/PxeTemplate/GetAction.php @@ -26,7 +26,7 @@ class GetAction extends AbstractOgBootController public function __invoke(PxeTemplate $template, HttpClientInterface $httpClient): JsonResponse { try { - $response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/pxe-templates/'.$template->getName(), [ + $response = $httpClient->request('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates/'.$template->getName(), [ 'headers' => [ 'accept' => 'application/json', ], diff --git a/src/Controller/OgBoot/PxeTemplate/GetCollectionAction.php b/src/Controller/OgBoot/PxeTemplate/GetCollectionAction.php index c294cae..623c8d3 100644 --- a/src/Controller/OgBoot/PxeTemplate/GetCollectionAction.php +++ b/src/Controller/OgBoot/PxeTemplate/GetCollectionAction.php @@ -25,7 +25,7 @@ class GetCollectionAction extends AbstractOgBootController public function __invoke(HttpClientInterface $httpClient): JsonResponse { try { - $response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/pxe-templates', [ + $response = $httpClient->request('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates', [ 'headers' => [ 'accept' => 'application/json', ], diff --git a/src/Controller/OgBoot/PxeTemplate/PostAction.php b/src/Controller/OgBoot/PxeTemplate/PostAction.php index a448bf1..e6fd198 100644 --- a/src/Controller/OgBoot/PxeTemplate/PostAction.php +++ b/src/Controller/OgBoot/PxeTemplate/PostAction.php @@ -27,7 +27,7 @@ class PostAction extends AbstractOgBootController public function __invoke(PxeTemplate $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse { try { - $response = $httpClient->request('POST', $this->ogBootApiUrl.'/ogboot/v1/pxe-templates', [ + $response = $httpClient->request('POST', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates', [ 'headers' => [ 'accept' => 'application/json', 'Content-Type' => 'application/json', diff --git a/src/Controller/OgBoot/PxeTemplate/SyncAction.php b/src/Controller/OgBoot/PxeTemplate/SyncAction.php index 50746bd..8d85270 100644 --- a/src/Controller/OgBoot/PxeTemplate/SyncAction.php +++ b/src/Controller/OgBoot/PxeTemplate/SyncAction.php @@ -28,7 +28,7 @@ class SyncAction extends AbstractOgBootController */ public function __invoke(HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl . '/ogboot/v1/pxe-templates'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl . '/ogboot/v1/pxe-templates'); foreach ($content['message'] as $template) { $templateEntity = $this->entityManager->getRepository(PxeTemplate::class)->findOneBy(['name' => $template]); diff --git a/src/Controller/OgDhcp/AbstractOgDhcpController.php b/src/Controller/OgDhcp/AbstractOgDhcpController.php index 9166a1e..9288698 100644 --- a/src/Controller/OgDhcp/AbstractOgDhcpController.php +++ b/src/Controller/OgDhcp/AbstractOgDhcpController.php @@ -25,7 +25,7 @@ abstract class AbstractOgDhcpController extends AbstractController #[Autowire(env: 'OG_DHCP_API_URL')] protected readonly string $ogDhcpApiUrl, protected readonly EntityManagerInterface $entityManager, - protected readonly GetIpAddressAndNetmaskFromCIDRService $getIpAddressAndNetmaskFromCIDRService + protected readonly GetIpAddressAndNetmaskFromCIDRService $getIpAddressAndNetmaskFromCIDRService, ) { } diff --git a/src/Controller/OgDhcp/Subnet/DeleteAction.php b/src/Controller/OgDhcp/Subnet/DeleteAction.php index a00555a..7b9554c 100644 --- a/src/Controller/OgDhcp/Subnet/DeleteAction.php +++ b/src/Controller/OgDhcp/Subnet/DeleteAction.php @@ -29,7 +29,7 @@ class DeleteAction extends AbstractOgDhcpController throw new ValidatorException('Data Id is required'); } - $content = $this->createRequest($httpClient, 'DELETE', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId()); + $content = $this->createRequest($httpClient, 'DELETE', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId()); $this->entityManager->remove($data); $this->entityManager->flush(); diff --git a/src/Controller/OgDhcp/Subnet/DeleteHostAction.php b/src/Controller/OgDhcp/Subnet/DeleteHostAction.php index cf32b80..8b2c251 100644 --- a/src/Controller/OgDhcp/Subnet/DeleteHostAction.php +++ b/src/Controller/OgDhcp/Subnet/DeleteHostAction.php @@ -42,7 +42,7 @@ class DeleteHostAction extends AbstractOgDhcpController ] ]; - $content = $this->createRequest($httpClient, 'DELETE', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId().'/hosts', $params); + $content = $this->createRequest($httpClient, 'DELETE', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId().'/hosts', $params); $data->removeClient($client); $this->entityManager->persist($data); diff --git a/src/Controller/OgDhcp/Subnet/GetAction.php b/src/Controller/OgDhcp/Subnet/GetAction.php index 77f1bce..257e26b 100644 --- a/src/Controller/OgDhcp/Subnet/GetAction.php +++ b/src/Controller/OgDhcp/Subnet/GetAction.php @@ -29,7 +29,7 @@ class GetAction extends AbstractOgDhcpController throw new ValidatorException('Checksum is required'); } - $content = $this->createRequest($httpClient, 'GET', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId()); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId()); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgDhcp/Subnet/GetCollectionAction.php b/src/Controller/OgDhcp/Subnet/GetCollectionAction.php index 9f9324c..95381d0 100644 --- a/src/Controller/OgDhcp/Subnet/GetCollectionAction.php +++ b/src/Controller/OgDhcp/Subnet/GetCollectionAction.php @@ -23,7 +23,7 @@ class GetCollectionAction extends AbstractOgDhcpController */ public function __invoke(HttpClientInterface $httpClient): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', $this->ogDhcpApiUrl . '/ogdhcp/v1/subnets'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogDhcpApiUrl . '/ogdhcp/v1/subnets'); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgDhcp/Subnet/GetHostsAction.php b/src/Controller/OgDhcp/Subnet/GetHostsAction.php index 52ca307..8056945 100644 --- a/src/Controller/OgDhcp/Subnet/GetHostsAction.php +++ b/src/Controller/OgDhcp/Subnet/GetHostsAction.php @@ -29,7 +29,7 @@ class GetHostsAction extends AbstractOgDhcpController throw new ValidatorException('Checksum is required'); } - $content = $this->createRequest($httpClient, 'GET', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId().'/hosts'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId().'/hosts'); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgDhcp/Subnet/PostAction.php b/src/Controller/OgDhcp/Subnet/PostAction.php index a4824f1..8cc41d1 100644 --- a/src/Controller/OgDhcp/Subnet/PostAction.php +++ b/src/Controller/OgDhcp/Subnet/PostAction.php @@ -35,7 +35,7 @@ class PostAction extends AbstractOgDhcpController ] ]; - $content = $this->createRequest($httpClient, 'POST', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets' , $params); + $content = $this->createRequest($httpClient, 'POST', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets' , $params); $data->setServerId($content['message']['id']); $data->setSynchronized(true); diff --git a/src/Controller/OgDhcp/Subnet/PostHostAction.php b/src/Controller/OgDhcp/Subnet/PostHostAction.php index 4330f8d..c6e3872 100644 --- a/src/Controller/OgDhcp/Subnet/PostHostAction.php +++ b/src/Controller/OgDhcp/Subnet/PostHostAction.php @@ -44,7 +44,7 @@ class PostHostAction extends AbstractOgDhcpController 'json' => $data ]; - $content = $this->createRequest($httpClient, 'POST', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$subnet->getServerId().'/hosts', $params); + $content = $this->createRequest($httpClient, 'POST', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$subnet->getServerId().'/hosts', $params); $subnet->addClient($clientEntity); $this->entityManager->persist($subnet); diff --git a/src/Controller/OgDhcp/Subnet/PutAction.php b/src/Controller/OgDhcp/Subnet/PutAction.php index 9e3004c..080f0bc 100644 --- a/src/Controller/OgDhcp/Subnet/PutAction.php +++ b/src/Controller/OgDhcp/Subnet/PutAction.php @@ -38,7 +38,7 @@ class PutAction extends AbstractOgDhcpController ] ]; - $content = $this->createRequest($httpClient, 'PUT', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId(), $params); + $content = $this->createRequest($httpClient, 'PUT', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId(), $params); $this->entityManager->persist($data); $this->entityManager->flush(); diff --git a/src/Controller/OgDhcp/Subnet/PutHostAction.php b/src/Controller/OgDhcp/Subnet/PutHostAction.php index 3815ca4..5ba614a 100644 --- a/src/Controller/OgDhcp/Subnet/PutHostAction.php +++ b/src/Controller/OgDhcp/Subnet/PutHostAction.php @@ -42,7 +42,7 @@ class PutHostAction extends AbstractOgDhcpController 'json' => $data ]; - $content = $this->createRequest($httpClient, 'PUT', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$subnet->getId().'/hosts', $params); + $content = $this->createRequest($httpClient, 'PUT', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$subnet->getId().'/hosts', $params); } return new JsonResponse(status: Response::HTTP_OK); diff --git a/src/Controller/OgDhcp/Subnet/SyncAction.php b/src/Controller/OgDhcp/Subnet/SyncAction.php index 29c86dc..0c301d7 100644 --- a/src/Controller/OgDhcp/Subnet/SyncAction.php +++ b/src/Controller/OgDhcp/Subnet/SyncAction.php @@ -26,7 +26,7 @@ class SyncAction extends AbstractOgDhcpController */ public function __invoke(HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', $this->ogDhcpApiUrl . '/ogdhcp/v1/subnets'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogDhcpApiUrl . '/ogdhcp/v1/subnets'); $arraySync = []; diff --git a/src/Controller/OgRepository/Image/CreateAuxFilesAction.php b/src/Controller/OgRepository/Image/CreateAuxFilesAction.php index 199b9da..70c9461 100644 --- a/src/Controller/OgRepository/Image/CreateAuxFilesAction.php +++ b/src/Controller/OgRepository/Image/CreateAuxFilesAction.php @@ -5,6 +5,7 @@ namespace App\Controller\OgRepository\Image; use App\Controller\OgRepository\AbstractOgRepositoryController; use App\Entity\Command; use App\Entity\Image; +use App\Model\CommandTypes; use App\Model\ImageStatus; use App\Model\TraceStatus; use Doctrine\ORM\EntityManagerInterface; @@ -40,14 +41,13 @@ class CreateAuxFilesAction extends AbstractOgRepositoryController ]; $content = $this->createRequest('POST', 'http://'.$data->getRepository()->getIp().':8006/ogrepository/v1/images/torrentsum', $params); - $command = $this->entityManager->getRepository(Command::class)->findOneBy(['name' => 'Crear Imagen']); $inputData = [ 'imageName' => $data->getName(), 'imageUuid' => $data->getUuid(), ]; - $this->createService->__invoke($data->getClient(), $command, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData); + $this->createService->__invoke($data->getClient(), CommandTypes::CREATE_IMAGE_AUX_FILE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData); $data->setStatus(ImageStatus::IN_PROGRESS); $this->entityManager->persist($data); diff --git a/src/Controller/OgRepository/Image/DeletePermanentAction.php b/src/Controller/OgRepository/Image/DeletePermanentAction.php index e560c6e..de36d77 100644 --- a/src/Controller/OgRepository/Image/DeletePermanentAction.php +++ b/src/Controller/OgRepository/Image/DeletePermanentAction.php @@ -29,7 +29,7 @@ class DeletePermanentAction extends AbstractOgRepositoryController throw new ValidatorException('Fullsum is required'); } - $content = $this->createRequest($httpClient, 'DELETE', 'http://'.$data->getRepository()->getIp().'/ogrepository/v1/images/'.$data->getImageFullsum().'?method=trash'); + $content = $this->createRequest( 'DELETE', 'http://'.$data->getRepository()->getIp().':8006/ogrepository/v1/images/'.$data->getImageFullsum().'?method=trash'); $this->entityManager->remove($data); $this->entityManager->flush(); diff --git a/src/Controller/OgRepository/Image/DeleteTrashAction.php b/src/Controller/OgRepository/Image/DeleteTrashAction.php index 59c671b..80a5c76 100644 --- a/src/Controller/OgRepository/Image/DeleteTrashAction.php +++ b/src/Controller/OgRepository/Image/DeleteTrashAction.php @@ -30,7 +30,7 @@ class DeleteTrashAction extends AbstractOgRepositoryController throw new ValidatorException('Fullsum is required'); } - $content = $this->createRequest($httpClient, 'DELETE', 'http://'.$data->getRepository()->getIp().'/ogrepository/v1/images/'.$data->getImageFullsum().'?method=trash'); + $content = $this->createRequest('DELETE', 'http://'.$data->getRepository()->getIp().':8006/ogrepository/v1/images/'.$data->getImageFullsum().'?method=trash'); $data->setStatus(ImageStatus::TRASH); $this->entityManager->persist($data); diff --git a/src/Controller/OgRepository/Image/DeployImageAction.php b/src/Controller/OgRepository/Image/DeployImageAction.php index db85293..c90a6e6 100644 --- a/src/Controller/OgRepository/Image/DeployImageAction.php +++ b/src/Controller/OgRepository/Image/DeployImageAction.php @@ -6,6 +6,7 @@ use App\Controller\OgRepository\AbstractOgRepositoryController; use App\Dto\Input\DeployImageInput; use App\Entity\Command; use App\Entity\Image; +use App\Model\CommandTypes; use App\Model\TraceStatus; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -20,7 +21,6 @@ use Symfony\Contracts\HttpClient\HttpClientInterface; class DeployImageAction extends AbstractOgRepositoryController { /** - * @throws TransportExceptionInterface * @throws ServerExceptionInterface * @throws RedirectionExceptionInterface * @throws ClientExceptionInterface @@ -29,9 +29,7 @@ class DeployImageAction extends AbstractOgRepositoryController { $client = $input->client; - $command = $this->entityManager->getRepository(Command::class)->findOneBy(['name' => 'Deploy Imagen']); - $this->createService->__invoke($data->getClient(), $command, TraceStatus::IN_PROGRESS, null); - + $this->createService->__invoke($data->getClient(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, null); return new JsonResponse(data: [], status: Response::HTTP_OK); } diff --git a/src/Controller/OgRepository/Image/RecoverAction.php b/src/Controller/OgRepository/Image/RecoverAction.php new file mode 100644 index 0000000..4e6b820 --- /dev/null +++ b/src/Controller/OgRepository/Image/RecoverAction.php @@ -0,0 +1,51 @@ +getImageFullsum()) { + throw new ValidatorException('Fullsum is required'); + } + + $params = [ + 'json' => [ + 'ID_img' => $data->getImageFullsum() + ] + ]; + + + $content = $this->createRequest('POST', 'http://'.$data->getRepository()->getIp().':8006/ogrepository/v1/trash/images', $params); + + $data->setStatus(ImageStatus::SUCCESS); + $this->entityManager->persist($data); + $this->entityManager->flush(); + + return new JsonResponse(data: $content, status: Response::HTTP_OK); + } +} \ No newline at end of file diff --git a/src/Dto/Input/NetworkSettingsInput.php b/src/Dto/Input/NetworkSettingsInput.php index e4dd125..6f33126 100644 --- a/src/Dto/Input/NetworkSettingsInput.php +++ b/src/Dto/Input/NetworkSettingsInput.php @@ -76,6 +76,12 @@ class NetworkSettingsInput #[Groups(['organizational-unit:write'])] public ?bool $validation = null; + #[Groups(['organizational-unit:write'])] + public ?string $oglog = null; + + #[Groups(['organizational-unit:write'])] + public ?string $ogshare = null; + public function __construct(?NetworkSettings $networkSettings = null) { if (!$networkSettings) { @@ -95,6 +101,8 @@ class NetworkSettingsInput $this->mcastSpeed = $networkSettings->getMcastSpeed(); $this->mcastPort = $networkSettings->getMcastPort(); $this->mcastMode = $networkSettings->getMcastMode(); + $this->oglog = $networkSettings->getOglog(); + $this->ogshare = $networkSettings->getOgshare(); if ($networkSettings->getMenu()) { $this->menu = new MenuOutput($networkSettings->getMenu()); @@ -130,6 +138,8 @@ class NetworkSettingsInput $networkSettings->setMcastSpeed($this->mcastSpeed); $networkSettings->setMcastPort($this->mcastPort); $networkSettings->setMcastMode($this->mcastMode); + $networkSettings->setOglog($this->oglog); + $networkSettings->setOgshare($this->ogshare); if ($this->menu) { $networkSettings->setMenu($this->menu->getEntity()); diff --git a/src/Dto/Output/NetworkSettingsOutput.php b/src/Dto/Output/NetworkSettingsOutput.php index c85361e..b13489e 100644 --- a/src/Dto/Output/NetworkSettingsOutput.php +++ b/src/Dto/Output/NetworkSettingsOutput.php @@ -57,6 +57,12 @@ final class NetworkSettingsOutput extends AbstractOutput #[Groups(['network-settings:read', "organizational-unit:read", "client:read"])] public ?OgLiveOutput $ogLive = null; + #[Groups(['network-settings:read', "organizational-unit:read", "client:read"])] + public ?string $oglog = null; + + #[Groups(['network-settings:read', "organizational-unit:read", "client:read"])] + public ?string $ogshare = null; + #[Groups(['network-settings:read', "organizational-unit:read", "client:read"])] public ?bool $validation = null; @@ -83,6 +89,8 @@ final class NetworkSettingsOutput extends AbstractOutput $this->mcastSpeed = $networkSettings->getMcastSpeed(); $this->mcastPort = $networkSettings->getMcastPort(); $this->mcastMode = $networkSettings->getMcastMode(); + $this->oglog = $networkSettings->getOglog(); + $this->ogshare = $networkSettings->getOgshare(); if ($networkSettings->getMenu()) { $this->menu = new MenuOutput($networkSettings->getMenu()); diff --git a/src/Dto/Output/TraceOutput.php b/src/Dto/Output/TraceOutput.php index e3a9b2d..8bbc100 100644 --- a/src/Dto/Output/TraceOutput.php +++ b/src/Dto/Output/TraceOutput.php @@ -11,7 +11,7 @@ use Symfony\Component\Serializer\Annotation\Groups; final class TraceOutput extends AbstractOutput { #[Groups(['trace:read'])] - public CommandOutput $command; + public ?string $command; #[Groups(['trace:read'])] public ClientOutput $client; @@ -44,7 +44,7 @@ final class TraceOutput extends AbstractOutput { parent::__construct($trace); - $this->command = new CommandOutput($trace->getCommand()); + $this->command = $trace->getCommand(); $this->client = new ClientOutput($trace->getClient()); $this->status = $trace->getStatus(); $this->jobId = $trace->getJobId(); diff --git a/src/Entity/Trace.php b/src/Entity/Trace.php index ae416bf..08bcc81 100644 --- a/src/Entity/Trace.php +++ b/src/Entity/Trace.php @@ -13,9 +13,8 @@ class Trace extends AbstractEntity #[ORM\JoinColumn(nullable: false)] private ?Client $client = null; - #[ORM\ManyToOne(inversedBy: 'traces')] - #[ORM\JoinColumn(nullable: false)] - private ?Command $command = null; + #[ORM\Column(length: 255, nullable: true)] + private ?string $command = null; #[ORM\Column(length: 255)] private ?string $status = null; @@ -47,12 +46,12 @@ class Trace extends AbstractEntity return $this; } - public function getCommand(): ?Command + public function getCommand(): ?string { return $this->command; } - public function setCommand(?Command $command): static + public function setCommand(?string $command): static { $this->command = $command; diff --git a/src/Model/CommandTypes.php b/src/Model/CommandTypes.php new file mode 100644 index 0000000..4744681 --- /dev/null +++ b/src/Model/CommandTypes.php @@ -0,0 +1,38 @@ + 'Deploy Image', + self::RESTORE_IMAGE => 'Update Cache', + self::CREATE_IMAGE => 'Create Image', + self::CREATE_IMAGE_AUX_FILE => 'Crear fichero auxiliar en repositorio', + self::POWER_ON => 'Encender', + self::REBOOT => 'Reiniciar', + self::SHUTDOWN => 'Apagar', + self::LOGIN => 'Login', + self::LOGOUT => 'Logout', + ]; + + public static function getCommandTypes(): array + { + return self::COMMAND_TYPES; + } + + public static function getCommandType(string $type): ?string + { + return self::COMMAND_TYPES[$type] ?? null; + } +} \ No newline at end of file diff --git a/src/Model/ImageStatus.php b/src/Model/ImageStatus.php index d46af96..3ef24f1 100644 --- a/src/Model/ImageStatus.php +++ b/src/Model/ImageStatus.php @@ -6,6 +6,7 @@ final class ImageStatus { public const string PENDING = 'pending'; public const string IN_PROGRESS = 'in-progress'; + public const string AUX_FILES_PENDING = 'aux-files-pending'; public const string SUCCESS = 'success'; public const string TRASH = 'trash'; public const string FAILED = 'failed'; @@ -13,6 +14,7 @@ final class ImageStatus private const array STATUS = [ self::PENDING => 'Pendiente', self::IN_PROGRESS => 'En progreso', + self::AUX_FILES_PENDING => 'Archivos auxiliares pendientes', self::TRASH => 'Papelera', self::SUCCESS => 'Completado', self::FAILED => 'Fallido', diff --git a/src/Service/CreatePartitionService.php b/src/Service/CreatePartitionService.php new file mode 100644 index 0000000..48b903f --- /dev/null +++ b/src/Service/CreatePartitionService.php @@ -0,0 +1,50 @@ +entityManager->getRepository(Partition::class) + ->findOneBy(['client' => $clientEntity, 'diskNumber' => $cfg['disk'], 'partitionNumber' => $cfg['par']]); + + if (!$partitionEntity) { + $partitionEntity = new Partition(); + } + + if (isset($cfg['soi']) && $cfg['soi'] !== '') { + $operativeSystem = $this->entityManager->getRepository(OperativeSystem::class) + ->findOneBy(['name' => $cfg['soi']]); + + if (!$operativeSystem) { + $operativeSystem = new OperativeSystem(); + $operativeSystem->setName($cfg['soi']); + $this->entityManager->persist($operativeSystem); + } + $partitionEntity->setOperativeSystem($operativeSystem); + } + + $partitionEntity->setClient($clientEntity); + $partitionEntity->setDiskNumber($cfg['disk']); + $partitionEntity->setPartitionNumber($cfg['par']); + $partitionEntity->setSize($cfg['tam']); + $partitionEntity->setMemoryUsage(((int) $cfg['uso']) * 100); + $this->entityManager->persist($partitionEntity); + } + + $this->entityManager->flush(); + } +} \ No newline at end of file diff --git a/src/Service/Trace/CreateService.php b/src/Service/Trace/CreateService.php index 1af179f..12a3459 100644 --- a/src/Service/Trace/CreateService.php +++ b/src/Service/Trace/CreateService.php @@ -15,11 +15,11 @@ readonly class CreateService { } - public function __invoke(Client $client, Command $command, string $status, ?string $jobId = null, array $input): Trace + public function __invoke(Client $client, ?string $command, string $status, string $jobId, ?array $input = []): Trace { $trace = new Trace(); $trace->setClient($client); - $trace->setCommand($command ?? null); + $trace->setCommand($command); $trace->setStatus($status); $trace->setJobId($jobId); $trace->setExecutedAt(new \DateTime()); diff --git a/src/State/Processor/ImageProcessor.php b/src/State/Processor/ImageProcessor.php index bcda6ed..8d79868 100644 --- a/src/State/Processor/ImageProcessor.php +++ b/src/State/Processor/ImageProcessor.php @@ -54,12 +54,12 @@ readonly class ImageProcessor implements ProcessorInterface } $image = $data->createOrUpdateEntity($entity); + $this->validator->validate($image); if ($data->source !== 'input') { $response = $this->createImageActionController->__invoke($image); } - $this->validator->validate($image); $this->imageRepository->save($image); return new ImageOutput($image); diff --git a/translations/validators.en.yaml b/translations/validators.en.yaml index 7881069..2ed5bc8 100644 --- a/translations/validators.en.yaml +++ b/translations/validators.en.yaml @@ -37,6 +37,7 @@ validators: image: name: not_blank: 'The name should not be blank.' + unique: 'The name should be unique.' network_settings: ip_address: diff --git a/translations/validators.es.yaml b/translations/validators.es.yaml index 9f11c35..a6bbf00 100644 --- a/translations/validators.es.yaml +++ b/translations/validators.es.yaml @@ -37,6 +37,7 @@ validators: image: name: not_blank: 'El nombre no debería estar vacío.' + unique: 'El nombre debería ser único. Ya existe una imagen con ese nombre.' network_settings: ip_address: