refs #2972. Integration remove leases ogDhcp
testing/ogcore-api/pipeline/head There was a failure building this commit
Details
testing/ogcore-api/pipeline/head There was a failure building this commit
Details
parent
08ed3aa4e7
commit
0e23464524
|
|
@ -121,6 +121,13 @@ resources:
|
|||
uriTemplate: /clients/{uuid}/get-partition-script-data
|
||||
controller: App\Controller\OgAgent\GetPartitionScriptDataAction
|
||||
|
||||
delete_client_lease:
|
||||
class: ApiPlatform\Metadata\Delete
|
||||
method: DELETE
|
||||
input: false
|
||||
uriTemplate: /clients/{uuid}/delete-lease
|
||||
controller: App\Controller\OgDhcp\Client\DeleteClientLeaseAction
|
||||
|
||||
|
||||
properties:
|
||||
App\Entity\Client:
|
||||
|
|
|
|||
|
|
@ -97,6 +97,25 @@ resources:
|
|||
uriTemplate: /og-dhcp/server/{uuid}/delete-host/{clientUuid}
|
||||
controller: App\Controller\OgDhcp\Subnet\DeleteHostAction
|
||||
|
||||
delete_subnet_leases:
|
||||
shortName: Subnet Server Leases
|
||||
description: Delete all leases of a Subnet
|
||||
class: ApiPlatform\Metadata\Delete
|
||||
method: DELETE
|
||||
input: false
|
||||
uriTemplate: /og-dhcp/server/{uuid}/delete-leases
|
||||
controller: App\Controller\OgDhcp\Subnet\DeleteSubnetLeasesAction
|
||||
|
||||
delete_client_lease:
|
||||
shortName: Subnet Server Leases
|
||||
description: Delete lease of a specific client
|
||||
class: ApiPlatform\Metadata\Delete
|
||||
method: DELETE
|
||||
input: false
|
||||
read: false
|
||||
uriTemplate: /og-dhcp/server/{uuid}/delete-lease/{clientUuid}
|
||||
controller: App\Controller\OgDhcp\Subnet\DeleteClientLeaseAction
|
||||
|
||||
|
||||
properties:
|
||||
App\Entity\Subnet:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\OgDhcp\Client;
|
||||
|
||||
use App\Controller\OgDhcp\AbstractOgDhcpController;
|
||||
use App\Entity\Client;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
|
||||
#[AsController]
|
||||
class DeleteClientLeaseAction extends AbstractOgDhcpController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(Client $data): JsonResponse
|
||||
{
|
||||
if (!$data->getIp()) {
|
||||
throw new BadRequestHttpException('Client has no IP address assigned');
|
||||
}
|
||||
|
||||
$subnet = $data->getSubnet();
|
||||
if (!$subnet) {
|
||||
throw new BadRequestHttpException('Client has no subnet associated');
|
||||
}
|
||||
|
||||
$dhcpServer = $subnet->getDhcpServer();
|
||||
if (!$dhcpServer) {
|
||||
throw new BadRequestHttpException('Subnet has no DHCP server associated');
|
||||
}
|
||||
|
||||
$port = $dhcpServer->getApiPort() ?? 8081;
|
||||
$url = sprintf('http://%s:%d/ogdhcp/v1/leases/%s', $dhcpServer->getIp(), $port, $data->getIp());
|
||||
|
||||
$content = $this->createRequest('DELETE', $url);
|
||||
|
||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\OgDhcp\Subnet;
|
||||
|
||||
use App\Controller\OgDhcp\AbstractOgDhcpController;
|
||||
use App\Entity\Client;
|
||||
use App\Entity\Subnet;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
|
||||
#[AsController]
|
||||
class DeleteClientLeaseAction extends AbstractOgDhcpController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(Subnet $data, string $clientUuid): JsonResponse
|
||||
{
|
||||
$client = $this->entityManager->getRepository(Client::class)->findOneBy(['uuid' => $clientUuid]);
|
||||
|
||||
if (!$client) {
|
||||
throw new BadRequestHttpException('Client not found');
|
||||
}
|
||||
|
||||
if (!$client->getIp()) {
|
||||
throw new BadRequestHttpException('Client has no IP address assigned');
|
||||
}
|
||||
|
||||
$dhcpServer = $data->getDhcpServer();
|
||||
if (!$dhcpServer) {
|
||||
throw new BadRequestHttpException('Subnet has no DHCP server associated');
|
||||
}
|
||||
|
||||
$port = $dhcpServer->getApiPort() ?? 8081;
|
||||
$url = sprintf('http://%s:%d/ogdhcp/v1/leases/%s', $dhcpServer->getIp(), $port, $client->getIp());
|
||||
|
||||
$content = $this->createRequest('DELETE', $url);
|
||||
|
||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<?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\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
|
||||
#[AsController]
|
||||
class DeleteSubnetLeasesAction extends AbstractOgDhcpController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(Subnet $data): JsonResponse
|
||||
{
|
||||
if (!$data->getServerId()) {
|
||||
throw new BadRequestHttpException('Subnet has no serverId assigned in DHCP server');
|
||||
}
|
||||
|
||||
$dhcpServer = $data->getDhcpServer();
|
||||
if (!$dhcpServer) {
|
||||
throw new BadRequestHttpException('Subnet has no DHCP server associated');
|
||||
}
|
||||
|
||||
$port = $dhcpServer->getApiPort() ?? 8081;
|
||||
$url = sprintf('http://%s:%d/ogdhcp/v1/subnets/%d/leases', $dhcpServer->getIp(), $port, $data->getServerId());
|
||||
|
||||
$content = $this->createRequest('DELETE', $url);
|
||||
|
||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue