From 31b78736f2b757771715c34006194179cfe28b09 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 27 Aug 2024 10:55:32 +0200 Subject: [PATCH] refs #614. Itnegration ogDhcp --- config/api_platform/Subnet.yaml | 36 +++++++++++++++++++ .../OgDhcp/Subnet/DeleteHostAction.php | 7 ++-- .../OgDhcp/Subnet/GetHostAction.php | 12 ------- .../OgDhcp/Subnet/GetHostsAction.php | 36 +++++++++++++++++++ src/Controller/OgDhcp/Subnet/PostAction.php | 12 +++---- .../OgDhcp/Subnet/PutHostAction.php | 7 ++-- 6 files changed, 88 insertions(+), 22 deletions(-) delete mode 100644 src/Controller/OgDhcp/Subnet/GetHostAction.php create mode 100644 src/Controller/OgDhcp/Subnet/GetHostsAction.php diff --git a/config/api_platform/Subnet.yaml b/config/api_platform/Subnet.yaml index c9bd475..b240585 100644 --- a/config/api_platform/Subnet.yaml +++ b/config/api_platform/Subnet.yaml @@ -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: diff --git a/src/Controller/OgDhcp/Subnet/DeleteHostAction.php b/src/Controller/OgDhcp/Subnet/DeleteHostAction.php index 95a3f1d..57aac51 100644 --- a/src/Controller/OgDhcp/Subnet/DeleteHostAction.php +++ b/src/Controller/OgDhcp/Subnet/DeleteHostAction.php @@ -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{ } \ No newline at end of file diff --git a/src/Controller/OgDhcp/Subnet/GetHostAction.php b/src/Controller/OgDhcp/Subnet/GetHostAction.php deleted file mode 100644 index 1211d8a..0000000 --- a/src/Controller/OgDhcp/Subnet/GetHostAction.php +++ /dev/null @@ -1,12 +0,0 @@ -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); + } +} \ No newline at end of file diff --git a/src/Controller/OgDhcp/Subnet/PostAction.php b/src/Controller/OgDhcp/Subnet/PostAction.php index 2f16f5d..67f00eb 100644 --- a/src/Controller/OgDhcp/Subnet/PostAction.php +++ b/src/Controller/OgDhcp/Subnet/PostAction.php @@ -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(); diff --git a/src/Controller/OgDhcp/Subnet/PutHostAction.php b/src/Controller/OgDhcp/Subnet/PutHostAction.php index a5f540e..91146e9 100644 --- a/src/Controller/OgDhcp/Subnet/PutHostAction.php +++ b/src/Controller/OgDhcp/Subnet/PutHostAction.php @@ -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{ } \ No newline at end of file