refs #1967. Sync ogBoot API when put template

pull/30/head
Manuel Aranda Rosales 2025-05-07 17:26:08 +02:00
parent 7ac0a62e9e
commit 7f5ed49f97
3 changed files with 21 additions and 4 deletions

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

@ -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()]