refs #2120. Remove pxe template when removed client

pull/34/head
Manuel Aranda Rosales 2025-06-02 00:15:03 +02:00
parent f9a00fd319
commit 7d59467acc
5 changed files with 40 additions and 32 deletions

View File

@ -4,6 +4,7 @@ resources:
input: App\Dto\Input\PartitionPostInput
output: App\Dto\Output\PartitionOutput
order:
diskNumber: 'ASC'
partitionNumber: 'ASC'
normalizationContext:
groups: ['default', 'partition:read']

View File

@ -34,16 +34,18 @@ class CheckClientAvailability extends Command
{
$io = new SymfonyStyle($input, $output);
$threshold = (new \DateTime())->modify(' - '.self::THRESHOLD_MINUTES . ' minutes');
$startQueryTime = microtime(true);
$validStatuses = [ClientStatus::OG_LIVE, ClientStatus::WINDOWS, ClientStatus::LINUX, ClientStatus::MACOS];
$query = $this->entityManager->createQuery(
'UPDATE App\Entity\Client c
SET c.status = :status
WHERE c.status = :currentStatus AND c.updatedAt < :threshold'
SET c.status = :status
WHERE c.status IN (:currentStatuses)
AND c.updatedAt < :threshold'
);
$query->setParameter('status', ClientStatus::DISCONNECTED);
$query->setParameter('currentStatus', ClientStatus::OG_LIVE);
$query->setParameter('currentStatuses', $validStatuses);
$query->setParameter('threshold', $threshold);
$updatedCount = $query->execute();

View File

@ -53,17 +53,15 @@ class PostHostAction extends AbstractOgDhcpController
$params
);
// Guardar resultado exitoso
$success[] = [
'client' => $clientEntity->getName(),
'response' => $content
];
// Persistir solo si la llamada fue exitosa
$subnet->addClient($clientEntity);
$this->entityManager->persist($subnet);
$this->entityManager->flush();
} catch (\Throwable $e) { // Capturar cualquier error sin interrumpir
} catch (\Throwable $e) {
$errors[] = [
'client' => $clientEntity->getName(),
'error' => $e->getMessage()

View File

@ -24,26 +24,23 @@ class PutHostAction extends AbstractOgDhcpController
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function __invoke(SubnetAddHostInput $input, Subnet $subnet): JsonResponse
public function __invoke(string $mac, Client $client): JsonResponse
{
$clients = $input->clients;
$subnet = $client->getSubnet();
foreach ($clients as $client) {
/** @var Client $clientEntity */
$clientEntity = $client->getEntity();
$data = [
'host' => $clientEntity->getName(),
'oldMacAddress' => '',
'macAddress' => '',
'address' => '',
];
/** @var Client $clientEntity */
$data = [
'hostname' => $client->getName(),
'oldMacAddress' => strtolower($mac),
'macAddress' => strtolower($client->getMac()),
'address' => $client->getIp(),
];
$params = [
'json' => $data
];
$params = [
'json' => $data
];
$content = $this->createRequest('PUT', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$subnet->getId().'/hosts', $params);
}
$content = $this->createRequest('PUT', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$subnet->getServerId().'/hosts', $params);
return new JsonResponse(status: Response::HTTP_OK);
}

View File

@ -63,15 +63,25 @@ class MercureSubscriber implements EventSubscriberInterface
'status' => $client->getStatus(),
];
$update = new Update(
'clients',
json_encode($data)
);
$this->hub->publish($update);
try {
$update = new Update(
'clients',
json_encode($data)
);
$this->logger->info('Evento Mercure disparado', [
'method' => $method,
'path' => $request->getPathInfo()
]);
$this->hub->publish($update);
$this->logger->info('Evento Mercure disparado', [
'method' => $method,
'path' => $request->getPathInfo()
]);
} catch (\Exception $e) {
$this->logger->error('Error setting method for Mercure update', [
'method' => $method,
'path' => $request->getPathInfo(),
'error' => $e->getMessage(),
]);
return;
}
}
}