refs #614. Itnegration ogDhcp. Change some params
parent
6d1a2a89ea
commit
a232d5cbd7
|
@ -23,7 +23,7 @@ resources:
|
|||
ApiPlatform\Metadata\Post: ~
|
||||
ApiPlatform\Metadata\Delete: ~
|
||||
|
||||
get_collection:
|
||||
get_collection_templates:
|
||||
shortName: PxeTemplate Server
|
||||
description: Get collection of PxeTemplate
|
||||
class: ApiPlatform\Metadata\GetCollection
|
||||
|
@ -32,7 +32,7 @@ resources:
|
|||
uriTemplate: /pxe-templates/server/get-collection
|
||||
controller: App\Controller\OgBoot\PxeTemplate\GetCollectionAction
|
||||
|
||||
get:
|
||||
get_template:
|
||||
shortName: PxeTemplate Server
|
||||
description: Get PxeTemplate
|
||||
class: ApiPlatform\Metadata\Get
|
||||
|
@ -41,7 +41,7 @@ resources:
|
|||
uriTemplate: /pxe-templates/server/{uuid}/get
|
||||
controller: App\Controller\OgBoot\PxeTemplate\GetAction
|
||||
|
||||
post:
|
||||
post_template:
|
||||
shortName: PxeTemplate Server
|
||||
description: Create PxeTemplate
|
||||
class: ApiPlatform\Metadata\Post
|
||||
|
@ -50,7 +50,7 @@ resources:
|
|||
uriTemplate: /pxe-templates/server/{uuid}/post
|
||||
controller: App\Controller\OgBoot\PxeTemplate\PostAction
|
||||
|
||||
delete:
|
||||
delete_template:
|
||||
shortName: PxeTemplate Server
|
||||
description: Delete PxeTemplate
|
||||
class: ApiPlatform\Metadata\Get
|
||||
|
|
|
@ -23,7 +23,7 @@ resources:
|
|||
ApiPlatform\Metadata\Post: ~
|
||||
ApiPlatform\Metadata\Delete: ~
|
||||
|
||||
get_collection:
|
||||
get_collection_subnets:
|
||||
shortName: Subnet Server
|
||||
description: Get collection of Subnet
|
||||
class: ApiPlatform\Metadata\GetCollection
|
||||
|
@ -32,7 +32,7 @@ resources:
|
|||
uriTemplate: /og-dhcp/server/get-collection
|
||||
controller: App\Controller\OgDhcp\Subnet\GetCollectionAction
|
||||
|
||||
get:
|
||||
get_subnet:
|
||||
shortName: Subnet Server
|
||||
description: Get Subnet
|
||||
class: ApiPlatform\Metadata\Get
|
||||
|
@ -41,7 +41,7 @@ resources:
|
|||
uriTemplate: /og-dhcp/server/{uuid}/get
|
||||
controller: App\Controller\OgDhcp\Subnet\GetAction
|
||||
|
||||
post:
|
||||
post_subnet:
|
||||
shortName: Subnet Server
|
||||
description: Create Subnet
|
||||
class: ApiPlatform\Metadata\Post
|
||||
|
@ -50,7 +50,7 @@ resources:
|
|||
uriTemplate: /og-dhcp/server/{uuid}/post
|
||||
controller: App\Controller\OgDhcp\Subnet\PostAction
|
||||
|
||||
put:
|
||||
put_subnet:
|
||||
shortName: Subnet Server
|
||||
description: Create Subnet
|
||||
class: ApiPlatform\Metadata\Put
|
||||
|
@ -59,7 +59,7 @@ resources:
|
|||
uriTemplate: /og-dhcp/server/{uuid}/put
|
||||
controller: App\Controller\OgDhcp\Subnet\PutAction
|
||||
|
||||
delete:
|
||||
delete_subnet:
|
||||
shortName: Subnet Server
|
||||
description: Delete Subnet
|
||||
class: ApiPlatform\Metadata\Delete
|
||||
|
@ -68,14 +68,14 @@ resources:
|
|||
uriTemplate: /og-dhcp/server/{uuid}/delete
|
||||
controller: App\Controller\OgDhcp\Subnet\DeleteAction
|
||||
|
||||
add_host:
|
||||
post_host:
|
||||
shortName: Subnet Server Hosts
|
||||
description: Add Host to Subnet
|
||||
description: Post Host to Subnet
|
||||
class: ApiPlatform\Metadata\Post
|
||||
method: POST
|
||||
input: false
|
||||
uriTemplate: /og-dhcp/server/{uuid}/add-host
|
||||
controller: App\Controller\OgDhcp\Subnet\AddHostAction
|
||||
input: App\Dto\Input\SubnetAddHostInput
|
||||
uriTemplate: /og-dhcp/server/{uuid}/post-host
|
||||
controller: App\Controller\OgDhcp\Subnet\PostHostAction
|
||||
|
||||
get_hosts:
|
||||
shortName: Subnet Server Hosts
|
||||
|
|
|
@ -25,11 +25,11 @@ class DeleteAction extends AbstractOgDhcpController
|
|||
*/
|
||||
public function __invoke(Subnet $data, HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
if (!$data->getChecksum()) {
|
||||
throw new ValidatorException('Checksum is required');
|
||||
if (!$data->getId()) {
|
||||
throw new ValidatorException('Data Id is required');
|
||||
}
|
||||
|
||||
$content = $this->createRequest($httpClient, 'DELETE', $this->ogDhcpApiUrl.'/opengnsys3/rest/dhcp/subnets/'.$data->getChecksum());
|
||||
$content = $this->createRequest($httpClient, 'DELETE', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getId());
|
||||
|
||||
$this->entityManager->remove($data);
|
||||
$this->entityManager->flush();
|
||||
|
|
|
@ -3,9 +3,43 @@
|
|||
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 DeleteHostAction extends AbstractOgDhcpController{
|
||||
class DeleteHostAction extends AbstractOgDhcpController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(Subnet $data, HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
if (!$data->getId()) {
|
||||
throw new ValidatorException('Data URL is required');
|
||||
}
|
||||
|
||||
$params = [
|
||||
'json' => [
|
||||
'host' => '',
|
||||
]
|
||||
];
|
||||
|
||||
$content = $this->createRequest($httpClient, 'POST', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getId().'/hosts', $params);
|
||||
|
||||
$this->entityManager->persist($data);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -29,7 +29,7 @@ class GetHostsAction extends AbstractOgDhcpController
|
|||
throw new ValidatorException('Checksum is required');
|
||||
}
|
||||
|
||||
$content = $this->createRequest($httpClient, 'GET', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getId());
|
||||
$content = $this->createRequest($httpClient, 'GET', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getId().'/hosts');
|
||||
|
||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class PostAction extends AbstractOgDhcpController
|
|||
]
|
||||
];
|
||||
|
||||
$content = $this->createRequest($httpClient, 'POST', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets', $params);
|
||||
$content = $this->createRequest($httpClient, 'POST', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets' , $params);
|
||||
|
||||
$this->entityManager->persist($data);
|
||||
$this->entityManager->flush();
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Controller\OgDhcp\Subnet;
|
||||
|
||||
use App\Controller\OgDhcp\AbstractOgDhcpController;
|
||||
use App\Dto\Input\SubnetAddHostInput;
|
||||
use App\Entity\Client;
|
||||
use App\Entity\Subnet;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
@ -15,7 +17,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
#[AsController]
|
||||
class AddHostAction extends AbstractOgDhcpController
|
||||
class PostHostAction extends AbstractOgDhcpController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
|
@ -23,26 +25,26 @@ class AddHostAction extends AbstractOgDhcpController
|
|||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(Subnet $data, HttpClientInterface $httpClient): JsonResponse
|
||||
public function __invoke(SubnetAddHostInput $input, HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
if (!$data) {
|
||||
throw new ValidatorException('Data URL is required');
|
||||
$subnet = $input->subnet->getEntity();
|
||||
$clients = $input->clients;
|
||||
|
||||
/** @var Client $client */
|
||||
foreach ($clients as $client) {
|
||||
$data = [
|
||||
'host' => $client->getName(),
|
||||
'macAddress' => $client->getMac(),
|
||||
'address' => $client->getIp(),
|
||||
];
|
||||
|
||||
$params = [
|
||||
'json' => $data
|
||||
];
|
||||
|
||||
$content = $this->createRequest($httpClient, 'POST', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$subnet->getId().'/hosts', $params);
|
||||
}
|
||||
|
||||
$params = [
|
||||
'json' => [
|
||||
'host' => '',
|
||||
'macAddress' => '',
|
||||
'address' => '',
|
||||
'nextServer' => '',
|
||||
]
|
||||
];
|
||||
|
||||
$content = $this->createRequest($httpClient, 'POST', $this->ogDhcpApiUrl.'/opengnsys3/rest/subnets/'.$data->getId().'/hosts', $params);
|
||||
|
||||
$this->entityManager->persist($data);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||
return new JsonResponse(status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -3,9 +3,47 @@
|
|||
namespace App\Controller\OgDhcp\Subnet;
|
||||
|
||||
use App\Controller\OgDhcp\AbstractOgDhcpController;
|
||||
use App\Dto\Input\SubnetAddHostInput;
|
||||
use App\Entity\Client;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
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 PutHostAction extends AbstractOgDhcpController{
|
||||
class PutHostAction extends AbstractOgDhcpController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(SubnetAddHostInput $input, HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
$subnet = $input->subnet->getEntity();
|
||||
$clients = $input->clients;
|
||||
|
||||
/** @var Client $client */
|
||||
foreach ($clients as $client) {
|
||||
$data = [
|
||||
'host' => $client->getName(),
|
||||
'oldMacAddress' => '',
|
||||
'macAddress' => '',
|
||||
'address' => '',
|
||||
];
|
||||
|
||||
$params = [
|
||||
'json' => $data
|
||||
];
|
||||
|
||||
$content = $this->createRequest($httpClient, 'PUT', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$subnet->getId().'/hosts', $params);
|
||||
}
|
||||
|
||||
return new JsonResponse(status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Dto\Input;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use App\Dto\Output\ClientOutput;
|
||||
use App\Dto\Output\PxeTemplateOutput;
|
||||
use App\Dto\Output\SubnetOutput;
|
||||
use App\Entity\PxeBootFile;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
final class SubnetAddHostInput
|
||||
{
|
||||
#[Assert\NotNull(message: 'validators.subnet_add_host.subnet.not_null')]
|
||||
#[Groups(['subnet:write'])]
|
||||
#[ApiProperty(description: 'The subnet of the pxeBootFile', example: "Subnet 1")]
|
||||
public ?SubnetOutput $subnet = null;
|
||||
|
||||
/**
|
||||
* @var ClientOutput[]
|
||||
*/
|
||||
#[Groups(['subnet:write'])]
|
||||
#[ApiProperty(description: 'The clients of the subnet', readableLink: false, writableLink: false, example: "Client 1")]
|
||||
public array $clients = [];
|
||||
}
|
Loading…
Reference in New Issue