Compare commits

...

2 Commits

Author SHA1 Message Date
Manuel Aranda Rosales 6df1057b20 refs #1973. Linked image to partition
testing/ogcore-api/pipeline/head There was a failure building this commit Details
2025-05-08 16:36:04 +02:00
Manuel Aranda Rosales 7f5ed49f97 refs #1967. Sync ogBoot API when put template 2025-05-07 17:26:08 +02:00
10 changed files with 93 additions and 10 deletions

View File

@ -294,7 +294,7 @@ services:
api_platform.filter.trace.search:
parent: 'api_platform.doctrine.orm.search_filter'
arguments: [ { 'id': 'exact', 'command.id': 'exact', 'client.id': 'exact', status: 'exact' } ]
arguments: [ { 'id': 'exact', 'command': 'exact', 'client.id': 'exact', status: 'exact' } ]
tags: [ 'api_platform.filter' ]
api_platform.filter.trace.order:

View File

@ -55,6 +55,7 @@ class DeployImageAction extends AbstractController
'method' => $input->method,
'client' => $client->getEntity()->getUuid(),
'image' => $image->getUuid(),
'imageName' => $image->getName(),
'numDisk' => (string) $input->diskNumber,
'numPartition' => (string) $input->partitionNumber,
];

View File

@ -161,6 +161,24 @@ class StatusController extends AbstractController
$client->setStatus(ClientStatus::OG_LIVE);
$this->entityManager->persist($client);
$this->entityManager->persist($trace);
if ($data['nfn'] === self::RESTORE_IMAGE) {
$partitionData = json_decode(json_encode($trace->getInput()), true);
$numDisk = (int) $partitionData['numDisk'] ?? null;
$numPartition = (int) $partitionData['numPartition'] ?? null;
$imageImageRepository = $this->entityManager->getRepository(ImageImageRepository::class)->findOneBy(['uuid' => $partitionData['image']]);
$partition = $this->entityManager->getRepository(Partition::class)
->findOneBy(['diskNumber' => $numDisk, 'partitionNumber' => $numPartition, 'client' => $client]);
if ($partition) {
$partition->setImage($imageImageRepository);
$this->entityManager->persist($partition);
}
}
$this->entityManager->flush();
}

View File

@ -85,7 +85,7 @@ final class ClientInput
#[ApiProperty(
description: 'La plantilla PXE del cliente'
)]
public ?PxeTemplateOutput $template = null;
public ?PxeTemplateOutput $pxeTemplate = null;
#[Groups(['client:write'])]
#[ApiProperty(
@ -143,7 +143,7 @@ final class ClientInput
}
if ($client->getTemplate()) {
$this->template = new PxeTemplateOutput($client->getTemplate());
$this->pxeTemplate = new PxeTemplateOutput($client->getTemplate());
}
if ($client->getHardwareProfile()) {
@ -165,7 +165,7 @@ final class ClientInput
$ogLive = $this->ogLive?->getEntity() ?? $client->getOrganizationalUnit()?->getNetworkSettings()?->getOgLive();
$hardwareProfile = $this->hardwareProfile?->getEntity() ?? $client->getOrganizationalUnit()?->getNetworkSettings()?->getHardwareProfile();
$repository = $this->repository?->getEntity() ?? $client->getOrganizationalUnit()?->getNetworkSettings()?->getRepository();
$template = $this->template?->getEntity() ?? $client->getOrganizationalUnit()?->getNetworkSettings()?->getPxeTemplate();
$template = $this->pxeTemplate?->getEntity() ?? $client->getOrganizationalUnit()?->getNetworkSettings()?->getPxeTemplate();
$client->setName($this->name);
$client->setSerialNumber($this->serialNumber);

View File

@ -123,11 +123,27 @@ final class ClientOutput extends AbstractOutput
$this->pxeTemplate = $template ? new PxeTemplateOutput($template) : null;
$this->hardwareProfile = $client->getHardwareProfile() ? new HardwareProfileOutput($client->getHardwareProfile()) : null;
$this->subnet = $client->getSubnet()?->getIpAddress();
if ($client->getSubnet()){
$this->subnet = $client->getSubnet()?->getIpAddress().'/'
. $this->convertMaskToCIDR($client->getSubnet() ? $client->getSubnet()->getNetmask() : $client->getOrganizationalUnit()->getNetworkSettings()->getNetmask());
}
$this->status = $client->getStatus();
$this->createdAt = $client->getCreatedAt();
$this->createdBy = $client->getCreatedBy();
$this->maintenance = $client->isMaintenance();
$this->pxeSync = $client->isPxeSync();
}
public function convertMaskToCIDR($mask): int
{
$bits = 0;
$mask = explode(".", $mask);
foreach ($mask as $oct)
$bits += strlen(str_replace("0", "", decbin($oct)));
return $bits;
}
}

View File

@ -13,12 +13,12 @@ class ImageImageRepositoryOutput extends AbstractOutput
public ?ImageOutput $image = null;
#[Groups(['image-image-repository:read', 'image:read'])]
public ?ImageRepositoryOutput $imageRepository= null;
public ?ImageRepositoryOutput $imageRepository = null;
#[Groups(['image-image-repository:read', 'image:read'])]
public string $status;
#[Groups(['image-image-repository:read', 'image:read'])]
#[Groups(['image-image-repository:read', 'image:read', 'partition:read'])]
public string $name;
#[Groups(['image-image-repository:read', 'image:read'])]

View File

@ -3,6 +3,7 @@
namespace App\Dto\Output;
use ApiPlatform\Metadata\Get;
use App\Entity\ImageImageRepository;
use App\Entity\Partition;
use Symfony\Component\Serializer\Annotation\Groups;
@ -30,6 +31,9 @@ class PartitionOutput extends AbstractOutput
#[Groups(['partition:read', 'client:read'])]
public ?OperativeSystemOutput $operativeSystem = null;
#[Groups(['partition:read', 'client:read'])]
public ?ImageImageRepositoryOutput $image = null;
#[Groups(['partition:read', 'client:read'])]
public ?int $memoryUsage = null;
@ -43,9 +47,15 @@ class PartitionOutput extends AbstractOutput
$this->size = $partition->getSize() / 1024 ;
$this->cacheContent = $partition->getCacheContent();
$this->filesystem = $partition->getFilesystem();
if ($partition->getOperativeSystem()) {
$this->operativeSystem = new OperativeSystemOutput($partition->getOperativeSystem());
}
if ($partition->getImage()) {
$this->image = new ImageImageRepositoryOutput($partition->getImage());
}
$this->memoryUsage = $partition->getMemoryUsage() / 100;
}
}

View File

@ -64,6 +64,7 @@ class Client extends AbstractEntity
private ?array $position = ['x' => 0, 'y' => 0];
#[ORM\ManyToOne(inversedBy: 'clients')]
#[ORM\JoinColumn( onDelete: 'SET NULL')]
private ?PxeTemplate $template = null;
#[ORM\ManyToOne()]

View File

@ -49,10 +49,17 @@ class Image extends AbstractEntity
#[ORM\Column(nullable: true)]
private ?int $version = null;
/**
* @var Collection<int, GitImageRepository>
*/
#[ORM\OneToMany(mappedBy: 'image', targetEntity: GitImageRepository::class,cascade: ['persist'], orphanRemoval: true)]
private Collection $gitImageRepositories;
public function __construct()
{
parent::__construct();
$this->imageImageRepositories = new ArrayCollection();
$this->gitImageRepositories = new ArrayCollection();
}
public function getDescription(): ?string
@ -206,4 +213,34 @@ class Image extends AbstractEntity
return $this;
}
/**
* @return Collection<int, GitImageRepository>
*/
public function getGitImageRepositories(): Collection
{
return $this->gitImageRepositories;
}
public function addGitImageRepository(GitImageRepository $gitImageRepository): static
{
if (!$this->gitImageRepositories->contains($gitImageRepository)) {
$this->gitImageRepositories->add($gitImageRepository);
$gitImageRepository->setImage($this);
}
return $this;
}
public function removeGitImageRepository(GitImageRepository $gitImageRepository): static
{
if ($this->gitImageRepositories->removeElement($gitImageRepository)) {
// set the owning side to null (unless already changed)
if ($gitImageRepository->getImage() === $this) {
$gitImageRepository->setImage(null);
}
}
return $this;
}
}

View File

@ -40,7 +40,7 @@ class Partition extends AbstractEntity
#[ORM\ManyToOne(inversedBy: 'partitions')]
#[ORM\JoinColumn(nullable: true)]
private ?Image $image = null;
private ?ImageImageRepository $image = null;
public function getDiskNumber(): ?int
{
@ -150,12 +150,12 @@ class Partition extends AbstractEntity
return $this;
}
public function getImage(): ?Image
public function getImage(): ?ImageImageRepository
{
return $this->image;
}
public function setImage(?Image $image): static
public function setImage(?ImageImageRepository $image): static
{
$this->image = $image;