refs #614. Itnegration ogDhcp. New endpoints
parent
cc1559ef08
commit
6d1a2a89ea
|
@ -29,7 +29,7 @@ resources:
|
||||||
class: ApiPlatform\Metadata\GetCollection
|
class: ApiPlatform\Metadata\GetCollection
|
||||||
method: GET
|
method: GET
|
||||||
input: false
|
input: false
|
||||||
uriTemplate: /subnets/server/get-collection
|
uriTemplate: /og-dhcp/server/get-collection
|
||||||
controller: App\Controller\OgDhcp\Subnet\GetCollectionAction
|
controller: App\Controller\OgDhcp\Subnet\GetCollectionAction
|
||||||
|
|
||||||
get:
|
get:
|
||||||
|
@ -38,7 +38,7 @@ resources:
|
||||||
class: ApiPlatform\Metadata\Get
|
class: ApiPlatform\Metadata\Get
|
||||||
method: GET
|
method: GET
|
||||||
input: false
|
input: false
|
||||||
uriTemplate: /subnets/server/{uuid}/get
|
uriTemplate: /og-dhcp/server/{uuid}/get
|
||||||
controller: App\Controller\OgDhcp\Subnet\GetAction
|
controller: App\Controller\OgDhcp\Subnet\GetAction
|
||||||
|
|
||||||
post:
|
post:
|
||||||
|
@ -47,16 +47,25 @@ resources:
|
||||||
class: ApiPlatform\Metadata\Post
|
class: ApiPlatform\Metadata\Post
|
||||||
method: POST
|
method: POST
|
||||||
input: false
|
input: false
|
||||||
uriTemplate: /subnets/server/{uuid}/post
|
uriTemplate: /og-dhcp/server/{uuid}/post
|
||||||
controller: App\Controller\OgDhcp\Subnet\PostAction
|
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:
|
delete:
|
||||||
shortName: Subnet Server
|
shortName: Subnet Server
|
||||||
description: Delete Subnet
|
description: Delete Subnet
|
||||||
class: ApiPlatform\Metadata\Get
|
class: ApiPlatform\Metadata\Delete
|
||||||
method: GET
|
method: DELETE
|
||||||
input: false
|
input: false
|
||||||
uriTemplate: /subnets/server/{uuid}/delete
|
uriTemplate: /og-dhcp/server/{uuid}/delete
|
||||||
controller: App\Controller\OgDhcp\Subnet\DeleteAction
|
controller: App\Controller\OgDhcp\Subnet\DeleteAction
|
||||||
|
|
||||||
add_host:
|
add_host:
|
||||||
|
@ -65,7 +74,7 @@ resources:
|
||||||
class: ApiPlatform\Metadata\Post
|
class: ApiPlatform\Metadata\Post
|
||||||
method: POST
|
method: POST
|
||||||
input: false
|
input: false
|
||||||
uriTemplate: /subnets/server/{uuid}/add-host
|
uriTemplate: /og-dhcp/server/{uuid}/add-host
|
||||||
controller: App\Controller\OgDhcp\Subnet\AddHostAction
|
controller: App\Controller\OgDhcp\Subnet\AddHostAction
|
||||||
|
|
||||||
get_hosts:
|
get_hosts:
|
||||||
|
@ -74,7 +83,7 @@ resources:
|
||||||
class: ApiPlatform\Metadata\GetCollection
|
class: ApiPlatform\Metadata\GetCollection
|
||||||
method: GET
|
method: GET
|
||||||
input: false
|
input: false
|
||||||
uriTemplate: /subnets/server/{uuid}/get-hosts
|
uriTemplate: /og-dhcp/server/{uuid}/get-hosts
|
||||||
controller: App\Controller\OgDhcp\Subnet\GetHostsAction
|
controller: App\Controller\OgDhcp\Subnet\GetHostsAction
|
||||||
|
|
||||||
put_host:
|
put_host:
|
||||||
|
@ -83,7 +92,7 @@ resources:
|
||||||
class: ApiPlatform\Metadata\Put
|
class: ApiPlatform\Metadata\Put
|
||||||
method: PUT
|
method: PUT
|
||||||
input: false
|
input: false
|
||||||
uriTemplate: /subnets/server/{uuid}/put-host
|
uriTemplate: /og-dhcp/server/{uuid}/put-host
|
||||||
controller: App\Controller\OgDhcp\Subnet\PutHostAction
|
controller: App\Controller\OgDhcp\Subnet\PutHostAction
|
||||||
|
|
||||||
delete_host:
|
delete_host:
|
||||||
|
@ -92,7 +101,7 @@ resources:
|
||||||
class: ApiPlatform\Metadata\Delete
|
class: ApiPlatform\Metadata\Delete
|
||||||
method: DELETE
|
method: DELETE
|
||||||
input: false
|
input: false
|
||||||
uriTemplate: /subnets/server/{uuid}/delete-host
|
uriTemplate: /og-dhcp/server/{uuid}/delete-host
|
||||||
controller: App\Controller\OgDhcp\Subnet\DeleteHostAction
|
controller: App\Controller\OgDhcp\Subnet\DeleteHostAction
|
||||||
|
|
||||||
properties:
|
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
|
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);
|
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,47 @@
|
||||||
|
|
||||||
namespace App\Controller\OgDhcp\Subnet;
|
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
|
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')]
|
#[Assert\NotBlank(message: 'validators.subnet.netmask.not_blank')]
|
||||||
#[Groups(['subnet:write'])]
|
#[Groups(['subnet:write'])]
|
||||||
#[ApiProperty(description: 'The netmask of the subnet', example: "")]
|
#[ApiProperty(description: 'The netmask of the subnet', example: "")]
|
||||||
|
@ -35,6 +40,7 @@ final class SubnetInput
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->name = $subnet->getName();
|
||||||
$this->netmask = $subnet->getNetmask();
|
$this->netmask = $subnet->getNetmask();
|
||||||
$this->ipAddress = $subnet->getIpAddress();
|
$this->ipAddress = $subnet->getIpAddress();
|
||||||
$this->nextServer = $subnet->getNextServer();
|
$this->nextServer = $subnet->getNextServer();
|
||||||
|
@ -47,6 +53,7 @@ final class SubnetInput
|
||||||
$subnet = new Subnet();
|
$subnet = new Subnet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$subnet->setName($this->name);
|
||||||
$subnet->setNetmask($this->netmask);
|
$subnet->setNetmask($this->netmask);
|
||||||
$subnet->setIpAddress($this->ipAddress);
|
$subnet->setIpAddress($this->ipAddress);
|
||||||
$subnet->setNextServer($this->nextServer);
|
$subnet->setNextServer($this->nextServer);
|
||||||
|
|
|
@ -10,6 +10,9 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
#[Get(shortName: 'Subnet')]
|
#[Get(shortName: 'Subnet')]
|
||||||
final class SubnetOutput extends AbstractOutput
|
final class SubnetOutput extends AbstractOutput
|
||||||
{
|
{
|
||||||
|
#[Groups(['subnet:read'])]
|
||||||
|
public string $name;
|
||||||
|
|
||||||
#[Groups(['subnet:read'])]
|
#[Groups(['subnet:read'])]
|
||||||
public string $netmask;
|
public string $netmask;
|
||||||
|
|
||||||
|
@ -32,6 +35,7 @@ final class SubnetOutput extends AbstractOutput
|
||||||
{
|
{
|
||||||
parent::__construct($subnet);
|
parent::__construct($subnet);
|
||||||
|
|
||||||
|
$this->name = $subnet->getName();
|
||||||
$this->netmask = $subnet->getNetmask();
|
$this->netmask = $subnet->getNetmask();
|
||||||
$this->ipAddress = $subnet->getIpAddress();
|
$this->ipAddress = $subnet->getIpAddress();
|
||||||
$this->nextServer = $subnet->getNextServer();
|
$this->nextServer = $subnet->getNextServer();
|
||||||
|
|
|
@ -8,6 +8,8 @@ use Doctrine\ORM\Mapping as ORM;
|
||||||
#[ORM\Entity(repositoryClass: SubnetRepository::class)]
|
#[ORM\Entity(repositoryClass: SubnetRepository::class)]
|
||||||
class Subnet extends AbstractEntity
|
class Subnet extends AbstractEntity
|
||||||
{
|
{
|
||||||
|
use NameableTrait;
|
||||||
|
|
||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
private ?string $netmask = null;
|
private ?string $netmask = null;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue