diff --git a/config/api_platform/ImageRepository.yaml b/config/api_platform/ImageRepository.yaml index 165e425..97cd0b9 100644 --- a/config/api_platform/ImageRepository.yaml +++ b/config/api_platform/ImageRepository.yaml @@ -66,6 +66,15 @@ resources: uriTemplate: /image-repositories/{uuid}/import-image controller: App\Controller\OgRepository\Image\ImportAction + convert_image_ogrepository: + shortName: OgRepository Server + description: Convert Image in OgRepository + class: ApiPlatform\Metadata\Post + method: POST + input: App\Dto\Input\ConvertImageRepositoryInput + uriTemplate: /image-repositories/{uuid}/convert-image + controller: App\Controller\OgRepository\Image\ConvertAction + properties: App\Entity\ImageRepository: id: diff --git a/src/Controller/OgRepository/Image/ConvertAction.php b/src/Controller/OgRepository/Image/ConvertAction.php new file mode 100644 index 0000000..5cc8a73 --- /dev/null +++ b/src/Controller/OgRepository/Image/ConvertAction.php @@ -0,0 +1,78 @@ +name; + + $params = [ + 'json' => [ + 'filesystem' => 'ext4', + 'virtual_image' => $image + ] + ]; + + $this->logger->info('Converting image', ['image' => $image]); + + $content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/images/virtual', $params); + + if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) { + throw new ValidatorException('Error importing image'); + } + + $inputData = [ + 'imageName' => $image + ]; + + $this->createService->__invoke(null, CommandTypes::CONVERT_IMAGE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData); + + $imageEntity = $this->entityManager->getRepository(Image::class)->findOneBy(['name' => $image]); + + if (!$imageEntity){ + $imageEntity = new Image(); + $imageEntity->setName($image); + $imageEntity->setRemotePc(false); + $imageEntity->setIsGlobal(false); + + $this->entityManager->persist($imageEntity); + } + + $imageImageRepositoryEntity = new ImageImageRepository(); + $imageImageRepositoryEntity->setStatus(ImageStatus::PENDING); + $imageImageRepositoryEntity->setImage($imageEntity); + $imageImageRepositoryEntity->setRepository($repository); + + $this->entityManager->persist($imageImageRepositoryEntity); + $this->entityManager->flush(); + + return new JsonResponse(data: [], status: Response::HTTP_OK); + } +} \ No newline at end of file diff --git a/src/Dto/Input/ConvertImageRepositoryInput.php b/src/Dto/Input/ConvertImageRepositoryInput.php new file mode 100644 index 0000000..a7c8d21 --- /dev/null +++ b/src/Dto/Input/ConvertImageRepositoryInput.php @@ -0,0 +1,15 @@ + 'Deploy Image', 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',