Merge branch 'develop' into tls
testing/ogcore-api/pipeline/head There was a failure building this commit
Details
testing/ogcore-api/pipeline/head There was a failure building this commit
Details
commit
9039558fad
28
CHANGELOG.md
28
CHANGELOG.md
|
@ -1,22 +1,40 @@
|
|||
# Changelog
|
||||
<<<<<<< HEAD
|
||||
## [0.13.0] - 2025-05-20
|
||||
### Added
|
||||
- Se ha creado la base para la comunicacion TLS con el agente.
|
||||
|
||||
### Improved
|
||||
- Refactorizacion de la API para la gestion de llamadas al agente
|
||||
|
||||
### Fixed
|
||||
- Se ha corregido un bug que hacia que no se eliminara la imagen al particionar.
|
||||
|
||||
---
|
||||
## [0.12.1] - 2025-05-14
|
||||
### Improved
|
||||
- Se ha eliminado la restriccion en el formulario de crear/editar repositorio, que hacia que la comprobara el formato de IP. Ahora tambien puede ser DNS.
|
||||
- Mejora en el script de ejecutar tareas.
|
||||
- Ahora al editar la mac de un cliente, se borra el fichero de arranque antiguo.
|
||||
- Se ha añadido una restriccion en plantillas para que tan solo haya 1 por defecto
|
||||
|
||||
---
|
||||
## [0.12.0] - 2025-05-13
|
||||
### Added
|
||||
- Se ha añadido nueva API para poder gestionar las tareas y acciones programadas.
|
||||
- Se ha añadido un nuevo campo en plantillas (defecto) el cual nos permite tener una plantilla por defecto en caso de que se elimine una.
|
||||
- Se ha comenzado la integracion con ogGit.
|
||||
|
||||
## Improved
|
||||
### Improved
|
||||
- Mejorado el comportamiento de la API al crear una imagen. Ahora se guardan datos del pc de origen.
|
||||
|
||||
## Fixed
|
||||
### Fixed
|
||||
- Se ha corregido el bug en la creacion de clientes masivos donde no se le asignaba la plantilla PXE.
|
||||
- Se ha corregido un bug en el DTO de clientes, que hacia que PHP diera un timeout por bucle infinito.
|
||||
=======
|
||||
|
||||
---
|
||||
## [0.11.2] - 2025-04-23
|
||||
### Fixed
|
||||
- Se ha cambiado la forma en guardar la fecha al recibir "ping" de los clientes.
|
||||
>>>>>>> main
|
||||
|
||||
---
|
||||
## [0.11.1] - 2025-04-16
|
||||
|
|
|
@ -9,6 +9,8 @@ resources:
|
|||
filters:
|
||||
- 'api_platform.filter.trace.order'
|
||||
- 'api_platform.filter.trace.search'
|
||||
- 'api_platform.filter.trace.date'
|
||||
|
||||
ApiPlatform\Metadata\Get:
|
||||
provider: App\State\Provider\TraceProvider
|
||||
|
||||
|
|
|
@ -304,6 +304,11 @@ services:
|
|||
$orderParameterName: 'order'
|
||||
tags: [ 'api_platform.filter' ]
|
||||
|
||||
api_platform.filter.trace.date:
|
||||
parent: 'api_platform.doctrine.orm.date_filter'
|
||||
arguments: [ { 'executedAt': ~, 'createdAt': ~ } ]
|
||||
tags: [ 'api_platform.filter' ]
|
||||
|
||||
api_platform.filter.user.order:
|
||||
parent: 'api_platform.doctrine.orm.order_filter'
|
||||
arguments:
|
||||
|
|
|
@ -26,7 +26,8 @@ services:
|
|||
- 8443:443 # Añadir el puerto 443
|
||||
volumes:
|
||||
- ./public:/var/www/html/public:cached
|
||||
- ./docker/certs:/etc/nginx/certs # Montar certificados en Nginx
|
||||
- ./docker/certs:/etc/nginx/certs
|
||||
- ./certs:/opt/opengnsys/ogcore/etc/certificates
|
||||
networks:
|
||||
- ogcore-network
|
||||
|
||||
|
@ -37,6 +38,7 @@ services:
|
|||
dockerfile: ./docker/Dockerfile-php
|
||||
volumes:
|
||||
- ./:/var/www/html
|
||||
- ./certs:/opt/opengnsys/ogcore/etc/certificates
|
||||
depends_on:
|
||||
- database
|
||||
networks:
|
||||
|
|
|
@ -12,11 +12,11 @@ server {
|
|||
root /var/www/html/public;
|
||||
index index.html index.php;
|
||||
|
||||
#ssl_certificate /opt/opengnsys/ogcore/etc/certificates/ogcore.crt;
|
||||
#ssl_certificate_key /opt/opengnsys/ogcore/etc/certificates/ogcore.key;
|
||||
ssl_certificate /etc/nginx/certs/ogcore.uds-test.net.crt.pem;
|
||||
ssl_certificate_key /etc/nginx/certs/ogcore.uds-test.net.key.pem;
|
||||
|
||||
|
||||
|
||||
location /opengnsys/rest/ous// {
|
||||
rewrite ^/opengnsys/rest/ous//([0-9]+)/images /opengnsys/rest/ous/$1/images;
|
||||
rewrite ^/opengnsys/rest/ous//([0-9]+)/labs /opengnsys/rest/ous/$1/labs;
|
||||
|
@ -44,6 +44,9 @@ server {
|
|||
|
||||
error_log /var/log/nginx/error.log debug;
|
||||
access_log /var/log/nginx/access.log;
|
||||
|
||||
#ssl_client_certificate /opt/opengnsys/ogcore/etc/certificates/ca.crt;
|
||||
#ssl_verify_client on;
|
||||
}
|
||||
|
||||
server {
|
||||
|
|
6
env.json
6
env.json
|
@ -7,6 +7,10 @@
|
|||
"UDS_AUTH_LOGIN": "test",
|
||||
"UDS_AUTH_USERNAME": "test",
|
||||
"UDS_AUTH_PASSWORD": "test",
|
||||
"UDS_URL": "https:\/\/localhost:8087\/uds\/rest\/"
|
||||
"UDS_URL": "https:\/\/localhost:8087\/uds\/rest\/",
|
||||
"SSL_ENABLED": "true",
|
||||
"OG_BOOT_IP": "127.0.0.1",
|
||||
"OG_BOOT_API_PORT": "8082",
|
||||
"OG_BOOT_PXE_PORT": "8085"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20250514051344 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE client ADD token VARCHAR(255) DEFAULT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE client DROP token');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20250514101117 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_NAME ON command (name)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('DROP INDEX UNIQ_IDENTIFIER_NAME ON command');
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ use App\Dto\Input\CommandExecuteInput;
|
|||
use App\Dto\Input\DeployImageInput;
|
||||
use App\Dto\Output\ClientOutput;
|
||||
use App\Entity\CommandTask;
|
||||
use App\Model\ClientStatus;
|
||||
use App\Repository\CommandTaskRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
|
@ -59,22 +60,20 @@ class RunScheduledCommandTasksCommand extends Command
|
|||
usort($scripts, fn($a, $b) => $a->getExecutionOrder() <=> $b->getExecutionOrder());
|
||||
|
||||
foreach ($scripts as $script) {
|
||||
try {
|
||||
$output->writeln(" - Ejecutando script de tipo {$script->getType()} con orden {$script->getExecutionOrder()}");
|
||||
$output->writeln(" - Ejecutando script de tipo {$script->getType()} con orden {$script->getExecutionOrder()}");
|
||||
|
||||
if ($script->getType() === 'run-script') {
|
||||
$input = new CommandExecuteInput();
|
||||
if ($script->getType() === 'run-script') {
|
||||
$input = new CommandExecuteInput();
|
||||
|
||||
foreach ($task->getOrganizationalUnit()?->getClients() as $client) {
|
||||
$input->clients[] = new ClientOutput($client);
|
||||
foreach ($task->getOrganizationalUnit()?->getClients() as $client) {
|
||||
if ($client->getStatus() !== ClientStatus::OG_LIVE) {
|
||||
continue;
|
||||
}
|
||||
$input->script = $script->getContent();
|
||||
|
||||
$this->runScriptAction->__invoke($input);
|
||||
$input->clients[] = new ClientOutput($client);
|
||||
}
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$output->writeln("Error ejecutando script: " . $e->getMessage());
|
||||
continue;
|
||||
$input->script = $script->getContent();
|
||||
|
||||
$this->runScriptAction->__invoke($input);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
|
||||
class AuthValidatorController extends AbstractController
|
||||
{
|
||||
private JWTTokenManagerInterface $jwtManager;
|
||||
|
||||
public function __construct(JWTTokenManagerInterface $jwtManager)
|
||||
{
|
||||
$this->jwtManager = $jwtManager;
|
||||
}
|
||||
|
||||
#[Route('/validate', name: 'auth_validate', methods: ['POST'])]
|
||||
public function validate(Request $request): Response
|
||||
{
|
||||
$sslClientVerify = $request->headers->get('SSL_CLIENT_VERIFY');
|
||||
$clientCertOk = $sslClientVerify === 'SUCCESS';
|
||||
|
||||
$authHeader = $request->headers->get('Authorization');
|
||||
$hasValidJwt = $this->validateJwtToken($authHeader);
|
||||
|
||||
if ($clientCertOk || $hasValidJwt) {
|
||||
return new Response('Authorized', Response::HTTP_OK);
|
||||
}
|
||||
|
||||
return new Response('Unauthorized', Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
private function validateJwtToken(?string $authHeader): bool
|
||||
{
|
||||
if (!$authHeader || !str_starts_with($authHeader, 'Bearer ')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$token = substr($authHeader, 7);
|
||||
|
||||
try {
|
||||
$payload = $this->jwtManager->parse($token);
|
||||
|
||||
return true;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\OgAgent;
|
||||
|
||||
use App\Controller\OgRepository\Git\CreateRepositoryAction;
|
||||
use App\Controller\OgRepository\Git\CreateTagAction;
|
||||
use App\Service\CreatePartitionService;
|
||||
use App\Service\Trace\CreateService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
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]
|
||||
abstract class AbstractOgAgentController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly EntityManagerInterface $entityManager,
|
||||
protected readonly HttpClientInterface $httpClient,
|
||||
protected readonly CreatePartitionService $createPartitionService,
|
||||
protected readonly LoggerInterface $logger,
|
||||
protected readonly CreateService $createService,
|
||||
protected readonly CreateRepositoryAction $createRepositoryAction,
|
||||
protected readonly CreateTagAction $createTagAction,
|
||||
#[Autowire(env: 'SSL_ENABLED')]
|
||||
private readonly string $sslEnabled,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function createRequest(string $method, string $url, array $params = [], string $token = null): array
|
||||
{
|
||||
$params = array_merge($params, [
|
||||
'headers' => [
|
||||
'accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => $token,
|
||||
],
|
||||
'verify_peer' => false,
|
||||
'verify_host' => false,
|
||||
'timeout' => 10
|
||||
]);
|
||||
|
||||
|
||||
if ($this->sslEnabled === 'true') {
|
||||
$params['verify_peer'] = true;
|
||||
$params['verify_host'] = false;
|
||||
$params['cafile'] = '/opt/opengnsys/ogcore/etc/certificates/ca.crt';
|
||||
$params['local_cert'] = '/opt/opengnsys/ogcore/etc/certificates/ogcore.crt';
|
||||
$params['local_pk'] = '/opt/opengnsys/ogcore/etc/certificates/ogcore.key';
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $this->httpClient->request($method, $url, $params);
|
||||
return json_decode($response->getContent(), true);
|
||||
} catch (ClientExceptionInterface | ServerExceptionInterface $e) {
|
||||
$this->logger->error(sprintf('Client/Server error in request to %s: %s', $url, $e->getMessage()));
|
||||
|
||||
return [
|
||||
'code' => Response::HTTP_INTERNAL_SERVER_ERROR,
|
||||
'error' => 'Client/Server error',
|
||||
'details' => $e->getMessage(),
|
||||
];
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$this->logger->error(sprintf('Transport error in request to %s: %s', $url, $e->getMessage()));
|
||||
|
||||
return [
|
||||
'code' => Response::HTTP_INTERNAL_SERVER_ERROR,
|
||||
'error' => 'Client/Server error',
|
||||
'details' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,19 +34,8 @@ use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
|||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class CreateImageAction extends AbstractController
|
||||
class CreateImageAction extends AbstractOgAgentController
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly EntityManagerInterface $entityManager,
|
||||
protected readonly HttpClientInterface $httpClient,
|
||||
protected readonly CreateService $createService,
|
||||
protected readonly LoggerInterface $logger,
|
||||
protected readonly CreateRepositoryAction $createRepositoryAction,
|
||||
protected readonly CreateTagAction $createTagAction,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
|
@ -147,29 +136,25 @@ class CreateImageAction extends AbstractController
|
|||
throw new Exception("El tipo de partición '$partitionCode' no se encontró en la lista.");
|
||||
}
|
||||
|
||||
try {
|
||||
$client = $client ?? $image->getClient();
|
||||
$this->logger->info('Creating image', ['image' => $image->getId()]);
|
||||
|
||||
$client = $client ?? $image->getClient();
|
||||
$this->logger->info('Creating image', ['image' => $image->getId()]);
|
||||
$response = $this->httpClient->request('POST', 'https://'.$client->getIp().':8000/opengnsys/CrearImagen', [
|
||||
'verify_peer' => false,
|
||||
'verify_host' => false,
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
$response = $this->createRequest(
|
||||
method: 'POST',
|
||||
url: 'https://'.$client->getIp().':8000/opengnsys/CrearImagen',
|
||||
params: [
|
||||
'json' => $data,
|
||||
]);
|
||||
],
|
||||
token: $client->getToken(),
|
||||
);
|
||||
|
||||
$this->logger->info('Creating image', ['image' => $imageImageRepository->getName(), 'repository' => $repository->getIp()]);
|
||||
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$this->logger->error('Error creating image', ['image' => $image->getId(), 'error' => $e->getMessage()]);
|
||||
return new JsonResponse(
|
||||
data: ['error' => $e->getMessage()],
|
||||
status: Response::HTTP_INTERNAL_SERVER_ERROR
|
||||
);
|
||||
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
|
||||
throw new ValidatorException('Error creating image');
|
||||
}
|
||||
|
||||
$jobId = json_decode($response->getContent(), true)['job_id'];
|
||||
$jobId = $response['job_id'];
|
||||
|
||||
$client->setStatus(ClientStatus::BUSY);
|
||||
$this->entityManager->persist($client);
|
||||
|
|
|
@ -29,17 +29,8 @@ use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
|||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class DeployImageAction extends AbstractController
|
||||
class DeployImageAction extends AbstractOgAgentController
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly EntityManagerInterface $entityManager,
|
||||
protected readonly HttpClientInterface $httpClient,
|
||||
protected readonly CreateService $createService,
|
||||
protected readonly LoggerInterface $logger,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
|
@ -91,26 +82,22 @@ class DeployImageAction extends AbstractController
|
|||
'ids' => '0'
|
||||
];
|
||||
|
||||
try {
|
||||
$response = $this->httpClient->request('POST', 'https://'.$client->getIp().':8000/opengnsys/RestaurarImagen', [
|
||||
'verify_peer' => false,
|
||||
'verify_host' => false,
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
$response = $this->createRequest(
|
||||
method: 'POST',
|
||||
url: 'https://'.$client->getIp().':8000/opengnsys/RestaurarImagen',
|
||||
params: [
|
||||
'json' => $data,
|
||||
]);
|
||||
$this->logger->info('Deploying image', ['image' => $image->getId()]);
|
||||
],
|
||||
token: $client->getToken(),
|
||||
);
|
||||
|
||||
$jobId = json_decode($response->getContent(), true)['job_id'];
|
||||
} catch (ClientExceptionInterface | ServerExceptionInterface | TransportExceptionInterface | TransportException $e) {
|
||||
$this->logger->error('Error deploying image', [
|
||||
'image' => $image->getId() ?? 'unknown',
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
return null;
|
||||
$this->logger->info('Deploying image', [ 'image' => $imageImageRepository->getName(), 'repository' => $repository->getIp()]);
|
||||
|
||||
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
|
||||
throw new ValidatorException('Error deploying image');
|
||||
}
|
||||
|
||||
$jobId = $response['job_id'];
|
||||
|
||||
$client->setStatus(ClientStatus::BUSY);
|
||||
$this->entityManager->persist($client);
|
||||
|
|
|
@ -27,17 +27,14 @@ use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
|||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class LoginAction extends AbstractController
|
||||
class LoginAction extends AbstractOgAgentController
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly EntityManagerInterface $entityManager,
|
||||
protected readonly HttpClientInterface $httpClient,
|
||||
protected readonly CreateService $createService,
|
||||
protected readonly LoggerInterface $logger,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(MultipleClientsInput $input): JsonResponse
|
||||
{
|
||||
foreach ($input->clients as $clientEntity) {
|
||||
|
@ -60,26 +57,21 @@ class LoginAction extends AbstractController
|
|||
'ids' => '0'
|
||||
];
|
||||
|
||||
try {
|
||||
$response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/ogAdmClient/IniciarSesion', [
|
||||
'verify_peer' => false,
|
||||
'verify_host' => false,
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
$response = $this->createRequest(
|
||||
method: 'POST',
|
||||
url: 'http://'.$client->getIp().':8000/opengnsys/IniciarSesion',
|
||||
params: [
|
||||
'json' => $data,
|
||||
]);
|
||||
$this->logger->info('Login client', ['client' => $client->getId()]);
|
||||
]
|
||||
);
|
||||
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$this->logger->error('Login rebooting client', ['client' => $client->getId(), 'error' => $e->getMessage()]);
|
||||
return new JsonResponse(
|
||||
data: ['error' => $e->getMessage()],
|
||||
status: Response::HTTP_INTERNAL_SERVER_ERROR
|
||||
);
|
||||
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
|
||||
throw new ValidatorException('Error logging in: '.$response['error']);
|
||||
}
|
||||
|
||||
$jobId = json_decode($response->getContent(), true)['job_id'];
|
||||
$this->logger->info('Login client', ['client' => $client->getId()]);
|
||||
|
||||
$jobId = $response['job_id'];
|
||||
|
||||
$client->setStatus(ClientStatus::INITIALIZING);
|
||||
$this->entityManager->persist($client);
|
||||
|
|
|
@ -28,17 +28,14 @@ use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
|||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class PartitionAssistantAction extends AbstractController
|
||||
class PartitionAssistantAction extends AbstractOgAgentController
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly EntityManagerInterface $entityManager,
|
||||
protected readonly HttpClientInterface $httpClient,
|
||||
protected readonly CreateService $createService,
|
||||
protected readonly LoggerInterface $logger,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(PartitionPostInput $input): JsonResponse
|
||||
{
|
||||
$partitions = $input->partitions;
|
||||
|
@ -101,28 +98,28 @@ class PartitionAssistantAction extends AbstractController
|
|||
"ids" => "0"
|
||||
];
|
||||
|
||||
try {
|
||||
$response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/opengnsys/Configurar', [
|
||||
'verify_peer' => false,
|
||||
'verify_host' => false,
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
$response = $this->createRequest(
|
||||
method: 'POST',
|
||||
url: 'https://'.$client->getIp().':8000/opengnsys/Configurar',
|
||||
params: [
|
||||
'json' => $result,
|
||||
]);
|
||||
$this->logger->info('Partitioning disk', ['client' => $client->getId(), 'disk' => $diskNumber]);
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$this->logger->error('Error partitioning disk', ['client' => $client->getId(), 'disk' => $diskNumber, 'error' => $e->getMessage()]);
|
||||
continue;
|
||||
],
|
||||
token: $client->getToken(),
|
||||
);
|
||||
|
||||
$this->logger->info('Partition assistant', ['client' => $client->getId()]);
|
||||
|
||||
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
|
||||
throw new ValidatorException('Error occurred while partitioning');
|
||||
}
|
||||
|
||||
$jobId = json_decode($response->getContent(), true)['job_id'];
|
||||
$jobId = $response['job_id'];
|
||||
|
||||
$client->setStatus(ClientStatus::BUSY);
|
||||
$this->entityManager->persist($client);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->createService->__invoke($client, CommandTypes::PARTITION_AND_FORMAT, TraceStatus::IN_PROGRESS, $jobId, []);
|
||||
$this->createService->__invoke($client, CommandTypes::PARTITION_AND_FORMAT, TraceStatus::IN_PROGRESS, $jobId, $data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,17 +28,14 @@ use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
|||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class PowerOffAction extends AbstractController
|
||||
class PowerOffAction extends AbstractOgAgentController
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly EntityManagerInterface $entityManager,
|
||||
protected readonly HttpClientInterface $httpClient,
|
||||
protected readonly CreateService $createService,
|
||||
protected readonly LoggerInterface $logger,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(MultipleClientsInput $input): JsonResponse
|
||||
{
|
||||
foreach ($input->clients as $clientEntity) {
|
||||
|
@ -60,26 +57,23 @@ class PowerOffAction extends AbstractController
|
|||
'ids' => '0'
|
||||
];
|
||||
|
||||
try {
|
||||
$response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/'.$endpoint, [
|
||||
'verify_peer' => false,
|
||||
'verify_host' => false,
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
$response = $this->createRequest(
|
||||
method: 'POST',
|
||||
url: 'https://'.$client->getIp().':8000/'.$endpoint,
|
||||
params: [
|
||||
'json' => $data,
|
||||
]);
|
||||
$this->logger->info('Powering off client', ['client' => $client->getId()]);
|
||||
$jobId = json_decode($response->getContent(), true)['job_id'];
|
||||
],
|
||||
token: $client->getToken(),
|
||||
);
|
||||
|
||||
} catch (ClientExceptionInterface | ServerExceptionInterface | TransportExceptionInterface | TransportException $e) {
|
||||
$this->logger->error('Error power off client', [
|
||||
'image' => $client->getIp(),
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
continue;
|
||||
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
|
||||
throw new ValidatorException('Error deploying image');
|
||||
}
|
||||
|
||||
$this->logger->info('Powering off client', ['client' => $client->getId()]);
|
||||
|
||||
$jobId = $response['job_id'];
|
||||
|
||||
$client->setStatus(ClientStatus::TURNING_OFF);
|
||||
$this->entityManager->persist($client);
|
||||
$this->entityManager->flush();
|
||||
|
|
|
@ -27,17 +27,14 @@ use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
|||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class RebootAction extends AbstractController
|
||||
class RebootAction extends AbstractOgAgentController
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly EntityManagerInterface $entityManager,
|
||||
protected readonly HttpClientInterface $httpClient,
|
||||
protected readonly CreateService $createService,
|
||||
protected readonly LoggerInterface $logger,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(MultipleClientsInput $input): JsonResponse
|
||||
{
|
||||
foreach ($input->clients as $clientEntity) {
|
||||
|
@ -56,27 +53,22 @@ class RebootAction extends AbstractController
|
|||
'ids' => '0'
|
||||
];
|
||||
|
||||
try {
|
||||
$response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/'.$endpoint, [
|
||||
'verify_peer' => false,
|
||||
'verify_host' => false,
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
$response = $this->createRequest(
|
||||
method: 'POST',
|
||||
url: 'http://'.$client->getIp().':8000/'.$endpoint,
|
||||
params: [
|
||||
'json' => $data,
|
||||
]);
|
||||
],
|
||||
token: $client->getToken(),
|
||||
);
|
||||
|
||||
$this->logger->info('Rebooting client', ['client' => $client->getId()]);
|
||||
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$this->logger->error('Error rebooting client', ['client' => $client->getId(), 'error' => $e->getMessage()]);
|
||||
return new JsonResponse(
|
||||
data: ['error' => $e->getMessage()],
|
||||
status: Response::HTTP_INTERNAL_SERVER_ERROR
|
||||
);
|
||||
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
|
||||
throw new ValidatorException('Error deploying image');
|
||||
}
|
||||
|
||||
$jobId = json_decode($response->getContent(), true)['job_id'];
|
||||
$this->logger->info('Rebooting client', ['client' => $client->getId()]);
|
||||
|
||||
$jobId = $response['job_id'];
|
||||
|
||||
$client->setStatus(ClientStatus::INITIALIZING);
|
||||
$this->entityManager->persist($client);
|
||||
|
|
|
@ -15,24 +15,25 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||
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;
|
||||
|
||||
class RunScriptAction extends AbstractController
|
||||
class RunScriptAction extends AbstractOgAgentController
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly EntityManagerInterface $entityManager,
|
||||
protected readonly HttpClientInterface $httpClient,
|
||||
protected readonly CreateService $createService,
|
||||
protected readonly LoggerInterface $logger,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(CommandExecuteInput $input): JsonResponse
|
||||
{
|
||||
/** @var Client $clientEntity */
|
||||
foreach ($input->clients as $clientEntity) {
|
||||
/** @var Client $client */
|
||||
$client = $clientEntity->getEntity();
|
||||
|
||||
if (!$client->getIp()) {
|
||||
|
@ -45,26 +46,22 @@ class RunScriptAction extends AbstractController
|
|||
'ids' => '0'
|
||||
];
|
||||
|
||||
try {
|
||||
$response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/opengnsys/EjecutarScript', [
|
||||
'verify_peer' => false,
|
||||
'verify_host' => false,
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
$response = $this->createRequest(
|
||||
method: 'POST',
|
||||
url: 'https://'.$client->getIp().':8000/opengnsys/EjecutarScript',
|
||||
params: [
|
||||
'json' => $data,
|
||||
]);
|
||||
$this->logger->info('Rebooting client', ['client' => $client->getId()]);
|
||||
],
|
||||
token: $client->getToken(),
|
||||
);
|
||||
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$this->logger->error('Error rebooting client', ['client' => $client->getId(), 'error' => $e->getMessage()]);
|
||||
return new JsonResponse(
|
||||
data: ['error' => $e->getMessage()],
|
||||
status: Response::HTTP_INTERNAL_SERVER_ERROR
|
||||
);
|
||||
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
|
||||
throw new ValidatorException('Error deploying image');
|
||||
}
|
||||
|
||||
$jobId = json_decode($response->getContent(), true)['job_id'];
|
||||
$this->logger->info('Powering off client', ['client' => $client->getId()]);
|
||||
|
||||
$jobId = $response['job_id'];
|
||||
|
||||
$this->entityManager->persist($client);
|
||||
$this->entityManager->flush();
|
||||
|
|
|
@ -24,15 +24,8 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
#[AsController]
|
||||
class StatusAction extends AbstractController
|
||||
class StatusAction extends AbstractOgAgentController
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly EntityManagerInterface $entityManager,
|
||||
protected readonly HttpClientInterface $httpClient,
|
||||
protected readonly CreatePartitionService $createPartitionService,
|
||||
protected readonly LoggerInterface $logger,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
|
@ -66,38 +59,37 @@ class StatusAction extends AbstractController
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function getOgLiveStatus (Client $client): JsonResponse|int|string
|
||||
{
|
||||
$this->logger->info('Checking client status', ['client' => $client->getId()]);
|
||||
|
||||
$params = [
|
||||
'full-config' => false,
|
||||
'json' => [
|
||||
'full-config' => false
|
||||
]
|
||||
];
|
||||
|
||||
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' => $params,
|
||||
]);
|
||||
$statusCode = $response->getStatusCode();
|
||||
$client->setStatus($statusCode === Response::HTTP_OK ? ClientStatus::OG_LIVE : ClientStatus::OFF);
|
||||
$data = $this->createRequest(
|
||||
method: 'POST',
|
||||
url: 'https://' . $client->getIp() . ':8000/opengnsys/status',
|
||||
params: $params,
|
||||
token: $client->getToken(),
|
||||
);
|
||||
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$this->logger->error('Error checking client status', ['client' => $client->getId(), 'error' => $e->getMessage()]);
|
||||
if (isset($data['error']) && $data['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
|
||||
$this->logger->error('Error checking client status', ['client' => $client->getId()]);
|
||||
$client->setStatus(ClientStatus::OFF);
|
||||
$this->entityManager->persist($client);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $e->getMessage();
|
||||
throw new ValidatorException('Error deploying image');
|
||||
}
|
||||
|
||||
$data = json_decode($response->getContent(), true);
|
||||
|
||||
if (isset($data['cfg'])) {
|
||||
$this->logger->info('Creating partitions', ['data' => $data['cfg']]);
|
||||
$this->createPartitionService->__invoke($data, $client);
|
||||
|
@ -109,25 +101,22 @@ class StatusAction extends AbstractController
|
|||
return Response::HTTP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function getSOStatus (Client $client): JsonResponse|int
|
||||
{
|
||||
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' => [],
|
||||
]);
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$client->setStatus(ClientStatus::OFF);
|
||||
$this->logger->error('Error checking client status', ['client' => $client->getId(), 'error' => $e->getMessage()]);
|
||||
return Response::HTTP_INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
|
||||
$data = json_decode($response->getContent(), true);
|
||||
$data = $this->createRequest(
|
||||
method: 'POST',
|
||||
url: 'https://' . $client->getIp() . ':8000/opengnsys/status',
|
||||
params: [
|
||||
'full-config' => false,
|
||||
],
|
||||
token: $client->getToken(),
|
||||
);
|
||||
|
||||
if (isset($data['cfg'])) {
|
||||
$this->createPartitionService->__invoke($data, $client);
|
||||
|
|
|
@ -49,6 +49,7 @@ class AgentController extends AbstractController
|
|||
}
|
||||
|
||||
$clientEntity->setStatus(ClientStatus::OG_LIVE);
|
||||
$clientEntity->setToken($data['secret'] ?? null);
|
||||
$this->entityManager->persist($clientEntity);
|
||||
|
||||
if (isset($data['cfg'])) {
|
||||
|
|
|
@ -9,6 +9,7 @@ use App\Service\Trace\CreateService;
|
|||
use App\Service\Utils\ExtractOgLiveFilenameDateService;
|
||||
use App\Service\Utils\SimplifyOgLiveFilenameService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
@ -25,8 +26,12 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|||
abstract class AbstractOgBootController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
#[Autowire(env: 'OG_BOOT_API_URL')]
|
||||
protected string $ogBootApiUrl,
|
||||
#[Autowire(env: 'OG_BOOT_IP')]
|
||||
protected string $ogBootIp,
|
||||
#[Autowire(env: 'OG_BOOT_PXE_PORT')]
|
||||
protected string $ogBootPxePort,
|
||||
#[Autowire(env: 'OG_BOOT_API_PORT')]
|
||||
protected string $ogBootApiPort,
|
||||
#[Autowire(env: 'OG_CORE_IP')]
|
||||
protected string $ogCoreIP,
|
||||
#[Autowire(env: 'OG_LOG_IP')]
|
||||
|
@ -36,6 +41,8 @@ abstract class AbstractOgBootController extends AbstractController
|
|||
protected readonly CreateService $createService,
|
||||
protected readonly SimplifyOgLiveFilenameService $simplifyOgLiveFilenameService,
|
||||
protected readonly ExtractOgLiveFilenameDateService $extractOgLiveFilenameDateService,
|
||||
protected readonly LoggerInterface $logger,
|
||||
|
||||
)
|
||||
{
|
||||
}
|
||||
|
@ -56,15 +63,25 @@ abstract class AbstractOgBootController extends AbstractController
|
|||
]);
|
||||
|
||||
try {
|
||||
$response = $this->httpClient->request($method, $url, $params);
|
||||
$response = $this->httpClient->request($method, 'http://'.$this->ogBootIp.':'.$this->ogBootApiPort.$url, $params);
|
||||
|
||||
return json_decode($response->getContent(), true);
|
||||
} catch (ClientExceptionInterface | ServerExceptionInterface $e) {
|
||||
$response = $e->getResponse();
|
||||
$content = json_decode($response->getContent(false), true);
|
||||
throw new HttpException($response->getStatusCode(), $content['error'] ?? 'An error occurred');
|
||||
$this->logger->error(sprintf('Client/Server error in request to %s: %s', $url, $e->getMessage()));
|
||||
|
||||
return [
|
||||
'code' => Response::HTTP_INTERNAL_SERVER_ERROR,
|
||||
'error' => 'Client/Server error',
|
||||
'details' => $e->getMessage(),
|
||||
];
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, $e->getMessage());
|
||||
$this->logger->error(sprintf('Transport error in request to %s: %s', $url, $e->getMessage()));
|
||||
|
||||
return [
|
||||
'code' => Response::HTTP_INTERNAL_SERVER_ERROR,
|
||||
'error' => 'Transport error',
|
||||
'details' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,11 @@ class GetAction extends AbstractOgBootController
|
|||
throw new ValidatorException('Checksum is required');
|
||||
}
|
||||
|
||||
$content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum());
|
||||
$content = $this->createRequest('GET', '/ogboot/v1/oglives/'.$data->getChecksum());
|
||||
|
||||
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||
}
|
||||
|
||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,11 @@ class GetCollectionAction extends AbstractOgBootController
|
|||
*/
|
||||
public function __invoke(): JsonResponse
|
||||
{
|
||||
$content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives');
|
||||
$content = $this->createRequest('GET', '/ogboot/v1/oglives');
|
||||
|
||||
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||
}
|
||||
|
||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use App\Controller\OgBoot\AbstractOgBootController;
|
|||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
|
@ -22,7 +23,11 @@ class GetDefaultAction extends AbstractOgBootController
|
|||
*/
|
||||
public function __invoke(): JsonResponse
|
||||
{
|
||||
$content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/default');
|
||||
$content = $this->createRequest('GET', '/ogboot/v1/oglives/default');
|
||||
|
||||
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||
}
|
||||
|
||||
return new JsonResponse(status: Response::HTTP_OK);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ class GetIsosAction extends AbstractOgBootController
|
|||
*/
|
||||
public function __invoke(): JsonResponse
|
||||
{
|
||||
$content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/isos');
|
||||
$content = $this->createRequest('GET', '/ogboot/v1/oglives/isos');
|
||||
|
||||
if (!isset($content['message']) || !is_array($content['message'])) {
|
||||
return new JsonResponse(data: ['error' => 'Invalid response'], status: Response::HTTP_BAD_REQUEST);
|
||||
|
|
|
@ -45,7 +45,11 @@ class InstallAction extends AbstractOgBootController
|
|||
'uuid' => 'InstallOgLive_'.$data->getUuid()
|
||||
];
|
||||
|
||||
$content = $this->createRequest('POST', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/install', $params);
|
||||
$content = $this->createRequest('POST', '/ogboot/v1/oglives/install', $params);
|
||||
|
||||
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||
}
|
||||
|
||||
$this->createService->__invoke(null, CommandTypes::INSTALL_OGLIVE, TraceStatus::IN_PROGRESS, 'InstallOgLive_'.$data->getUuid(), $inputData);
|
||||
|
||||
|
|
|
@ -36,7 +36,11 @@ class SetDefaultAction extends AbstractOgBootController
|
|||
]
|
||||
];
|
||||
|
||||
$content = $this->createRequest('PUT', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/default', $params);
|
||||
$content = $this->createRequest('PUT', '/ogboot/v1/oglives/default', $params);
|
||||
|
||||
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||
}
|
||||
|
||||
$oldDefaultOgLive = $this->entityManager->getRepository(OgLive::class)->findBy(['isDefault' => true]);
|
||||
|
||||
|
|
|
@ -30,7 +30,11 @@ class SyncAction extends AbstractOgBootController
|
|||
*/
|
||||
public function __invoke(): JsonResponse
|
||||
{
|
||||
$content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl . '/ogboot/v1/oglives');
|
||||
$content = $this->createRequest('GET', '/ogboot/v1/oglives');
|
||||
|
||||
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||
}
|
||||
|
||||
$allOgLives = $this->entityManager->getRepository(OgLive::class)->findAll();
|
||||
$apiChecksums = array_map(fn($ogLive) => $ogLive['id'], $content['message']['installed_ogLives']);
|
||||
|
|
|
@ -31,7 +31,11 @@ class UninstallAction extends AbstractOgBootController
|
|||
throw new ValidatorException('Checksum is required');
|
||||
}
|
||||
|
||||
$content = $this->createRequest( 'DELETE', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum());
|
||||
$content = $this->createRequest( 'DELETE', '/ogboot/v1/oglives/'.$data->getChecksum());
|
||||
|
||||
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||
}
|
||||
|
||||
$this->entityManager->remove($data);
|
||||
$this->entityManager->flush();
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\OgBoot\PxeBootFile;
|
||||
|
||||
use App\Controller\OgBoot\AbstractOgBootController;
|
||||
use App\Entity\Client;
|
||||
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;
|
||||
|
||||
#[AsController]
|
||||
class DeleteAction extends AbstractOgBootController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(string $mac): JsonResponse
|
||||
{
|
||||
$response = $this->createRequest('DELETE', '/ogboot/v1/pxes/'.$mac);
|
||||
|
||||
if ($response->getStatusCode() !== Response::HTTP_OK) {
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
|
@ -24,15 +24,11 @@ class GetAction extends AbstractOgBootController
|
|||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(Client $client, HttpClientInterface $httpClient): JsonResponse
|
||||
public function __invoke(Client $client): JsonResponse
|
||||
{
|
||||
try {
|
||||
$response = $httpClient->request('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxes/'.$client->getMac(), [
|
||||
'headers' => [
|
||||
'accept' => 'application/json',
|
||||
],
|
||||
]);
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$response = $this->createRequest('GET', '/ogboot/v1/pxes/'.$client->getName());
|
||||
|
||||
if ($response->getStatusCode() !== Response::HTTP_OK) {
|
||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class GetCollectionAction extends AbstractOgBootController
|
|||
*/
|
||||
public function __invoke(HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
$content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxes');
|
||||
$content = $this->createRequest('GET', '/ogboot/v1/pxes');
|
||||
|
||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ class PostAction extends AbstractOgBootController
|
|||
*/
|
||||
public function __invoke(Client $client, PxeTemplate $pxeTemplate): JsonResponse
|
||||
{
|
||||
$ogRepoIp = $this->ogBootApiUrl;
|
||||
$ogRepoIp = $this->ogBootIp;
|
||||
|
||||
$ogRepoIp = $client->getRepository()?->getIp()
|
||||
?? $client->getOrganizationalUnit()?->getNetworkSettings()?->getRepository()?->getIp();
|
||||
|
@ -42,7 +42,9 @@ class PostAction extends AbstractOgBootController
|
|||
'mac' => strtolower($client->getMac()),
|
||||
'lang' => 'es_ES.UTF-8',
|
||||
'ip' => $client->getIp(),
|
||||
'server_ip' => $this->ogBootApiUrl,
|
||||
'server_ip' => $this->ogBootIp,
|
||||
'server_api_port' => $this->ogBootApiPort,
|
||||
'server_pxe_port' => $this->ogBootPxePort,
|
||||
'router' => $client->getOrganizationalUnit()->getNetworkSettings()->getRouter(),
|
||||
'netmask' => $client->getOrganizationalUnit()->getNetworkSettings() ? $client->getOrganizationalUnit()->getNetworkSettings()->getNetmask() : '255.255.255.0',
|
||||
'computer_name' => $client->getName(),
|
||||
|
@ -50,10 +52,10 @@ class PostAction extends AbstractOgBootController
|
|||
'group' => $client->getOrganizationalUnit()->getName(),
|
||||
'ogrepo' => $ogRepoIp,
|
||||
'ogcore' => $this->ogCoreIP,
|
||||
'oglive' => $this->ogBootApiUrl,
|
||||
'oglive' => $this->ogBootIp,
|
||||
'oglog' => $this->ogLogIp,
|
||||
'ogshare' => $client->getOrganizationalUnit()->getNetworkSettings()?->getOgShare()
|
||||
? $client->getOrganizationalUnit()->getNetworkSettings()?->getOgShare(): $this->ogBootApiUrl,
|
||||
? $client->getOrganizationalUnit()->getNetworkSettings()?->getOgShare(): $this->ogBootIp,
|
||||
'oglivedir' => $ogLive,
|
||||
'ogprof' => 'false',
|
||||
'hardprofile' => $client->getHardwareProfile() ? $client->getHardwareProfile()->getDescription() : 'default',
|
||||
|
@ -64,7 +66,7 @@ class PostAction extends AbstractOgBootController
|
|||
]
|
||||
];
|
||||
|
||||
$content = $this->createRequest('POST', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxes', $params);
|
||||
$content = $this->createRequest('POST', '/ogboot/v1/pxes', $params);
|
||||
|
||||
$client->setPxeSync(true);
|
||||
$this->entityManager->persist($client);
|
||||
|
|
|
@ -10,6 +10,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
|
@ -30,7 +31,11 @@ class DeleteAction extends AbstractOgBootController
|
|||
$this->entityManager->remove($data);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$content = $this->createRequest('DELETE', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates/'.$data->getName());
|
||||
$content = $this->createRequest('DELETE', '/ogboot/v1/pxe-templates/'.$data->getName());
|
||||
|
||||
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||
}
|
||||
|
||||
$defaultTemplateEntity = $this->entityManager->getRepository(PxeTemplate::class)->findOneBy(['isDefault' => true]);
|
||||
|
||||
|
|
|
@ -25,13 +25,9 @@ class GetAction extends AbstractOgBootController
|
|||
*/
|
||||
public function __invoke(PxeTemplate $template, HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
try {
|
||||
$response = $httpClient->request('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates/'.$template->getName(), [
|
||||
'headers' => [
|
||||
'accept' => 'application/json',
|
||||
],
|
||||
]);
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$response = $this->createRequest('GET', '/ogboot/v1/pxe-templates/'.$template->getName());
|
||||
|
||||
if ($response->getStatusCode() !== Response::HTTP_OK) {
|
||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
|
@ -24,18 +25,12 @@ class GetCollectionAction extends AbstractOgBootController
|
|||
*/
|
||||
public function __invoke(HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
try {
|
||||
$response = $httpClient->request('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates', [
|
||||
'headers' => [
|
||||
'accept' => 'application/json',
|
||||
],
|
||||
]);
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
$content = $this->createRequest('GET', '/ogboot/v1/pxe-templates');
|
||||
|
||||
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||
}
|
||||
|
||||
$data = json_decode($response->getContent(), true);
|
||||
|
||||
return new JsonResponse( data: $data, status: Response::HTTP_OK);
|
||||
return new JsonResponse( data: $content, status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
|
@ -33,7 +34,11 @@ class PostAction extends AbstractOgBootController
|
|||
]
|
||||
];
|
||||
|
||||
$content = $this->createRequest('POST', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates' , $params);
|
||||
$content = $this->createRequest('POST', '/ogboot/v1/pxe-templates' , $params);
|
||||
|
||||
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||
}
|
||||
|
||||
$data->setSynchronized(true);
|
||||
$this->entityManager->persist($data);
|
||||
|
|
|
@ -28,7 +28,7 @@ class SyncAction extends AbstractOgBootController
|
|||
*/
|
||||
public function __invoke(): JsonResponse
|
||||
{
|
||||
$content = $this->createRequest('GET', 'http://' . $this->ogBootApiUrl . '/ogboot/v1/pxe-templates');
|
||||
$content = $this->createRequest('GET', '/ogboot/v1/pxe-templates');
|
||||
$templateNamesFromApi = $content['message'];
|
||||
|
||||
$existingTemplates = $this->entityManager->getRepository(PxeTemplate::class)->findAll();
|
||||
|
@ -49,7 +49,11 @@ class SyncAction extends AbstractOgBootController
|
|||
$templateEntity->setName($templateName);
|
||||
}
|
||||
|
||||
$templateContent = $this->createRequest('GET', 'http://' . $this->ogBootApiUrl . '/ogboot/v1/pxe-templates/' . $templateEntity->getName());
|
||||
$templateContent = $this->createRequest('GET', '/ogboot/v1/pxe-templates/' . $templateEntity->getName());
|
||||
|
||||
if (isset($templateContent['error']) && $templateContent['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||
throw new ValidatorException('An error occurred: ' . $templateContent['error']);
|
||||
}
|
||||
|
||||
$templateEntity->setTemplateContent($templateContent['template_content']);
|
||||
$templateEntity->setSynchronized(true);
|
||||
|
|
|
@ -51,6 +51,7 @@ class SyncAction extends AbstractOgRepositoryController
|
|||
$imageEntity->setName($image['name']);
|
||||
$imageEntity->setRemotePc(false);
|
||||
$imageEntity->setIsGlobal(false);
|
||||
$imageEntity->setType('monolithic');
|
||||
|
||||
$this->entityManager->persist($imageEntity);
|
||||
}
|
||||
|
@ -59,6 +60,7 @@ class SyncAction extends AbstractOgRepositoryController
|
|||
$imageImageRepositoryEntity = new ImageImageRepository();
|
||||
}
|
||||
|
||||
$imageImageRepositoryEntity->setName($image['name']);
|
||||
$imageImageRepositoryEntity->setImageFullsum($image['fullsum']);
|
||||
$imageImageRepositoryEntity->setDatasize($image['datasize']);
|
||||
$imageImageRepositoryEntity->setStatus(ImageStatus::SUCCESS);
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Dto\Input;
|
||||
|
||||
class BootClientInput
|
||||
{
|
||||
|
||||
}
|
|
@ -22,7 +22,6 @@ final class ImageRepositoryInput
|
|||
public ?string $name = null;
|
||||
|
||||
#[Assert\NotBlank]
|
||||
#[Assert\Ip]
|
||||
#[Groups(['repository:write'])]
|
||||
#[ApiProperty(description: 'The IP of the repository', example: "")]
|
||||
public ?string $ip = null;
|
||||
|
|
|
@ -4,9 +4,11 @@ namespace App\Dto\Input;
|
|||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use App\Entity\PxeTemplate;
|
||||
use App\Validator\Constraints\PxeTemplateUniqueDefault;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[PxeTemplateUniqueDefault]
|
||||
final class PxeTemplateInput
|
||||
{
|
||||
#[Assert\NotBlank(message: 'validators.pxe_template.name.not_blank')]
|
||||
|
|
|
@ -89,6 +89,9 @@ class Client extends AbstractEntity
|
|||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $firmwareType = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $token = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
@ -354,4 +357,16 @@ class Client extends AbstractEntity
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getToken(): ?string
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
public function setToken(?string $token): static
|
||||
{
|
||||
$this->token = $token;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,11 @@ use Doctrine\DBAL\Types\Types;
|
|||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
|
||||
#[ORM\Entity(repositoryClass: CommandRepository::class)]
|
||||
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_NAME', fields: ['name'])]
|
||||
#[UniqueEntity(fields: ['name'], message: 'validators.command.name.unique')]
|
||||
class Command extends AbstractEntity
|
||||
{
|
||||
use NameableTrait;
|
||||
|
|
|
@ -227,19 +227,17 @@ class CommandTask extends AbstractEntity
|
|||
|
||||
if ($type === 'none') {
|
||||
$execDate = $schedule->getExecutionDate();
|
||||
if ($execDate !== null && $execDate > $now) {
|
||||
if ($executionTime !== null) {
|
||||
$execDateTime = \DateTime::createFromFormat(
|
||||
'Y-m-d H:i:s',
|
||||
$execDate->format('Y-m-d') . ' ' . $executionTime->format('H:i:s')
|
||||
);
|
||||
} else {
|
||||
$execDateTime = $execDate;
|
||||
}
|
||||
if ($executionTime !== null) {
|
||||
$execDateTime = \DateTime::createFromFormat(
|
||||
'Y-m-d H:i:s',
|
||||
$execDate->format('Y-m-d') . ' ' . $executionTime->format('H:i:s')
|
||||
);
|
||||
} else {
|
||||
$execDateTime = $execDate;
|
||||
}
|
||||
|
||||
if ($closestDateTime === null || $execDateTime < $closestDateTime) {
|
||||
$closestDateTime = $execDateTime;
|
||||
}
|
||||
if ($closestDateTime === null || $execDateTime < $closestDateTime) {
|
||||
$closestDateTime = $execDateTime;
|
||||
}
|
||||
} else {
|
||||
$details = $schedule->getRecurrenceDetails();
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace App\EventListener;
|
||||
|
||||
use App\Controller\OgBoot\PxeBootFile\DeleteAction;
|
||||
use App\Controller\OgBoot\PxeBootFile\PostAction;
|
||||
use App\Entity\Client;
|
||||
use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;
|
||||
use Doctrine\ORM\Event\PreUpdateEventArgs;
|
||||
use Doctrine\ORM\Events;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
|
||||
#[AsEntityListener(event: Events::preUpdate, method: 'preUpdate', entity: Client::class)]
|
||||
readonly class ClientMacListener
|
||||
{
|
||||
public function __construct(
|
||||
private DeleteAction $deleteAction,
|
||||
)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function preUpdate(Client $client, PreUpdateEventArgs $event): void
|
||||
{
|
||||
$em = $event->getObjectManager();
|
||||
$uow = $em->getUnitOfWork();
|
||||
$changeSet = $uow->getEntityChangeSet($client);
|
||||
|
||||
if (!array_key_exists('mac', $changeSet)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$oldMac = isset($changeSet['mac'][0]) ? $changeSet['mac'][0] : null;
|
||||
|
||||
if ($oldMac === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->deleteAction->__invoke($oldMac);
|
||||
}
|
||||
|
||||
}
|
|
@ -49,15 +49,19 @@ class CreatePartitionService
|
|||
$partitionEntity->setOperativeSystem(null);
|
||||
|
||||
if (isset($cfg['soi']) && $cfg['soi'] !== '') {
|
||||
$operativeSystem = $this->entityManager->getRepository(OperativeSystem::class)
|
||||
->findOneBy(['name' => $cfg['soi']]);
|
||||
if ($cfg['soi'] === 'DATA') {
|
||||
$partitionEntity->setImage(null);
|
||||
} else {
|
||||
$operativeSystem = $this->entityManager->getRepository(OperativeSystem::class)
|
||||
->findOneBy(['name' => $cfg['soi']]);
|
||||
|
||||
if (!$operativeSystem) {
|
||||
$operativeSystem = new OperativeSystem();
|
||||
$operativeSystem->setName($cfg['soi']);
|
||||
$this->entityManager->persist($operativeSystem);
|
||||
if (!$operativeSystem) {
|
||||
$operativeSystem = new OperativeSystem();
|
||||
$operativeSystem->setName($cfg['soi']);
|
||||
$this->entityManager->persist($operativeSystem);
|
||||
}
|
||||
$partitionEntity->setOperativeSystem($operativeSystem);
|
||||
}
|
||||
$partitionEntity->setOperativeSystem($operativeSystem);
|
||||
}
|
||||
|
||||
$partitionEntity->setClient($clientEntity);
|
||||
|
|
|
@ -16,8 +16,12 @@ use Symfony\Component\HttpClient\HttpClient;
|
|||
readonly class StatusService
|
||||
{
|
||||
public function __construct(
|
||||
#[Autowire(env: 'OG_BOOT_API_URL')]
|
||||
private string $ogBootApiUrl
|
||||
#[Autowire(env: 'OG_BOOT_IP')]
|
||||
protected string $ogBootIp,
|
||||
#[Autowire(env: 'OG_BOOT_PXE_PORT')]
|
||||
protected string $ogBootPxePort,
|
||||
#[Autowire(env: 'OG_BOOT_API_PORT')]
|
||||
protected string $ogBootApiPort,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
@ -31,12 +35,12 @@ readonly class StatusService
|
|||
public function __invoke()
|
||||
{
|
||||
$httpClient = HttpClient::create([
|
||||
'verify_peer' => false, // Ignorar la verificación del certificado SSL
|
||||
'verify_host' => false, // Ignorar la verificación del nombre del host
|
||||
'verify_peer' => false,
|
||||
'verify_host' => false,
|
||||
]);
|
||||
|
||||
try {
|
||||
$response = $httpClient->request('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/status', [
|
||||
$response = $httpClient->request('GET', 'http://'.$this->ogBootIp.':'.$this->ogBootApiPort.'/ogboot/v1/status', [
|
||||
'headers' => [
|
||||
'accept' => 'application/json',
|
||||
],
|
||||
|
|
|
@ -25,13 +25,13 @@ class UDSClient
|
|||
public function __construct(
|
||||
private HttpClientInterface $httpClient,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
#[Autowire(env: 'UDS_URL')]
|
||||
#[Autowire(env: 'REMOTE_PC_URL')]
|
||||
private readonly string $udsAPIurl,
|
||||
#[Autowire(env: 'UDS_AUTH_LOGIN')]
|
||||
#[Autowire(env: 'REMOTE_PC_AUTH_LOGIN')]
|
||||
private readonly string $udsAuthLogin,
|
||||
#[Autowire(env: 'UDS_AUTH_USERNAME')]
|
||||
#[Autowire(env: 'REMOTE_PC_AUTH_USERNAME')]
|
||||
private readonly string $udsAuthUsername,
|
||||
#[Autowire(env: 'UDS_AUTH_PASSWORD')]
|
||||
#[Autowire(env: 'REMOTE_PC_AUTH_PASSWORD')]
|
||||
private readonly string $udsAuthPassword,
|
||||
)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
#[\Attribute]
|
||||
class PxeTemplateUniqueDefault extends Constraint
|
||||
{
|
||||
public string $message;
|
||||
|
||||
public function __construct(mixed $options = null, ?array $groups = null, mixed $payload = null)
|
||||
{
|
||||
parent::__construct($options, $groups, $payload);
|
||||
|
||||
$this->message = 'Ya hay un oglive marcado como predeterminado.';
|
||||
}
|
||||
|
||||
public function getTargets(): string
|
||||
{
|
||||
return self::CLASS_CONSTRAINT;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace App\Validator\Constraints;
|
||||
|
||||
use App\Dto\Input\PxeTemplateInput;
|
||||
use App\Dto\Input\RemoteCalendarRuleInput;
|
||||
use App\Entity\OgLive;
|
||||
use App\Entity\PxeTemplate;
|
||||
use App\Entity\RemoteCalendarRule;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
|
||||
class PxeTemplateUniqueDefaultValidator extends ConstraintValidator
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly RequestStack $requestStack
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public function validate(mixed $value, Constraint $constraint): void
|
||||
{
|
||||
$request = $this->requestStack->getCurrentRequest();
|
||||
|
||||
if (!$value instanceof PxeTemplateInput) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($value->isDefault === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$ogLiveDefault = $this->entityManager->getRepository(PxeTemplate::class)
|
||||
->findOneBy([
|
||||
'isDefault' => true,
|
||||
]);
|
||||
|
||||
if ($ogLiveDefault) {
|
||||
$this->context->buildViolation($constraint->message)->addViolation();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ validators:
|
|||
command:
|
||||
name:
|
||||
not_blank: 'The name should not be blank.'
|
||||
unique: 'The name should be unique.'
|
||||
script:
|
||||
not_blank: 'The script should not be blank.'
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ validators:
|
|||
command:
|
||||
name:
|
||||
not_blank: 'El nombre no debería estar vacío.'
|
||||
unique: 'El nombre debería ser único. Ya existe un comando con ese nombre.'
|
||||
script:
|
||||
not_blank: 'El script no debería estar vacío.'
|
||||
|
||||
|
|
Loading…
Reference in New Issue