refs #917. Partition assistant
testing/ogcore-api/pipeline/head This commit looks good Details

composer-install
Manuel Aranda Rosales 2024-12-04 08:51:21 +01:00
parent 0f52548284
commit e27e4b408f
2 changed files with 34 additions and 3 deletions

View File

@ -11,9 +11,11 @@ use App\Entity\Trace;
use App\Model\ClientStatus; use App\Model\ClientStatus;
use App\Model\CommandTypes; use App\Model\CommandTypes;
use App\Model\ImageStatus; use App\Model\ImageStatus;
use App\Model\PartitionTypes;
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;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@ -35,6 +37,12 @@ class CreateImageAction extends AbstractController
{ {
} }
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function __invoke(Image $image): JsonResponse public function __invoke(Image $image): JsonResponse
{ {
if (!$image->getClient()->getIp()) { if (!$image->getClient()->getIp()) {
@ -46,7 +54,7 @@ class CreateImageAction extends AbstractController
$data = [ $data = [
'dsk' => (string) $partitionInfo['numDisk'], 'dsk' => (string) $partitionInfo['numDisk'],
'par' => (string) $partitionInfo['numPartition'], 'par' => (string) $partitionInfo['numPartition'],
'cpt' => "83", 'cpt' => null,
'idi' => $image->getUuid(), 'idi' => $image->getUuid(),
'nci' => $image->getName(), 'nci' => $image->getName(),
'ipr' => $image->getRepository()->getIp(), 'ipr' => $image->getRepository()->getIp(),
@ -54,6 +62,20 @@ class CreateImageAction extends AbstractController
'ids' => '0' 'ids' => '0'
]; ];
$partitionTypes = PartitionTypes::getPartitionTypes();
$partitionCode = $partitionInfo['partitionCode'];
$cptKey = array_search($partitionCode, array_column($partitionTypes, 'name'), true);
if ($cptKey !== false) {
$keys = array_keys($partitionTypes);
$partitionTypeCode = $keys[$cptKey];
$data['cpt'] = dechex($partitionTypeCode);
} else {
throw new Exception("El tipo de partición '$partitionCode' no se encontró en la lista.");
}
try { try {
$response = $this->httpClient->request('POST', 'https://'.$image->getClient()->getIp().':8000/CloningEngine/CrearImagen', [ $response = $this->httpClient->request('POST', 'https://'.$image->getClient()->getIp().':8000/CloningEngine/CrearImagen', [
'verify_peer' => false, 'verify_peer' => false,

View File

@ -7,6 +7,7 @@ use App\Entity\OperativeSystem;
use App\Entity\Partition; use App\Entity\Partition;
use App\Model\PartitionTypes; use App\Model\PartitionTypes;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Exception;
class CreatePartitionService class CreatePartitionService
{ {
@ -52,12 +53,20 @@ class CreatePartitionService
$partitionEntity->setPartitionNumber($cfg['par']); $partitionEntity->setPartitionNumber($cfg['par']);
$partitionEntity->setSize($cfg['tam']); $partitionEntity->setSize($cfg['tam']);
if (isset($cfg['cpt']) && $cfg['fsi'] !== '') { if (isset($cfg['cpt']) && $cfg['cpt'] !== '') {
$partitionEntity->setPartitionCode(PartitionTypes::getPartitionType(hexdec((integer)$cfg['cpt']))['name']); $decimalValue = hexdec($cfg['cpt']);
$partitionType = PartitionTypes::getPartitionType($decimalValue);
if ($partitionType) {
$partitionEntity->setPartitionCode($partitionType['name']);
} else {
throw new Exception("El tipo de partición con código {$decimalValue} no se encontró.");
}
} else { } else {
$partitionEntity->setPartitionCode(PartitionTypes::getPartitionType(0)['name']); $partitionEntity->setPartitionCode(PartitionTypes::getPartitionType(0)['name']);
} }
$partitionEntity->setFilesystem($cfg['fsi']); $partitionEntity->setFilesystem($cfg['fsi']);
$partitionEntity->setMemoryUsage(((int) $cfg['uso']) * 100); $partitionEntity->setMemoryUsage(((int) $cfg['uso']) * 100);
$this->entityManager->persist($partitionEntity); $this->entityManager->persist($partitionEntity);