refs #614. Itnegration ogDhcp. New endpoints
parent
cc1559ef08
commit
6d1a2a89ea
|
@ -29,7 +29,7 @@ resources:
|
|||
class: ApiPlatform\Metadata\GetCollection
|
||||
method: GET
|
||||
input: false
|
||||
uriTemplate: /subnets/server/get-collection
|
||||
uriTemplate: /og-dhcp/server/get-collection
|
||||
controller: App\Controller\OgDhcp\Subnet\GetCollectionAction
|
||||
|
||||
get:
|
||||
|
@ -38,7 +38,7 @@ resources:
|
|||
class: ApiPlatform\Metadata\Get
|
||||
method: GET
|
||||
input: false
|
||||
uriTemplate: /subnets/server/{uuid}/get
|
||||
uriTemplate: /og-dhcp/server/{uuid}/get
|
||||
controller: App\Controller\OgDhcp\Subnet\GetAction
|
||||
|
||||
post:
|
||||
|
@ -47,16 +47,25 @@ resources:
|
|||
class: ApiPlatform\Metadata\Post
|
||||
method: POST
|
||||
input: false
|
||||
uriTemplate: /subnets/server/{uuid}/post
|
||||
uriTemplate: /og-dhcp/server/{uuid}/post
|
||||
controller: App\Controller\OgDhcp\Subnet\PostAction
|
||||
|
||||
put:
|
||||
shortName: Subnet Server
|
||||
description: Create Subnet
|
||||
class: ApiPlatform\Metadata\Put
|
||||
method: PUT
|
||||
input: false
|
||||
uriTemplate: /og-dhcp/server/{uuid}/put
|
||||
controller: App\Controller\OgDhcp\Subnet\PutAction
|
||||
|
||||
delete:
|
||||
shortName: Subnet Server
|
||||
description: Delete Subnet
|
||||
class: ApiPlatform\Metadata\Get
|
||||
method: GET
|
||||
class: ApiPlatform\Metadata\Delete
|
||||
method: DELETE
|
||||
input: false
|
||||
uriTemplate: /subnets/server/{uuid}/delete
|
||||
uriTemplate: /og-dhcp/server/{uuid}/delete
|
||||
controller: App\Controller\OgDhcp\Subnet\DeleteAction
|
||||
|
||||
add_host:
|
||||
|
@ -65,7 +74,7 @@ resources:
|
|||
class: ApiPlatform\Metadata\Post
|
||||
method: POST
|
||||
input: false
|
||||
uriTemplate: /subnets/server/{uuid}/add-host
|
||||
uriTemplate: /og-dhcp/server/{uuid}/add-host
|
||||
controller: App\Controller\OgDhcp\Subnet\AddHostAction
|
||||
|
||||
get_hosts:
|
||||
|
@ -74,7 +83,7 @@ resources:
|
|||
class: ApiPlatform\Metadata\GetCollection
|
||||
method: GET
|
||||
input: false
|
||||
uriTemplate: /subnets/server/{uuid}/get-hosts
|
||||
uriTemplate: /og-dhcp/server/{uuid}/get-hosts
|
||||
controller: App\Controller\OgDhcp\Subnet\GetHostsAction
|
||||
|
||||
put_host:
|
||||
|
@ -83,7 +92,7 @@ resources:
|
|||
class: ApiPlatform\Metadata\Put
|
||||
method: PUT
|
||||
input: false
|
||||
uriTemplate: /subnets/server/{uuid}/put-host
|
||||
uriTemplate: /og-dhcp/server/{uuid}/put-host
|
||||
controller: App\Controller\OgDhcp\Subnet\PutHostAction
|
||||
|
||||
delete_host:
|
||||
|
@ -92,7 +101,7 @@ resources:
|
|||
class: ApiPlatform\Metadata\Delete
|
||||
method: DELETE
|
||||
input: false
|
||||
uriTemplate: /subnets/server/{uuid}/delete-host
|
||||
uriTemplate: /og-dhcp/server/{uuid}/delete-host
|
||||
controller: App\Controller\OgDhcp\Subnet\DeleteHostAction
|
||||
|
||||
properties:
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20240827102833 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE TABLE subnet (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, netmask VARCHAR(255) NOT NULL, ip_address VARCHAR(255) NOT NULL, next_server VARCHAR(255) NOT NULL, boot_file_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_91C24216D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('DROP TABLE subnet');
|
||||
}
|
||||
}
|
|
@ -23,8 +23,9 @@ class GetCollectionAction extends AbstractOgDhcpController
|
|||
*/
|
||||
public function __invoke(HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
$content = $this->createRequest($httpClient, 'GET', $this->ogDhcpApiUrl . '/opengnsys3/rest/subnets');
|
||||
$content = $this->createRequest($httpClient, 'GET', $this->ogDhcpApiUrl . '/ogdhcp/v1/subnets');
|
||||
|
||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,47 @@
|
|||
|
||||
namespace App\Controller\OgDhcp\Subnet;
|
||||
|
||||
class PutAction
|
||||
{
|
||||
use App\Controller\OgDhcp\AbstractOgDhcpController;
|
||||
use App\Entity\Subnet;
|
||||
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;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
#[AsController]
|
||||
class PutAction extends AbstractOgDhcpController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(Subnet $data, HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
if (null === $data->getId()) {
|
||||
throw new ValidatorException('Id is required');
|
||||
}
|
||||
|
||||
$params = [
|
||||
'json' => [
|
||||
'mask' => $data->getNetmask(),
|
||||
'address' => $data->getIpAddress(),
|
||||
'nextServer' => $data->getNextServer(),
|
||||
'bootFileName' => $data->getBootFileName(),
|
||||
]
|
||||
];
|
||||
|
||||
$content = $this->createRequest($httpClient, 'POST', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getId(), $params);
|
||||
|
||||
$this->entityManager->persist($data);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -9,6 +9,11 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
|
||||
final class SubnetInput
|
||||
{
|
||||
#[Assert\NotBlank(message: 'validators.subnet.name.not_blank')]
|
||||
#[Groups(['subnet:write'])]
|
||||
#[ApiProperty(description: 'The name of the subnet', example: "Subnet 1")]
|
||||
public ?string $name = null;
|
||||
|
||||
#[Assert\NotBlank(message: 'validators.subnet.netmask.not_blank')]
|
||||
#[Groups(['subnet:write'])]
|
||||
#[ApiProperty(description: 'The netmask of the subnet', example: "")]
|
||||
|
@ -35,6 +40,7 @@ final class SubnetInput
|
|||
return;
|
||||
}
|
||||
|
||||
$this->name = $subnet->getName();
|
||||
$this->netmask = $subnet->getNetmask();
|
||||
$this->ipAddress = $subnet->getIpAddress();
|
||||
$this->nextServer = $subnet->getNextServer();
|
||||
|
@ -47,6 +53,7 @@ final class SubnetInput
|
|||
$subnet = new Subnet();
|
||||
}
|
||||
|
||||
$subnet->setName($this->name);
|
||||
$subnet->setNetmask($this->netmask);
|
||||
$subnet->setIpAddress($this->ipAddress);
|
||||
$subnet->setNextServer($this->nextServer);
|
||||
|
|
|
@ -10,6 +10,9 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
|||
#[Get(shortName: 'Subnet')]
|
||||
final class SubnetOutput extends AbstractOutput
|
||||
{
|
||||
#[Groups(['subnet:read'])]
|
||||
public string $name;
|
||||
|
||||
#[Groups(['subnet:read'])]
|
||||
public string $netmask;
|
||||
|
||||
|
@ -32,6 +35,7 @@ final class SubnetOutput extends AbstractOutput
|
|||
{
|
||||
parent::__construct($subnet);
|
||||
|
||||
$this->name = $subnet->getName();
|
||||
$this->netmask = $subnet->getNetmask();
|
||||
$this->ipAddress = $subnet->getIpAddress();
|
||||
$this->nextServer = $subnet->getNextServer();
|
||||
|
|
|
@ -8,6 +8,8 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
#[ORM\Entity(repositoryClass: SubnetRepository::class)]
|
||||
class Subnet extends AbstractEntity
|
||||
{
|
||||
use NameableTrait;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $netmask = null;
|
||||
|
||||
|
|
Loading…
Reference in New Issue