Compare commits

...

2 Commits

Author SHA1 Message Date
Manuel Aranda Rosales a2e0ced906 refs #1731. New endpoint integration. Convert image to virtual
testing/ogcore-api/pipeline/head This commit looks good Details
2025-03-19 15:45:07 +01:00
Manuel Aranda Rosales 5be87008c4 refs #1701. Updated Sync with ogLive. Parse new data 2025-03-19 15:44:35 +01:00
12 changed files with 131 additions and 26 deletions

View File

@ -56,6 +56,14 @@ resources:
uriTemplate: /image-image-repositories/{uuid}/backup-image
controller: App\Controller\OgRepository\Image\BackupImageAction
convert_image_to_virtual_image_ogrepository:
shortName: OgRepository Server
class: ApiPlatform\Metadata\Post
method: POST
input: App\Dto\Input\ConvertImageToVirtualInput
uriTemplate: /image-image-repositories/{uuid}/convert-image-to-virtual
controller: App\Controller\OgRepository\Image\ConvertImageToVirtualAction
trash_delete_image_ogrepository:
shortName: OgRepository Server
description: Delete Image in OgRepository

View File

@ -12,6 +12,7 @@ framework:
handler_id: null
cookie_secure: auto
cookie_samesite: lax
storage_factory_id: session.storage.factory.native
#esi: true
#fragments: true

View File

@ -7,7 +7,7 @@ namespace App\Controller\OgBoot;
use App\Controller\OgBoot\PxeBootFile\PostAction;
use App\Service\Trace\CreateService;
use App\Service\Utils\ExtractOgLiveFilenameDateService;
use App\Service\Utils\SymflipyOgLiveFilenameService;
use App\Service\Utils\SimplifyOgLiveFilenameService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
@ -34,7 +34,7 @@ abstract class AbstractOgBootController extends AbstractController
protected readonly EntityManagerInterface $entityManager,
protected readonly HttpClientInterface $httpClient,
protected readonly CreateService $createService,
protected readonly SymflipyOgLiveFilenameService $symflipyOgLiveFilenameService,
protected readonly SimplifyOgLiveFilenameService $simplifyOgLiveFilenameService,
protected readonly ExtractOgLiveFilenameDateService $extractOgLiveFilenameDateService,
)
{

View File

@ -30,7 +30,7 @@ class GetIsosAction extends AbstractOgBootController
}
$isos = array_map(function ($iso) {
$filename = $this->symflipyOgLiveFilenameService->__invoke($iso['filename']);
$filename = $this->simplifyOgLiveFilenameService->__invoke($iso['filename']);
return [
'id' => $iso['id'],

View File

@ -49,7 +49,7 @@ class InstallAction extends AbstractOgBootController
$this->createService->__invoke(null, CommandTypes::INSTALL_OGLIVE, TraceStatus::IN_PROGRESS, 'InstallOgLive_'.$data->getUuid(), $inputData);
$data->setName($this->symflipyOgLiveFilenameService->__invoke($data->getFilename()));
$data->setName($this->simplifyOgLiveFilenameService->__invoke($data->getFilename()));
$data->setDate(new \DateTime());
$data->setStatus(OgLiveStatus::PENDING);
$this->entityManager->persist($data);

View File

@ -76,7 +76,7 @@ class SyncAction extends AbstractOgBootController
*/
private function extracted(OgLive $ogLiveEntity, mixed $ogLive): void
{
$ogLiveEntity->setName($this->symflipyOgLiveFilenameService->__invoke(str_replace(self::OG_BOOT_DIRECTORY, '', $ogLive['directory'])));
$ogLiveEntity->setName($this->simplifyOgLiveFilenameService->__invoke(str_replace(self::OG_BOOT_DIRECTORY, '', $ogLive['directory'])));
$ogLiveEntity->setDate(new \DateTime($this->extractOgLiveFilenameDateService->__invoke(str_replace(self::OG_BOOT_DIRECTORY, '', $ogLive['directory']))));
$ogLiveEntity->setInstalled(true);
$ogLiveEntity->setArchitecture($ogLive['architecture']);

View File

@ -8,6 +8,7 @@ use App\Entity\Trace;
use App\Model\OgLiveStatus;
use App\Model\TraceStatus;
use App\Service\Utils\ExtractOgLiveFilenameDateService;
use App\Service\Utils\SimplifyOgLiveFilenameService;
use App\Service\Utils\SymflipyOgLiveFilenameService;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
@ -34,7 +35,7 @@ class InstallOgLiveResponseAction extends AbstractController
public function __construct(
protected readonly EntityManagerInterface $entityManager,
protected readonly LoggerInterface $logger,
protected readonly SymflipyOgLiveFilenameService $symflipyOgLiveFilenameService,
protected readonly SimplifyOgLiveFilenameService $simplifyOgLiveFilenameService,
protected readonly ExtractOgLiveFilenameDateService $extractOgLiveFilenameDateService,
)
{
@ -93,7 +94,7 @@ class InstallOgLiveResponseAction extends AbstractController
private function updateOgLive (OgLive $ogLive, mixed $details, string $status): void
{
if ( is_array($details) && $status === self::OG_LIVE_INSTALL_SUCCESS) {
$ogLive->setName($this->symflipyOgLiveFilenameService->__invoke($details['directory']));
$ogLive->setName($this->simplifyOgLiveFilenameService->__invoke($details['directory']));
$ogLive->setDate(new \DateTime($this->extractOgLiveFilenameDateService->__invoke($details['directory'])));
$ogLive->setFilename(str_replace(self::OG_BOOT_DIRECTORY, '', $details['directory']));
$ogLive->setInstalled(true);

View File

@ -0,0 +1,65 @@
<?php
namespace App\Controller\OgRepository\Image;
use App\Controller\OgRepository\AbstractOgRepositoryController;
use App\Dto\Input\BackupImageInput;
use App\Entity\ImageImageRepository;
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;
#[AsController]
class ConvertImageToVirtualAction extends AbstractOgRepositoryController
{
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function __invoke(ConvertImageToVirtualAction $input, ImageImageRepository $imageImageRepository): JsonResponse
{
$image = $imageImageRepository->getImage();
if (!$image->getName()) {
throw new ValidatorException('Name is required');
}
$params = [
'json' => [
'ID_img' => $imageImageRepository->getImageFullsum(),
'vm_extension' => 'opengnsys'
]
];
$this->logger->info('Convert image to virtual', ['image' => $image->getName()]);
$repository = $imageImageRepository->getRepository();
$content = $this->createRequest('PUT', 'http://'.$repository->getIp().':8006/ogrepository/v1/images/virtual', $params);
$inputData = [
'imageName' => $image->getName(),
'repositoryUuid' => $repository->getUuid(),
'imageImageRepositoryUuid' => $imageImageRepository->getUuid(),
'ID_img' => $imageImageRepository->getImageFullsum(),
];
$this->createService->__invoke($image->getClient(), CommandTypes::CONVERT_IMAGE_TO_VIRTUAL, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData);
$imageImageRepository->setStatus(ImageStatus::TRANSFERRING);
$this->entityManager->persist($imageImageRepository);
$this->entityManager->flush();
return new JsonResponse(data: $content, status: Response::HTTP_OK);
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Dto\Input;
use App\Dto\Output\ImageOutput;
use App\Dto\Output\ImageRepositoryOutput;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
class ConvertImageToVirtualInput
{
#[Assert\NotNull]
#[Groups(['image-image-repository:write'])]
public ?string $extension = '';
}

View File

@ -12,6 +12,7 @@ final class CommandTypes
public const string BACKUP_IMAGE = 'backup-image';
public const string IMPORT_IMAGE = 'import-image';
public const string EXPORT_IMAGE = 'export-image';
public const string CONVERT_IMAGE_TO_VIRTUAL = 'convert-image-to-virtual';
public const string TRANSFER_IMAGE = 'transfer-image';
public const string POWER_ON = 'power-on';
public const string REBOOT = 'reboot';
@ -26,10 +27,11 @@ final class CommandTypes
self::RESTORE_IMAGE => 'Update Cache',
self::CREATE_IMAGE => 'Create Image',
self::CONVERT_IMAGE => 'Convert Image',
self::CREATE_IMAGE_AUX_FILE => 'Crear fichero auxiliar en repositorio',
self::BACKUP_IMAGE => 'Crear backup de imagen',
self::IMPORT_IMAGE => 'Importar imagen',
self::EXPORT_IMAGE => 'Exportar imagen',
self::CONVERT_IMAGE_TO_VIRTUAL => 'Convert Image to Virtual',
self::CREATE_IMAGE_AUX_FILE => 'Create Image Aux File',
self::BACKUP_IMAGE => 'Backup Image',
self::IMPORT_IMAGE => 'Import image',
self::EXPORT_IMAGE => 'Export image',
self::POWER_ON => 'Encender',
self::REBOOT => 'Reiniciar',
self::SHUTDOWN => 'Apagar',

View File

@ -0,0 +1,28 @@
<?php
namespace App\Service\Utils;
class SimplifyOgLiveFilenameService
{
private const string PATTERN = '/^ogLive-([^-]+)-(.+)-([^-]+)-r([0-9]+)(?:\.([a-f0-9]+))?_([0-9]+)(?:\.iso)?$/';
public function __invoke(string $filename): ?string
{
if (!preg_match(self::PATTERN, $filename, $matches)) {
return null;
}
$distro = $matches[1];
$kernelFull = $matches[2];
$arch = $matches[3];
$revision = $matches[4];
$commit = $matches[5] ?? null;
$date = $matches[6];
$kernel = in_array($arch, ['amd64', 'i386']) ? $kernelFull : "$kernelFull-$arch";
$arch = in_array($arch, ['amd64', 'i386']) ? $arch : 'i386';
return 'ogLive-'.$kernelFull.'-'.$date;
}
}

View File

@ -1,15 +0,0 @@
<?php
namespace App\Service\Utils;
class SymflipyOgLiveFilenameService
{
public function __invoke(string $filename): string
{
if (preg_match('/^(.+)-r\d+\.[a-f0-9]+_(\d{8})(?:\.iso)?$/', $filename, $matches)) {
return "{$matches[1]}-{$matches[2]}";
}
return $filename;
}
}