refs #1731. New endpoint integration. Convert image to virtual
testing/ogcore-api/pipeline/head This commit looks good
Details
testing/ogcore-api/pipeline/head This commit looks good
Details
parent
5be87008c4
commit
a2e0ced906
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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 = '';
|
||||
}
|
|
@ -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',
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue