Auto. clients creation
testing/ogcore-api/pipeline/head This commit looks good Details

composer-install
Manuel Aranda Rosales 2024-12-04 18:28:36 +01:00
parent e27e4b408f
commit 2b90e2618d
9 changed files with 87 additions and 5 deletions

View File

@ -80,6 +80,8 @@ class StatusAction extends AbstractController
} catch (TransportExceptionInterface $e) {
$client->setStatus(ClientStatus::OFF);
$this->entityManager->persist($client);
$this->entityManager->flush();
return $e->getMessage();
}

View File

@ -26,6 +26,9 @@ class AgentController extends AbstractController
{
}
/**
* @throws \Exception
*/
#[Route('/opengnsys/rest/ogAdmClient/InclusionCliente', methods: ['POST'])]
public function processClient(Request $request): JsonResponse
{

View File

@ -40,7 +40,7 @@ class PostAction extends AbstractOgBootController
'computer_name' => $client->getName(),
'netiface' => $client->getNetiface(),
'group' => $client->getOrganizationalUnit()->getName(),
'ogrepo' => $client->getRepository()?->getIp() ,
'ogrepo' => $client->getRepository() ? $client->getRepository()->getIp() : $client->getOrganizationalUnit()->getNetworkSettings()->getRepository()->getIp(),
'ogcore' => $this->ogCoreIP,
'oglive' => $this->ogBootApiUrl,
'oglog' => $client->getOrganizationalUnit()->getNetworkSettings()?->getOgLog(),

View File

@ -40,11 +40,11 @@ class DeployImageInput
public ?string $mcastIp = null;
#[Groups(['image:write'])]
public ?int $mcastSpeed = null;
public ?string $mcastSpeed = null;
#[OrganizationalUnitMulticastPort]
#[Groups(['image:write'])]
public ?int $mcastPort = null;
public ?string $mcastPort = null;
#[OrganizationalUnitMulticastMode]
#[Groups(['image:write'])]

View File

@ -4,6 +4,7 @@ namespace App\Dto\Input;
use ApiPlatform\Metadata\ApiProperty;
use App\Dto\Output\HardwareProfileOutput;
use App\Dto\Output\ImageRepositoryOutput;
use App\Dto\Output\MenuOutput;
use App\Dto\Output\OgLiveOutput;
use App\Entity\HardwareProfile;
@ -73,6 +74,9 @@ class NetworkSettingsInput
#[Groups(['organizational-unit:write'])]
public ?OgLiveOutput $ogLive = null;
#[Groups(['organizational-unit:write'])]
public ?ImageRepositoryOutput $repository = null;
#[Groups(['organizational-unit:write'])]
public ?bool $validation = null;
@ -116,6 +120,10 @@ class NetworkSettingsInput
$this->ogLive = new OgLiveOutput($networkSettings->getOgLive());
}
if ($networkSettings->getRepository()) {
$this->repository = new ImageRepositoryOutput($networkSettings->getRepository());
}
$this->validation = $networkSettings->getValidation();
}
@ -153,6 +161,10 @@ class NetworkSettingsInput
$networkSettings->setOgLive($this->ogLive->getEntity());
}
if ($this->repository) {
$networkSettings->setRepository($this->repository->getEntity());
}
$networkSettings->setValidation($this->validation);
return $networkSettings;

View File

@ -9,7 +9,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
#[Get(shortName: 'ImageRepository')]
class ImageRepositoryOutput extends AbstractOutput
{
#[Groups(['repository:read', 'image:read', 'client:read'])]
#[Groups(['repository:read', 'image:read', 'client:read', "organizational-unit:read"])]
public ?string $name = '';
#[Groups(['repository:read'])]

View File

@ -57,6 +57,9 @@ 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 ?ImageRepositoryOutput $repository = null;
#[Groups(['network-settings:read', "organizational-unit:read", "client:read"])]
public ?string $oglog = null;
@ -104,6 +107,10 @@ final class NetworkSettingsOutput extends AbstractOutput
$this->ogLive = new OgLiveOutput($networkSettings->getOgLive());
}
if ($networkSettings->getRepository()) {
$this->repository = new ImageRepositoryOutput($networkSettings->getRepository());
}
$this->validation = $networkSettings->getValidation();
$this->createdAt = $networkSettings->getCreatedAt();
$this->createdBy = $networkSettings->getCreatedBy();

View File

@ -10,7 +10,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
#[Get(shortName: 'OgLive')]
final class OgLiveOutput extends AbstractOutput
{
#[Groups(['og-live:read', 'client:read'])]
#[Groups(['og-live:read', 'client:read', "organizational-unit:read"])]
public string $name;
#[Groups(['og-live:read'])]

View File

@ -0,0 +1,58 @@
<?php
namespace App\EventSubscriber;
use ApiPlatform\Symfony\EventListener\EventPriorities;
use App\Controller\OgBoot\PxeBootFile\PostAction;
use App\Dto\Output\ClientOutput;
use App\Entity\Client;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
final readonly class ClientSubscriber implements EventSubscriberInterface
{
public function __construct(
private PostAction $postAction,
)
{
}
public static function getSubscribedEvents(): array
{
return [
KernelEvents::VIEW => ['sendMail', EventPriorities::POST_WRITE],
];
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function sendMail(ViewEvent $event): void
{
$clientOutput = $event->getControllerResult();
$method = $event->getRequest()->getMethod();
if (!$clientOutput instanceof ClientOutput || (Request::METHOD_POST !== $method && Request::METHOD_PUT !== $method)) {
return;
}
/** @var Client $client */
$client = $clientOutput->getEntity();
if ($client->getTemplate() === null) {
return;
}
$this->postAction->__invoke($client, $client->getTemplate());
}
}