Updated APIS, and general improvements

pull/13/head
Manuel Aranda Rosales 2024-11-20 16:00:44 +01:00
parent 5c91265417
commit 2f89e5bc57
53 changed files with 375 additions and 141 deletions

View File

@ -51,8 +51,8 @@ resources:
trash_delete_image_ogrepository: trash_delete_image_ogrepository:
shortName: OgRepository Server shortName: OgRepository Server
description: Delete Image in OgRepository description: Delete Image in OgRepository
class: ApiPlatform\Metadata\Delete class: ApiPlatform\Metadata\Post
method: DELETE method: POST
input: false input: false
uriTemplate: /images/server/{uuid}/delete-trash uriTemplate: /images/server/{uuid}/delete-trash
controller: App\Controller\OgRepository\Image\DeleteTrashAction controller: App\Controller\OgRepository\Image\DeleteTrashAction
@ -60,12 +60,21 @@ resources:
permanent_delete_image_ogrepository: permanent_delete_image_ogrepository:
shortName: OgRepository Server shortName: OgRepository Server
description: Delete Image in OgRepository description: Delete Image in OgRepository
class: ApiPlatform\Metadata\Delete class: ApiPlatform\Metadata\Post
method: DELETE method: POST
input: false input: false
uriTemplate: /images/server/{uuid}/delete-permanent uriTemplate: /images/server/{uuid}/delete-permanent
controller: App\Controller\OgRepository\Image\DeletePermanentAction 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: properties:
App\Entity\Image: App\Entity\Image:
id: id:

View File

@ -1,7 +1,8 @@
{ {
"vars": { "vars": {
"OG_BOOT_API_URL": "http:\/\/192.168.18.48", "OG_BOOT_API_URL": "192.168.68.58",
"OG_DHCP_API_URL": "http:\/\/192.168.18.48:81", "OG_DHCP_API_URL": "192.168.68.58:81",
"OG_CORE_IP": "192.168.68.62",
"UDS_AUTH_LOGIN": "Usuarios locales", "UDS_AUTH_LOGIN": "Usuarios locales",
"UDS_AUTH_USERNAME": "natiqindel", "UDS_AUTH_USERNAME": "natiqindel",
"UDS_AUTH_PASSWORD": "correct horse battery staple", "UDS_AUTH_PASSWORD": "correct horse battery staple",

View File

@ -0,0 +1,35 @@
<?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 Version20241120050107 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 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)');
}
}

View File

@ -8,6 +8,7 @@ use App\Dto\Input\DeployImageInput;
use App\Entity\Command; use App\Entity\Command;
use App\Entity\Image; use App\Entity\Image;
use App\Entity\OrganizationalUnit; use App\Entity\OrganizationalUnit;
use App\Model\CommandTypes;
use App\Model\DeployMethodTypes; use App\Model\DeployMethodTypes;
use App\Model\TraceStatus; use App\Model\TraceStatus;
use App\Service\Trace\CreateService; use App\Service\Trace\CreateService;
@ -32,8 +33,6 @@ class DeployImageAction extends AbstractController
public function __invoke(DeployImageInput $input, Image $image): JsonResponse public function __invoke(DeployImageInput $input, Image $image): JsonResponse
{ {
$command = $this->entityManager->getRepository(Command::class)->findOneBy(['name' => 'Restaurar Imagen']);
$partitionInfo = json_decode($image->getPartitionInfo(), true); $partitionInfo = json_decode($image->getPartitionInfo(), true);
$inputData = [ $inputData = [
@ -52,43 +51,18 @@ class DeployImageAction extends AbstractController
switch ($input->method){ switch ($input->method){
case DeployMethodTypes::UNICAST: case DeployMethodTypes::UNICAST:
$data = [ $agentJobId = $this->deployImageOgAgentAction->__invoke($image, $input, DeployMethodTypes::UNICAST);
'dsk' => (string) $partitionInfo['numDisk'], $this->createService->__invoke($input->client->getEntity(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, $agentJobId, $inputData);
'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);
break; break;
case DeployMethodTypes::MULTICAST: case DeployMethodTypes::MULTICAST:
$data = [ $agentJobId = $this->deployImageOgAgentAction->__invoke($image, $input, DeployMethodTypes::MULTICAST);
'dsk' => (string) $image->getPartitionInfo()['numDisk'], $this->createService->__invoke($image->getClient(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, $agentJobId, $inputData);
'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);
break; break;
} }
return new JsonResponse(data: [], status: Response::HTTP_OK); return new JsonResponse(data: [], status: Response::HTTP_OK);
} }
} }

View File

@ -9,6 +9,8 @@ use App\Entity\Command;
use App\Entity\Image; use App\Entity\Image;
use App\Entity\Trace; use App\Entity\Trace;
use App\Model\ClientStatus; use App\Model\ClientStatus;
use App\Model\CommandTypes;
use App\Model\ImageStatus;
use App\Model\TraceStatus; use App\Model\TraceStatus;
use App\Service\Trace\CreateService; use App\Service\Trace\CreateService;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
@ -71,14 +73,15 @@ class CreateImageAction extends AbstractController
$jobId = json_decode($response->getContent(), true)['job_id']; $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 = $image->getClient();
$client->setStatus(ClientStatus::BUSY); $client->setStatus(ClientStatus::BUSY);
$this->entityManager->persist($client); $this->entityManager->persist($client);
$this->entityManager->flush(); $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); return new JsonResponse(data: $image, status: Response::HTTP_OK);
} }

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Controller\OgAgent; namespace App\Controller\OgAgent;
use App\Dto\Input\DeployImageInput;
use App\Entity\Client; use App\Entity\Client;
use App\Entity\Command; use App\Entity\Command;
use App\Entity\Image; 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()) { if (!$image->getClient()->getIp()) {
throw new ValidatorException('IP is required'); throw new ValidatorException('IP is required');
@ -42,6 +43,9 @@ class DeployImageAction extends AbstractController
$partitionInfo = json_decode($image->getPartitionInfo(), true); $partitionInfo = json_decode($image->getPartitionInfo(), true);
/** @var Client $client */
$client = $input->client->getEntity();
$data = [ $data = [
'dsk' => (string) $partitionInfo['numDisk'], 'dsk' => (string) $partitionInfo['numDisk'],
'par' => (string) $partitionInfo['numPartition'], 'par' => (string) $partitionInfo['numPartition'],
@ -50,7 +54,7 @@ class DeployImageAction extends AbstractController
'nci' => $image->getName(), 'nci' => $image->getName(),
'ipr' => $image->getRepository()->getIp(), 'ipr' => $image->getRepository()->getIp(),
'nfn' => 'RestaurarImagen', 'nfn' => 'RestaurarImagen',
'ptc' => 'unicast', 'ptc' => $method,
'ids' => '0' 'ids' => '0'
]; ];

View File

@ -7,6 +7,7 @@ use App\Entity\OperativeSystem;
use App\Entity\Partition; use App\Entity\Partition;
use App\Model\ClientStatus; use App\Model\ClientStatus;
use App\Model\OgLiveStatus; use App\Model\OgLiveStatus;
use App\Service\CreatePartitionService;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpClient\HttpClient; use Symfony\Component\HttpClient\HttpClient;
@ -26,7 +27,8 @@ class StatusAction extends AbstractController
{ {
public function __construct( public function __construct(
protected readonly EntityManagerInterface $entityManager, 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'); 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 { try {
$response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/ogAdmClient/status', [ $response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/ogAdmClient/status', [
'verify_peer' => false, 'verify_peer' => false,
@ -66,33 +79,43 @@ class StatusAction extends AbstractController
$data = json_decode($response->getContent(), true); $data = json_decode($response->getContent(), true);
if (isset($data['cfg'])) { if (isset($data['cfg'])) {
foreach ($data['cfg'] as $cfg) { $this->createPartitionService->__invoke($data, $client);
$partitionEntity = $this->entityManager->getRepository(Partition::class) }
->findOneBy(['client' => $client, 'diskNumber' => $cfg['disk'], 'partitionNumber' => $cfg['par']]);
if (!$partitionEntity) { $this->entityManager->persist($client);
$partitionEntity = new Partition(); $this->entityManager->flush();
}
if (isset($cfg['soi']) && $cfg['soi'] !== '') { return new JsonResponse(status: Response::HTTP_OK);
$operativeSystem = $this->entityManager->getRepository(OperativeSystem::class) }
->findOneBy(['name' => $cfg['soi']]);
if (!$operativeSystem) { public function getSOStatus (Client $client): JsonResponse
$operativeSystem = new OperativeSystem(); {
$operativeSystem->setName($cfg['soi']); try {
$this->entityManager->persist($operativeSystem); $response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/opengnsys/status', [
} 'verify_peer' => false,
$partitionEntity->setOperativeSystem($operativeSystem); '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); } catch (TransportExceptionInterface $e) {
$partitionEntity->setDiskNumber($cfg['disk']); $client->setStatus(ClientStatus::OFF);
$partitionEntity->setPartitionNumber($cfg['par']);
$partitionEntity->setSize($cfg['tam']); return new JsonResponse(
$partitionEntity->setMemoryUsage(((int) $cfg['uso']) * 100); data: ['error' => $e->getMessage()],
$this->entityManager->persist($partitionEntity); 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); $this->entityManager->persist($client);

View File

@ -7,6 +7,7 @@ namespace App\Controller\OgAgent\Webhook;
use App\Entity\Client; use App\Entity\Client;
use App\Entity\OrganizationalUnit; use App\Entity\OrganizationalUnit;
use App\Entity\Partition; use App\Entity\Partition;
use App\Service\CreatePartitionService;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
@ -19,7 +20,8 @@ use Symfony\Component\Routing\Attribute\Route;
class AgentController extends AbstractController class AgentController extends AbstractController
{ {
public function __construct( 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); return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND);
} }
foreach ($data['cfg'] as $cfg) { if (isset($data['cfg'])) {
if (isset($cfg['disk']) && isset($cfg['par'])) { $this->createPartitionService->__invoke($data, $clientEntity);
$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);
}
} }
$this->entityManager->flush(); $this->entityManager->flush();
$center = $this->entityManager->getRepository(OrganizationalUnit::class)->find($clientEntity->getOrganizationalUnit()->getId()); $center = $this->entityManager->getRepository(OrganizationalUnit::class)->find($clientEntity->getOrganizationalUnit()->getId());

View File

@ -6,10 +6,14 @@ use App\Controller\OgRepository\Image\CreateAuxFilesAction;
use App\Entity\Image; use App\Entity\Image;
use App\Entity\OperativeSystem; use App\Entity\OperativeSystem;
use App\Entity\Partition; use App\Entity\Partition;
use App\Entity\Software;
use App\Entity\SoftwareProfile;
use App\Entity\Trace; use App\Entity\Trace;
use App\Model\ClientStatus; use App\Model\ClientStatus;
use App\Model\ImageStatus; use App\Model\ImageStatus;
use App\Model\SoftwareTypes;
use App\Model\TraceStatus; use App\Model\TraceStatus;
use App\Service\CreatePartitionService;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
@ -28,7 +32,8 @@ class ClientsController extends AbstractController
{ {
public function __construct( public function __construct(
protected readonly EntityManagerInterface $entityManager, 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']]); $trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]);
$image = $this->entityManager->getRepository(Image::class)->findOneBy(['uuid' => $data['idi']]); $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) { if ($data['res'] === 1) {
$trace->setStatus(TraceStatus::SUCCESS); $trace->setStatus(TraceStatus::SUCCESS);
$trace->setFinishedAt(new \DateTime()); $trace->setFinishedAt(new \DateTime());
$image->setStatus(ImageStatus::PENDING); $image->setStatus(ImageStatus::AUX_FILES_PENDING);
$image->setCreated(true); $image->setCreated(true);
if (isset($data['cfg'])) {
$this->createPartitionService->__invoke($data, $image->getClient());
}
$this->createSoftwareProfile($data['inv_sft'], $image);
$this->createAuxFilesAction->__invoke($image); $this->createAuxFilesAction->__invoke($image);
} else { } else {
$trace->setStatus(TraceStatus::FAILED); $trace->setStatus(TraceStatus::FAILED);
$trace->setFinishedAt(new \DateTime()); $trace->setFinishedAt(new \DateTime());
$trace->setOutput($data['der']); $trace->setOutput($data['der']);
$image->setCreated(false); $image->setCreated(false);
} }
$this->entityManager->persist($image); $this->entityManager->persist($image);
@ -99,4 +110,31 @@ class ClientsController extends AbstractController
return new JsonResponse([], Response::HTTP_OK); 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();
}
} }

View File

@ -23,6 +23,8 @@ abstract class AbstractOgBootController extends AbstractController
public function __construct( public function __construct(
#[Autowire(env: 'OG_BOOT_API_URL')] #[Autowire(env: 'OG_BOOT_API_URL')]
protected string $ogBootApiUrl, protected string $ogBootApiUrl,
#[Autowire(env: 'OG_CORE_IP')]
protected string $ogCoreIP,
protected readonly EntityManagerInterface $entityManager protected readonly EntityManagerInterface $entityManager
) )
{ {

View File

@ -29,7 +29,7 @@ class GetAction extends AbstractOgBootController
throw new ValidatorException('Checksum is required'); 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); return new JsonResponse(data: $content, status: Response::HTTP_OK);
} }

View File

@ -24,7 +24,7 @@ class GetCollectionAction extends AbstractOgBootController
*/ */
public function __invoke(HttpClientInterface $httpClient): JsonResponse 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); return new JsonResponse(data: $content, status: Response::HTTP_OK);
} }

View File

@ -23,7 +23,7 @@ class GetDefaultAction extends AbstractOgBootController
*/ */
public function __invoke(HttpClientInterface $httpClient): JsonResponse 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); return new JsonResponse(status: Response::HTTP_OK);
} }

View File

@ -24,7 +24,7 @@ class GetIsosAction extends AbstractOgBootController
*/ */
public function __invoke(HttpClientInterface $httpClient): JsonResponse 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); return new JsonResponse(data: $content, status: Response::HTTP_OK);
} }

View File

@ -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); $data->setStatus(OgLiveStatus::PENDING);
$entityManager->persist($data); $entityManager->persist($data);

View File

@ -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]); $oldDefaultOgLive = $this->entityManager->getRepository(OgLive::class)->findBy(['isDefault' => true]);

View File

@ -27,7 +27,7 @@ class SyncAction extends AbstractOgBootController
*/ */
public function __invoke(HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse 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) { foreach ($content['message']['installed_ogLives'] as $ogLive) {
$ogLiveEntity = $this->entityManager->getRepository(OgLive::class)->findOneBy(['checksum' => $ogLive['id']]); $ogLiveEntity = $this->entityManager->getRepository(OgLive::class)->findOneBy(['checksum' => $ogLive['id']]);

View File

@ -31,7 +31,7 @@ class UninstallAction extends AbstractOgBootController
throw new ValidatorException('Checksum is required'); 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->remove($data);
$entityManager->flush(); $entityManager->flush();

View File

@ -27,7 +27,7 @@ class GetAction extends AbstractOgBootController
public function __invoke(Client $client, HttpClientInterface $httpClient): JsonResponse public function __invoke(Client $client, HttpClientInterface $httpClient): JsonResponse
{ {
try { 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' => [ 'headers' => [
'accept' => 'application/json', 'accept' => 'application/json',
], ],

View File

@ -26,7 +26,7 @@ class GetCollectionAction extends AbstractOgBootController
*/ */
public function __invoke(HttpClientInterface $httpClient): JsonResponse 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); return new JsonResponse(data: $content, status: Response::HTTP_OK);
} }

View File

@ -36,19 +36,20 @@ class PostAction extends AbstractOgBootController
'mac' => strtolower($client->getMac()), 'mac' => strtolower($client->getMac()),
'lang' => 'es_ES.UTF_8', 'lang' => 'es_ES.UTF_8',
'ip' => $client->getIp(), 'ip' => $client->getIp(),
//'server_ip' => '192.168.2.4', //rootServer (ogCore) 'server_ip' => $this->ogBootApiUrl,
'router' => $client->getOrganizationalUnit()->getNetworkSettings()->getRouter(), 'router' => $client->getOrganizationalUnit()->getNetworkSettings()->getRouter(),
'netmask' => $client->getOrganizationalUnit()->getNetworkSettings() ? $client->getOrganizationalUnit()->getNetworkSettings()->getNetmask() : '255.255.255.0', 'netmask' => $client->getOrganizationalUnit()->getNetworkSettings() ? $client->getOrganizationalUnit()->getNetworkSettings()->getNetmask() : '255.255.255.0',
'computer_name' => $client->getName(), 'computer_name' => $client->getName(),
'netiface' => $client->getNetiface(), 'netiface' => $client->getNetiface(),
'group' => $client->getOrganizationalUnit()->getName(), 'group' => $client->getOrganizationalUnit()->getName(),
'ogrepo' => $client->getRepository() ? $client->getRepository()->getIp() : '192.168.2.4', 'ogrepo' => $client->getRepository()->getIp() ,
//'ogcore' => 'parametro_consola', 'ogcore' => $this->ogCoreIP,
//'oglive' => '192.168.2.4', 'oglive' => $this->ogBootApiUrl,
'oglog' => '192.168.2.4', 'oglog' => $client->getOrganizationalUnit()->getNetworkSettings()?->getOgLog(),
//'ogshare' => '192.168.2.4', 'ogshare' => $client->getOrganizationalUnit()->getNetworkSettings()?->getOgShare()
? $client->getOrganizationalUnit()->getNetworkSettings()?->getOgShare(): $this->ogBootApiUrl,
'oglivedir' => $client->getOgLive()->getFilename(), 'oglivedir' => $client->getOgLive()->getFilename(),
'ogprof' => 'false', // cliente del profesor 'ogprof' => 'false',
'hardprofile' => $client->getHardwareProfile() ? $client->getHardwareProfile()->getDescription() : 'default', 'hardprofile' => $client->getHardwareProfile() ? $client->getHardwareProfile()->getDescription() : 'default',
'ogntp' => $client->getOrganizationalUnit()->getNetworkSettings()?->getNtp(), //optional 'ogntp' => $client->getOrganizationalUnit()->getNetworkSettings()?->getNtp(), //optional
'ogdns' => $client->getOrganizationalUnit()->getNetworkSettings()?->getDns(), //optional 'ogdns' => $client->getOrganizationalUnit()->getNetworkSettings()?->getDns(), //optional
@ -58,7 +59,7 @@ class PostAction extends AbstractOgBootController
]; ];
try { try {
$response = $httpClient->request('POST', $this->ogBootApiUrl.'/ogboot/v1/pxes', [ $response = $httpClient->request('POST', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxes', [
'headers' => [ 'headers' => [
'accept' => 'application/json', 'accept' => 'application/json',
'Content-Type' => 'application/json', 'Content-Type' => 'application/json',

View File

@ -27,7 +27,7 @@ class DeleteAction extends AbstractOgBootController
public function __invoke(PxeTemplate $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse public function __invoke(PxeTemplate $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse
{ {
try { 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' => [ 'headers' => [
'accept' => 'application/json', 'accept' => 'application/json',
], ],

View File

@ -26,7 +26,7 @@ class GetAction extends AbstractOgBootController
public function __invoke(PxeTemplate $template, HttpClientInterface $httpClient): JsonResponse public function __invoke(PxeTemplate $template, HttpClientInterface $httpClient): JsonResponse
{ {
try { 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' => [ 'headers' => [
'accept' => 'application/json', 'accept' => 'application/json',
], ],

View File

@ -25,7 +25,7 @@ class GetCollectionAction extends AbstractOgBootController
public function __invoke(HttpClientInterface $httpClient): JsonResponse public function __invoke(HttpClientInterface $httpClient): JsonResponse
{ {
try { try {
$response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/pxe-templates', [ $response = $httpClient->request('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates', [
'headers' => [ 'headers' => [
'accept' => 'application/json', 'accept' => 'application/json',
], ],

View File

@ -27,7 +27,7 @@ class PostAction extends AbstractOgBootController
public function __invoke(PxeTemplate $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse public function __invoke(PxeTemplate $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse
{ {
try { try {
$response = $httpClient->request('POST', $this->ogBootApiUrl.'/ogboot/v1/pxe-templates', [ $response = $httpClient->request('POST', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates', [
'headers' => [ 'headers' => [
'accept' => 'application/json', 'accept' => 'application/json',
'Content-Type' => 'application/json', 'Content-Type' => 'application/json',

View File

@ -28,7 +28,7 @@ class SyncAction extends AbstractOgBootController
*/ */
public function __invoke(HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse 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) { foreach ($content['message'] as $template) {
$templateEntity = $this->entityManager->getRepository(PxeTemplate::class)->findOneBy(['name' => $template]); $templateEntity = $this->entityManager->getRepository(PxeTemplate::class)->findOneBy(['name' => $template]);

View File

@ -25,7 +25,7 @@ abstract class AbstractOgDhcpController extends AbstractController
#[Autowire(env: 'OG_DHCP_API_URL')] #[Autowire(env: 'OG_DHCP_API_URL')]
protected readonly string $ogDhcpApiUrl, protected readonly string $ogDhcpApiUrl,
protected readonly EntityManagerInterface $entityManager, protected readonly EntityManagerInterface $entityManager,
protected readonly GetIpAddressAndNetmaskFromCIDRService $getIpAddressAndNetmaskFromCIDRService protected readonly GetIpAddressAndNetmaskFromCIDRService $getIpAddressAndNetmaskFromCIDRService,
) )
{ {
} }

View File

@ -29,7 +29,7 @@ class DeleteAction extends AbstractOgDhcpController
throw new ValidatorException('Data Id is required'); 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->remove($data);
$this->entityManager->flush(); $this->entityManager->flush();

View File

@ -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); $data->removeClient($client);
$this->entityManager->persist($data); $this->entityManager->persist($data);

View File

@ -29,7 +29,7 @@ class GetAction extends AbstractOgDhcpController
throw new ValidatorException('Checksum is required'); 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); return new JsonResponse(data: $content, status: Response::HTTP_OK);
} }

View File

@ -23,7 +23,7 @@ class GetCollectionAction extends AbstractOgDhcpController
*/ */
public function __invoke(HttpClientInterface $httpClient): JsonResponse 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); return new JsonResponse(data: $content, status: Response::HTTP_OK);
} }

View File

@ -29,7 +29,7 @@ class GetHostsAction extends AbstractOgDhcpController
throw new ValidatorException('Checksum is required'); 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); return new JsonResponse(data: $content, status: Response::HTTP_OK);
} }

View File

@ -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->setServerId($content['message']['id']);
$data->setSynchronized(true); $data->setSynchronized(true);

View File

@ -44,7 +44,7 @@ class PostHostAction extends AbstractOgDhcpController
'json' => $data '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); $subnet->addClient($clientEntity);
$this->entityManager->persist($subnet); $this->entityManager->persist($subnet);

View File

@ -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->persist($data);
$this->entityManager->flush(); $this->entityManager->flush();

View File

@ -42,7 +42,7 @@ class PutHostAction extends AbstractOgDhcpController
'json' => $data '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); return new JsonResponse(status: Response::HTTP_OK);

View File

@ -26,7 +26,7 @@ class SyncAction extends AbstractOgDhcpController
*/ */
public function __invoke(HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse 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 = []; $arraySync = [];

View File

@ -5,6 +5,7 @@ namespace App\Controller\OgRepository\Image;
use App\Controller\OgRepository\AbstractOgRepositoryController; use App\Controller\OgRepository\AbstractOgRepositoryController;
use App\Entity\Command; use App\Entity\Command;
use App\Entity\Image; use App\Entity\Image;
use App\Model\CommandTypes;
use App\Model\ImageStatus; use App\Model\ImageStatus;
use App\Model\TraceStatus; use App\Model\TraceStatus;
use Doctrine\ORM\EntityManagerInterface; 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); $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 = [ $inputData = [
'imageName' => $data->getName(), 'imageName' => $data->getName(),
'imageUuid' => $data->getUuid(), '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); $data->setStatus(ImageStatus::IN_PROGRESS);
$this->entityManager->persist($data); $this->entityManager->persist($data);

View File

@ -29,7 +29,7 @@ class DeletePermanentAction extends AbstractOgRepositoryController
throw new ValidatorException('Fullsum is required'); 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->remove($data);
$this->entityManager->flush(); $this->entityManager->flush();

View File

@ -30,7 +30,7 @@ class DeleteTrashAction extends AbstractOgRepositoryController
throw new ValidatorException('Fullsum is required'); 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); $data->setStatus(ImageStatus::TRASH);
$this->entityManager->persist($data); $this->entityManager->persist($data);

View File

@ -6,6 +6,7 @@ use App\Controller\OgRepository\AbstractOgRepositoryController;
use App\Dto\Input\DeployImageInput; use App\Dto\Input\DeployImageInput;
use App\Entity\Command; use App\Entity\Command;
use App\Entity\Image; use App\Entity\Image;
use App\Model\CommandTypes;
use App\Model\TraceStatus; use App\Model\TraceStatus;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@ -20,7 +21,6 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
class DeployImageAction extends AbstractOgRepositoryController class DeployImageAction extends AbstractOgRepositoryController
{ {
/** /**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface * @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface * @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface * @throws ClientExceptionInterface
@ -29,9 +29,7 @@ class DeployImageAction extends AbstractOgRepositoryController
{ {
$client = $input->client; $client = $input->client;
$command = $this->entityManager->getRepository(Command::class)->findOneBy(['name' => 'Deploy Imagen']); $this->createService->__invoke($data->getClient(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, null);
$this->createService->__invoke($data->getClient(), $command, TraceStatus::IN_PROGRESS, null);
return new JsonResponse(data: [], status: Response::HTTP_OK); return new JsonResponse(data: [], status: Response::HTTP_OK);
} }

View File

@ -0,0 +1,51 @@
<?php
namespace App\Controller\OgRepository\Image;
use App\Controller\OgRepository\AbstractOgRepositoryController;
use App\Dto\Input\DeployImageInput;
use App\Entity\Image;
use App\Model\CommandTypes;
use App\Model\ImageStatus;
use App\Model\TraceStatus;
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;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
#[AsController]
class RecoverAction extends AbstractOgRepositoryController
{
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function __invoke(Image $data, HttpClientInterface $httpClient): JsonResponse
{
if (!$data->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);
}
}

View File

@ -76,6 +76,12 @@ class NetworkSettingsInput
#[Groups(['organizational-unit:write'])] #[Groups(['organizational-unit:write'])]
public ?bool $validation = null; 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) public function __construct(?NetworkSettings $networkSettings = null)
{ {
if (!$networkSettings) { if (!$networkSettings) {
@ -95,6 +101,8 @@ class NetworkSettingsInput
$this->mcastSpeed = $networkSettings->getMcastSpeed(); $this->mcastSpeed = $networkSettings->getMcastSpeed();
$this->mcastPort = $networkSettings->getMcastPort(); $this->mcastPort = $networkSettings->getMcastPort();
$this->mcastMode = $networkSettings->getMcastMode(); $this->mcastMode = $networkSettings->getMcastMode();
$this->oglog = $networkSettings->getOglog();
$this->ogshare = $networkSettings->getOgshare();
if ($networkSettings->getMenu()) { if ($networkSettings->getMenu()) {
$this->menu = new MenuOutput($networkSettings->getMenu()); $this->menu = new MenuOutput($networkSettings->getMenu());
@ -130,6 +138,8 @@ class NetworkSettingsInput
$networkSettings->setMcastSpeed($this->mcastSpeed); $networkSettings->setMcastSpeed($this->mcastSpeed);
$networkSettings->setMcastPort($this->mcastPort); $networkSettings->setMcastPort($this->mcastPort);
$networkSettings->setMcastMode($this->mcastMode); $networkSettings->setMcastMode($this->mcastMode);
$networkSettings->setOglog($this->oglog);
$networkSettings->setOgshare($this->ogshare);
if ($this->menu) { if ($this->menu) {
$networkSettings->setMenu($this->menu->getEntity()); $networkSettings->setMenu($this->menu->getEntity());

View File

@ -57,6 +57,12 @@ final class NetworkSettingsOutput extends AbstractOutput
#[Groups(['network-settings:read', "organizational-unit:read", "client:read"])] #[Groups(['network-settings:read', "organizational-unit:read", "client:read"])]
public ?OgLiveOutput $ogLive = null; 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"])] #[Groups(['network-settings:read', "organizational-unit:read", "client:read"])]
public ?bool $validation = null; public ?bool $validation = null;
@ -83,6 +89,8 @@ final class NetworkSettingsOutput extends AbstractOutput
$this->mcastSpeed = $networkSettings->getMcastSpeed(); $this->mcastSpeed = $networkSettings->getMcastSpeed();
$this->mcastPort = $networkSettings->getMcastPort(); $this->mcastPort = $networkSettings->getMcastPort();
$this->mcastMode = $networkSettings->getMcastMode(); $this->mcastMode = $networkSettings->getMcastMode();
$this->oglog = $networkSettings->getOglog();
$this->ogshare = $networkSettings->getOgshare();
if ($networkSettings->getMenu()) { if ($networkSettings->getMenu()) {
$this->menu = new MenuOutput($networkSettings->getMenu()); $this->menu = new MenuOutput($networkSettings->getMenu());

View File

@ -11,7 +11,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
final class TraceOutput extends AbstractOutput final class TraceOutput extends AbstractOutput
{ {
#[Groups(['trace:read'])] #[Groups(['trace:read'])]
public CommandOutput $command; public ?string $command;
#[Groups(['trace:read'])] #[Groups(['trace:read'])]
public ClientOutput $client; public ClientOutput $client;
@ -44,7 +44,7 @@ final class TraceOutput extends AbstractOutput
{ {
parent::__construct($trace); parent::__construct($trace);
$this->command = new CommandOutput($trace->getCommand()); $this->command = $trace->getCommand();
$this->client = new ClientOutput($trace->getClient()); $this->client = new ClientOutput($trace->getClient());
$this->status = $trace->getStatus(); $this->status = $trace->getStatus();
$this->jobId = $trace->getJobId(); $this->jobId = $trace->getJobId();

View File

@ -13,9 +13,8 @@ class Trace extends AbstractEntity
#[ORM\JoinColumn(nullable: false)] #[ORM\JoinColumn(nullable: false)]
private ?Client $client = null; private ?Client $client = null;
#[ORM\ManyToOne(inversedBy: 'traces')] #[ORM\Column(length: 255, nullable: true)]
#[ORM\JoinColumn(nullable: false)] private ?string $command = null;
private ?Command $command = null;
#[ORM\Column(length: 255)] #[ORM\Column(length: 255)]
private ?string $status = null; private ?string $status = null;
@ -47,12 +46,12 @@ class Trace extends AbstractEntity
return $this; return $this;
} }
public function getCommand(): ?Command public function getCommand(): ?string
{ {
return $this->command; return $this->command;
} }
public function setCommand(?Command $command): static public function setCommand(?string $command): static
{ {
$this->command = $command; $this->command = $command;

View File

@ -0,0 +1,38 @@
<?php
namespace App\Model;
final class CommandTypes
{
public const string DEPLOY_IMAGE = 'deploy-image';
public const string RESTORE_IMAGE = 'restore-image';
public const string CREATE_IMAGE = 'create-image';
public const string CREATE_IMAGE_AUX_FILE = 'create-image-aux-file';
public const string POWER_ON = 'power-on';
public const string REBOOT = 'reboot';
public const string SHUTDOWN = 'shutdown';
public const string LOGIN = 'login';
public const string LOGOUT = 'logout';
private const array COMMAND_TYPES = [
self::DEPLOY_IMAGE => '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;
}
}

View File

@ -6,6 +6,7 @@ final class ImageStatus
{ {
public const string PENDING = 'pending'; public const string PENDING = 'pending';
public const string IN_PROGRESS = 'in-progress'; public const string IN_PROGRESS = 'in-progress';
public const string AUX_FILES_PENDING = 'aux-files-pending';
public const string SUCCESS = 'success'; public const string SUCCESS = 'success';
public const string TRASH = 'trash'; public const string TRASH = 'trash';
public const string FAILED = 'failed'; public const string FAILED = 'failed';
@ -13,6 +14,7 @@ final class ImageStatus
private const array STATUS = [ private const array STATUS = [
self::PENDING => 'Pendiente', self::PENDING => 'Pendiente',
self::IN_PROGRESS => 'En progreso', self::IN_PROGRESS => 'En progreso',
self::AUX_FILES_PENDING => 'Archivos auxiliares pendientes',
self::TRASH => 'Papelera', self::TRASH => 'Papelera',
self::SUCCESS => 'Completado', self::SUCCESS => 'Completado',
self::FAILED => 'Fallido', self::FAILED => 'Fallido',

View File

@ -0,0 +1,50 @@
<?php
namespace App\Service;
use App\Entity\Client;
use App\Entity\OperativeSystem;
use App\Entity\Partition;
use Doctrine\ORM\EntityManagerInterface;
class CreatePartitionService
{
public function __construct(
protected EntityManagerInterface $entityManager
)
{
}
public function __invoke(array $data, Client $clientEntity): void
{
foreach ($data['cfg'] as $cfg) {
$partitionEntity = $this->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();
}
}

View File

@ -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 = new Trace();
$trace->setClient($client); $trace->setClient($client);
$trace->setCommand($command ?? null); $trace->setCommand($command);
$trace->setStatus($status); $trace->setStatus($status);
$trace->setJobId($jobId); $trace->setJobId($jobId);
$trace->setExecutedAt(new \DateTime()); $trace->setExecutedAt(new \DateTime());

View File

@ -54,12 +54,12 @@ readonly class ImageProcessor implements ProcessorInterface
} }
$image = $data->createOrUpdateEntity($entity); $image = $data->createOrUpdateEntity($entity);
$this->validator->validate($image);
if ($data->source !== 'input') { if ($data->source !== 'input') {
$response = $this->createImageActionController->__invoke($image); $response = $this->createImageActionController->__invoke($image);
} }
$this->validator->validate($image);
$this->imageRepository->save($image); $this->imageRepository->save($image);
return new ImageOutput($image); return new ImageOutput($image);

View File

@ -37,6 +37,7 @@ validators:
image: image:
name: name:
not_blank: 'The name should not be blank.' not_blank: 'The name should not be blank.'
unique: 'The name should be unique.'
network_settings: network_settings:
ip_address: ip_address:

View File

@ -37,6 +37,7 @@ validators:
image: image:
name: name:
not_blank: 'El nombre no debería estar vacío.' 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: network_settings:
ip_address: ip_address: