refs #614. Itnegration ogDhcp

feature/integration-dhcp
Manuel Aranda Rosales 2024-08-27 10:55:32 +02:00
parent f88bb46f3e
commit 31b78736f2
6 changed files with 88 additions and 22 deletions

View File

@ -59,6 +59,42 @@ resources:
uriTemplate: /subnets/server/{uuid}/delete
controller: App\Controller\OgDhcp\Subnet\DeleteAction
add_host:
shortName: Subnet Server Hosts
description: Add Host to Subnet
class: ApiPlatform\Metadata\Post
method: POST
input: false
uriTemplate: /subnets/server/{uuid}/add-host
controller: App\Controller\OgDhcp\Subnet\AddHostAction
get_hosts:
shortName: Subnet Server Hosts
description: Get Hosts of Subnet
class: ApiPlatform\Metadata\GetCollection
method: GET
input: false
uriTemplate: /subnets/server/{uuid}/get-hosts
controller: App\Controller\OgDhcp\Subnet\GetHostsAction
put_host:
shortName: Subnet Server Hosts
description: Put Host of Subnet
class: ApiPlatform\Metadata\Put
method: PUT
input: false
uriTemplate: /subnets/server/{uuid}/put-host
controller: App\Controller\OgDhcp\Subnet\PutHostAction
delete_host:
shortName: Subnet Server Hosts
description: Delete Host of Subnet
class: ApiPlatform\Metadata\Delete
method: DELETE
input: false
uriTemplate: /subnets/server/{uuid}/delete-host
controller: App\Controller\OgDhcp\Subnet\DeleteHostAction
properties:
App\Entity\Subnet:
id:

View File

@ -2,7 +2,10 @@
namespace App\Controller\OgDhcp\Subnet;
class DeleteHostAction
{
use App\Controller\OgDhcp\AbstractOgDhcpController;
use Symfony\Component\HttpKernel\Attribute\AsController;
#[AsController]
class DeleteHostAction extends AbstractOgDhcpController{
}

View File

@ -1,12 +0,0 @@
<?php
namespace App\Controller\OgDhcp\Subnet;
use App\Controller\OgDhcp\AbstractOgDhcpController;
use Symfony\Component\HttpKernel\Attribute\AsController;
#[AsController]
class GetHostAction extends AbstractOgDhcpController
{
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\Controller\OgDhcp\Subnet;
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 GetHostsAction extends AbstractOgDhcpController
{
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function __invoke(Subnet $data, HttpClientInterface $httpClient): JsonResponse
{
if (!$data->getId()) {
throw new ValidatorException('Checksum is required');
}
$content = $this->createRequest($httpClient, 'GET', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getId());
return new JsonResponse(data: $content, status: Response::HTTP_OK);
}
}

View File

@ -25,17 +25,17 @@ class PostAction extends AbstractOgDhcpController
*/
public function __invoke(Subnet $data, HttpClientInterface $httpClient): JsonResponse
{
if (!$data) {
throw new ValidatorException('Data URL is required');
}
$params = [
'json' => [
'url' => ''
'subnetId' => $data->getId(),
'mask' => $data->getNetmask(),
'address' => $data->getIpAddress(),
'nextServer' => $data->getNextServer(),
'bootFileName' => $data->getBootFileName(),
]
];
$content = $this->createRequest($httpClient, 'POST', $this->ogDhcpApiUrl.'/opengnsys3/rest/subnets', $params);
$content = $this->createRequest($httpClient, 'POST', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets', $params);
$this->entityManager->persist($data);
$this->entityManager->flush();

View File

@ -2,7 +2,10 @@
namespace App\Controller\OgDhcp\Subnet;
class PutHostAction
{
use App\Controller\OgDhcp\AbstractOgDhcpController;
use Symfony\Component\HttpKernel\Attribute\AsController;
#[AsController]
class PutHostAction extends AbstractOgDhcpController{
}