Modificado setClientBootMode para crear una traza en caso de ejecución en modo temporal, #114
|
|
@ -1,5 +1,10 @@
|
|||
# Changelog
|
||||
|
||||
## [1.7.10] - 2026-05-13
|
||||
### Improved
|
||||
- Modificado setClientBootMode para crear una traza en caso de ejecución en modo temporal, el id de dicha traza se le pasa al comando opengnsys:pxe:sync para que pueda sincronizar el fichero PXE del cliente y finalizar la traza indicando si se ha realizado correctamente o no
|
||||
- Modificado comando opengnsys:pxe:sync para que pueda ser llamado desde la api con un trace id y se pueda hacer un seguimiento del mismo, con lo que se ha tenido que añadir el servicio de trazas.
|
||||
|
||||
## [1.7.9] - 2026-05-12
|
||||
### Added
|
||||
- Añadida nueva ruta para cambiar la plantilla de un cliente /clients/set-boot-mode, recibe el nombre de la plantilla, el modo 0=temporal, 1=permanente y puede enviarse mac, ip o nombre del cliente o nombre del aula.
|
||||
|
|
|
|||
|
|
@ -3,11 +3,15 @@
|
|||
namespace App\Command;
|
||||
|
||||
use App\Controller\OgBoot\PxeBootFile\PostAction as PostPxeAction;
|
||||
use App\Model\TraceStatus;
|
||||
use App\Repository\ClientRepository;
|
||||
use App\Repository\TraceRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand(
|
||||
|
|
@ -18,6 +22,8 @@ class PxeSyncCommand extends Command
|
|||
{
|
||||
public function __construct(
|
||||
private readonly ClientRepository $clientRepository,
|
||||
private readonly TraceRepository $traceRepository,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly PostPxeAction $postPxeAction
|
||||
) {
|
||||
parent::__construct();
|
||||
|
|
@ -27,13 +33,24 @@ class PxeSyncCommand extends Command
|
|||
{
|
||||
$this
|
||||
->addArgument('mac', InputArgument::REQUIRED, 'Dirección MAC del cliente')
|
||||
->addArgument('delay', InputArgument::OPTIONAL, 'Tiempo de espera en segundos antes de sincronizar', 0);
|
||||
->addArgument('delay', InputArgument::OPTIONAL, 'Tiempo de espera en segundos antes de sincronizar', 0)
|
||||
->addOption('trace-id', null, InputOption::VALUE_OPTIONAL, 'ID de la traza asociada');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$mac = $input->getArgument('mac');
|
||||
$delay = (int) $input->getArgument('delay');
|
||||
$traceId = $input->getOption('trace-id');
|
||||
|
||||
$trace = null;
|
||||
if ($traceId) {
|
||||
$trace = $this->traceRepository->find($traceId);
|
||||
if ($trace) {
|
||||
$trace->setStatus(TraceStatus::IN_PROGRESS);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
}
|
||||
|
||||
if ($delay > 0) {
|
||||
$output->writeln("Esperando $delay segundos...");
|
||||
|
|
@ -42,13 +59,27 @@ class PxeSyncCommand extends Command
|
|||
|
||||
$client = $this->clientRepository->findOneBy(['mac' => $mac]);
|
||||
if (!$client) {
|
||||
$output->writeln("<error>Cliente con MAC $mac no encontrado</error>");
|
||||
$msg = "Cliente con MAC $mac no encontrado";
|
||||
$output->writeln("<error>$msg</error>");
|
||||
if ($trace) {
|
||||
$trace->setStatus(TraceStatus::FAILED);
|
||||
$trace->setOutput($msg);
|
||||
$trace->setFinishedAt(new \DateTime());
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$template = $client->getTemplate();
|
||||
if (!$template) {
|
||||
$output->writeln("<error>El cliente no tiene una plantilla asignada</error>");
|
||||
$msg = "El cliente no tiene una plantilla asignada";
|
||||
$output->writeln("<error>$msg</error>");
|
||||
if ($trace) {
|
||||
$trace->setStatus(TraceStatus::FAILED);
|
||||
$trace->setOutput($msg);
|
||||
$trace->setFinishedAt(new \DateTime());
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
|
|
@ -57,9 +88,26 @@ class PxeSyncCommand extends Command
|
|||
try {
|
||||
$this->postPxeAction->__invoke($client, $template);
|
||||
$output->writeln("<info>Sincronización completada con éxito</info>");
|
||||
|
||||
if ($trace) {
|
||||
$trace->setStatus(TraceStatus::SUCCESS);
|
||||
$trace->setOutput("Sincronización completada con éxito");
|
||||
$trace->setFinishedAt(new \DateTime());
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln("<error>Error durante la sincronización: " . $e->getMessage() . "</error>");
|
||||
$msg = "Error durante la sincronización: " . $e->getMessage();
|
||||
$output->writeln("<error>$msg</error>");
|
||||
|
||||
if ($trace) {
|
||||
$trace->setStatus(TraceStatus::FAILED);
|
||||
$trace->setOutput($msg);
|
||||
$trace->setFinishedAt(new \DateTime());
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,12 @@ namespace App\Controller\OgBoot;
|
|||
use App\Controller\OgBoot\PxeBootFile\PostAction as PostPxeAction;
|
||||
use App\Entity\Client;
|
||||
use App\Entity\PxeTemplate;
|
||||
use App\Entity\Trace;
|
||||
use App\Model\TraceStatus;
|
||||
use App\Repository\ClientRepository;
|
||||
use App\Repository\OrganizationalUnitRepository;
|
||||
use App\Repository\PxeTemplateRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
|
@ -21,7 +24,8 @@ class SetClientBootModeAction extends AbstractController
|
|||
private readonly ClientRepository $clientRepository,
|
||||
private readonly OrganizationalUnitRepository $ouRepository,
|
||||
private readonly PxeTemplateRepository $pxeTemplateRepository,
|
||||
private readonly PostPxeAction $postPxeAction
|
||||
private readonly PostPxeAction $postPxeAction,
|
||||
private readonly EntityManagerInterface $entityManager
|
||||
) {}
|
||||
|
||||
#[Route('/clients/set-boot-mode', name: 'api_clients_set_boot_mode', methods: ['POST'])]
|
||||
|
|
@ -109,7 +113,24 @@ class SetClientBootModeAction extends AbstractController
|
|||
if ($mode == 0) {
|
||||
$projectDir = $this->getParameter('kernel.project_dir');
|
||||
$mac = $client->getMac();
|
||||
$cmd = sprintf('php %s/bin/console opengnsys:pxe:sync %s 60 > /dev/null 2>&1 &', $projectDir,escapeshellarg($mac));
|
||||
|
||||
// Crear traza para el proceso en segundo plano
|
||||
$trace = new Trace();
|
||||
$trace->setClient($client);
|
||||
$trace->setCommand('opengnsys:pxe:sync');
|
||||
$trace->setStatus(TraceStatus::PENDING);
|
||||
$trace->setExecutedAt(new \DateTime());
|
||||
$trace->setInput(['mac' => $mac, 'delay' => 60]);
|
||||
|
||||
$this->entityManager->persist($trace);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$cmd = sprintf(
|
||||
'php %s/bin/console opengnsys:pxe:sync %s 60 --trace-id=%d > /dev/null 2>&1 &',
|
||||
$projectDir,
|
||||
escapeshellarg($mac),
|
||||
$trace->getId()
|
||||
);
|
||||
exec($cmd);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue