refs #2084. New env to ogBoot
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
a3f271a9ae
commit
76a90d1129
5
env.json
5
env.json
|
@ -8,6 +8,9 @@
|
||||||
"UDS_AUTH_USERNAME": "test",
|
"UDS_AUTH_USERNAME": "test",
|
||||||
"UDS_AUTH_PASSWORD": "test",
|
"UDS_AUTH_PASSWORD": "test",
|
||||||
"UDS_URL": "https:\/\/localhost:8087\/uds\/rest\/",
|
"UDS_URL": "https:\/\/localhost:8087\/uds\/rest\/",
|
||||||
"SSL_ENABLED": "true"
|
"SSL_ENABLED": "true",
|
||||||
|
"OG_BOOT_IP": "127.0.0.1",
|
||||||
|
"OG_BOOT_API_PORT": "8082",
|
||||||
|
"OG_BOOT_PXE_PORT": "8085"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ use App\Service\Trace\CreateService;
|
||||||
use App\Service\Utils\ExtractOgLiveFilenameDateService;
|
use App\Service\Utils\ExtractOgLiveFilenameDateService;
|
||||||
use App\Service\Utils\SimplifyOgLiveFilenameService;
|
use App\Service\Utils\SimplifyOgLiveFilenameService;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
@ -25,8 +26,12 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
abstract class AbstractOgBootController extends AbstractController
|
abstract class AbstractOgBootController extends AbstractController
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
#[Autowire(env: 'OG_BOOT_API_URL')]
|
#[Autowire(env: 'OG_BOOT_IP')]
|
||||||
protected string $ogBootApiUrl,
|
protected string $ogBootIp,
|
||||||
|
#[Autowire(env: 'OG_BOOT_PXE_PORT')]
|
||||||
|
protected string $ogBootPxePort,
|
||||||
|
#[Autowire(env: 'OG_BOOT_API_PORT')]
|
||||||
|
protected string $ogBootApiPort,
|
||||||
#[Autowire(env: 'OG_CORE_IP')]
|
#[Autowire(env: 'OG_CORE_IP')]
|
||||||
protected string $ogCoreIP,
|
protected string $ogCoreIP,
|
||||||
#[Autowire(env: 'OG_LOG_IP')]
|
#[Autowire(env: 'OG_LOG_IP')]
|
||||||
|
@ -36,6 +41,8 @@ abstract class AbstractOgBootController extends AbstractController
|
||||||
protected readonly CreateService $createService,
|
protected readonly CreateService $createService,
|
||||||
protected readonly SimplifyOgLiveFilenameService $simplifyOgLiveFilenameService,
|
protected readonly SimplifyOgLiveFilenameService $simplifyOgLiveFilenameService,
|
||||||
protected readonly ExtractOgLiveFilenameDateService $extractOgLiveFilenameDateService,
|
protected readonly ExtractOgLiveFilenameDateService $extractOgLiveFilenameDateService,
|
||||||
|
protected readonly LoggerInterface $logger,
|
||||||
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -56,15 +63,25 @@ abstract class AbstractOgBootController extends AbstractController
|
||||||
]);
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $this->httpClient->request($method, $url, $params);
|
$response = $this->httpClient->request($method, 'http://'.$this->ogBootIp.':'.$this->ogBootApiPort.$url, $params);
|
||||||
|
|
||||||
return json_decode($response->getContent(), true);
|
return json_decode($response->getContent(), true);
|
||||||
} catch (ClientExceptionInterface | ServerExceptionInterface $e) {
|
} catch (ClientExceptionInterface | ServerExceptionInterface $e) {
|
||||||
$response = $e->getResponse();
|
$this->logger->error(sprintf('Client/Server error in request to %s: %s', $url, $e->getMessage()));
|
||||||
$content = json_decode($response->getContent(false), true);
|
|
||||||
throw new HttpException($response->getStatusCode(), $content['error'] ?? 'An error occurred');
|
return [
|
||||||
|
'code' => Response::HTTP_INTERNAL_SERVER_ERROR,
|
||||||
|
'error' => 'Client/Server error',
|
||||||
|
'details' => $e->getMessage(),
|
||||||
|
];
|
||||||
} catch (TransportExceptionInterface $e) {
|
} catch (TransportExceptionInterface $e) {
|
||||||
throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, $e->getMessage());
|
$this->logger->error(sprintf('Transport error in request to %s: %s', $url, $e->getMessage()));
|
||||||
|
|
||||||
|
return [
|
||||||
|
'code' => Response::HTTP_INTERNAL_SERVER_ERROR,
|
||||||
|
'error' => 'Transport error',
|
||||||
|
'details' => $e->getMessage(),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,11 @@ class GetAction extends AbstractOgBootController
|
||||||
throw new ValidatorException('Checksum is required');
|
throw new ValidatorException('Checksum is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum());
|
$content = $this->createRequest('GET', '/ogboot/v1/oglives/'.$data->getChecksum());
|
||||||
|
|
||||||
|
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||||
|
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||||
|
}
|
||||||
|
|
||||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,11 @@ class GetCollectionAction extends AbstractOgBootController
|
||||||
*/
|
*/
|
||||||
public function __invoke(): JsonResponse
|
public function __invoke(): JsonResponse
|
||||||
{
|
{
|
||||||
$content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives');
|
$content = $this->createRequest('GET', '/ogboot/v1/oglives');
|
||||||
|
|
||||||
|
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||||
|
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||||
|
}
|
||||||
|
|
||||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use App\Controller\OgBoot\AbstractOgBootController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||||
|
@ -22,7 +23,11 @@ class GetDefaultAction extends AbstractOgBootController
|
||||||
*/
|
*/
|
||||||
public function __invoke(): JsonResponse
|
public function __invoke(): JsonResponse
|
||||||
{
|
{
|
||||||
$content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/default');
|
$content = $this->createRequest('GET', '/ogboot/v1/oglives/default');
|
||||||
|
|
||||||
|
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||||
|
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||||
|
}
|
||||||
|
|
||||||
return new JsonResponse(status: Response::HTTP_OK);
|
return new JsonResponse(status: Response::HTTP_OK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ class GetIsosAction extends AbstractOgBootController
|
||||||
*/
|
*/
|
||||||
public function __invoke(): JsonResponse
|
public function __invoke(): JsonResponse
|
||||||
{
|
{
|
||||||
$content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/isos');
|
$content = $this->createRequest('GET', '/ogboot/v1/oglives/isos');
|
||||||
|
|
||||||
if (!isset($content['message']) || !is_array($content['message'])) {
|
if (!isset($content['message']) || !is_array($content['message'])) {
|
||||||
return new JsonResponse(data: ['error' => 'Invalid response'], status: Response::HTTP_BAD_REQUEST);
|
return new JsonResponse(data: ['error' => 'Invalid response'], status: Response::HTTP_BAD_REQUEST);
|
||||||
|
|
|
@ -45,7 +45,11 @@ class InstallAction extends AbstractOgBootController
|
||||||
'uuid' => 'InstallOgLive_'.$data->getUuid()
|
'uuid' => 'InstallOgLive_'.$data->getUuid()
|
||||||
];
|
];
|
||||||
|
|
||||||
$content = $this->createRequest('POST', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/install', $params);
|
$content = $this->createRequest('POST', '/ogboot/v1/oglives/install', $params);
|
||||||
|
|
||||||
|
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||||
|
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||||
|
}
|
||||||
|
|
||||||
$this->createService->__invoke(null, CommandTypes::INSTALL_OGLIVE, TraceStatus::IN_PROGRESS, 'InstallOgLive_'.$data->getUuid(), $inputData);
|
$this->createService->__invoke(null, CommandTypes::INSTALL_OGLIVE, TraceStatus::IN_PROGRESS, 'InstallOgLive_'.$data->getUuid(), $inputData);
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,11 @@ class SetDefaultAction extends AbstractOgBootController
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
$content = $this->createRequest('PUT', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/default', $params);
|
$content = $this->createRequest('PUT', '/ogboot/v1/oglives/default', $params);
|
||||||
|
|
||||||
|
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||||
|
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||||
|
}
|
||||||
|
|
||||||
$oldDefaultOgLive = $this->entityManager->getRepository(OgLive::class)->findBy(['isDefault' => true]);
|
$oldDefaultOgLive = $this->entityManager->getRepository(OgLive::class)->findBy(['isDefault' => true]);
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,11 @@ class SyncAction extends AbstractOgBootController
|
||||||
*/
|
*/
|
||||||
public function __invoke(): JsonResponse
|
public function __invoke(): JsonResponse
|
||||||
{
|
{
|
||||||
$content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl . '/ogboot/v1/oglives');
|
$content = $this->createRequest('GET', '/ogboot/v1/oglives');
|
||||||
|
|
||||||
|
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||||
|
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||||
|
}
|
||||||
|
|
||||||
$allOgLives = $this->entityManager->getRepository(OgLive::class)->findAll();
|
$allOgLives = $this->entityManager->getRepository(OgLive::class)->findAll();
|
||||||
$apiChecksums = array_map(fn($ogLive) => $ogLive['id'], $content['message']['installed_ogLives']);
|
$apiChecksums = array_map(fn($ogLive) => $ogLive['id'], $content['message']['installed_ogLives']);
|
||||||
|
|
|
@ -31,7 +31,11 @@ class UninstallAction extends AbstractOgBootController
|
||||||
throw new ValidatorException('Checksum is required');
|
throw new ValidatorException('Checksum is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = $this->createRequest( 'DELETE', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum());
|
$content = $this->createRequest( 'DELETE', '/ogboot/v1/oglives/'.$data->getChecksum());
|
||||||
|
|
||||||
|
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||||
|
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||||
|
}
|
||||||
|
|
||||||
$this->entityManager->remove($data);
|
$this->entityManager->remove($data);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
|
|
@ -23,13 +23,9 @@ class DeleteAction extends AbstractOgBootController
|
||||||
*/
|
*/
|
||||||
public function __invoke(string $mac): JsonResponse
|
public function __invoke(string $mac): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
$response = $this->createRequest('DELETE', '/ogboot/v1/pxes/'.$mac);
|
||||||
$response = $this->httpClient->request('DELETE', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxes/'.$mac, [
|
|
||||||
'headers' => [
|
if ($response->getStatusCode() !== Response::HTTP_OK) {
|
||||||
'accept' => 'application/json',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
} catch (TransportExceptionInterface $e) {
|
|
||||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,13 +26,9 @@ class GetAction extends AbstractOgBootController
|
||||||
*/
|
*/
|
||||||
public function __invoke(Client $client): JsonResponse
|
public function __invoke(Client $client): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
$response = $this->createRequest('GET', '/ogboot/v1/pxes/'.$client->getName());
|
||||||
$response = $this->httpClient->request('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxes/'.$client->getMac(), [
|
|
||||||
'headers' => [
|
if ($response->getStatusCode() !== Response::HTTP_OK) {
|
||||||
'accept' => 'application/json',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
} catch (TransportExceptionInterface $e) {
|
|
||||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ class GetCollectionAction extends AbstractOgBootController
|
||||||
*/
|
*/
|
||||||
public function __invoke(HttpClientInterface $httpClient): JsonResponse
|
public function __invoke(HttpClientInterface $httpClient): JsonResponse
|
||||||
{
|
{
|
||||||
$content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxes');
|
$content = $this->createRequest('GET', '/ogboot/v1/pxes');
|
||||||
|
|
||||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ class PostAction extends AbstractOgBootController
|
||||||
*/
|
*/
|
||||||
public function __invoke(Client $client, PxeTemplate $pxeTemplate): JsonResponse
|
public function __invoke(Client $client, PxeTemplate $pxeTemplate): JsonResponse
|
||||||
{
|
{
|
||||||
$ogRepoIp = $this->ogBootApiUrl;
|
$ogRepoIp = $this->ogBootIp;
|
||||||
|
|
||||||
$ogRepoIp = $client->getRepository()?->getIp()
|
$ogRepoIp = $client->getRepository()?->getIp()
|
||||||
?? $client->getOrganizationalUnit()?->getNetworkSettings()?->getRepository()?->getIp();
|
?? $client->getOrganizationalUnit()?->getNetworkSettings()?->getRepository()?->getIp();
|
||||||
|
@ -42,7 +42,9 @@ class PostAction extends AbstractOgBootController
|
||||||
'mac' => strtolower($client->getMac()),
|
'mac' => strtolower($client->getMac()),
|
||||||
'lang' => 'es_ES.UTF-8',
|
'lang' => 'es_ES.UTF-8',
|
||||||
'ip' => $client->getIp(),
|
'ip' => $client->getIp(),
|
||||||
'server_ip' => $this->ogBootApiUrl,
|
'server_ip' => $this->ogBootIp,
|
||||||
|
'server_api_port' => $this->ogBootApiPort,
|
||||||
|
'server_pxe_port' => $this->ogBootPxePort,
|
||||||
'router' => $client->getOrganizationalUnit()->getNetworkSettings()->getRouter(),
|
'router' => $client->getOrganizationalUnit()->getNetworkSettings()->getRouter(),
|
||||||
'netmask' => $client->getOrganizationalUnit()->getNetworkSettings() ? $client->getOrganizationalUnit()->getNetworkSettings()->getNetmask() : '255.255.255.0',
|
'netmask' => $client->getOrganizationalUnit()->getNetworkSettings() ? $client->getOrganizationalUnit()->getNetworkSettings()->getNetmask() : '255.255.255.0',
|
||||||
'computer_name' => $client->getName(),
|
'computer_name' => $client->getName(),
|
||||||
|
@ -50,10 +52,10 @@ class PostAction extends AbstractOgBootController
|
||||||
'group' => $client->getOrganizationalUnit()->getName(),
|
'group' => $client->getOrganizationalUnit()->getName(),
|
||||||
'ogrepo' => $ogRepoIp,
|
'ogrepo' => $ogRepoIp,
|
||||||
'ogcore' => $this->ogCoreIP,
|
'ogcore' => $this->ogCoreIP,
|
||||||
'oglive' => $this->ogBootApiUrl,
|
'oglive' => $this->ogBootIp,
|
||||||
'oglog' => $this->ogLogIp,
|
'oglog' => $this->ogLogIp,
|
||||||
'ogshare' => $client->getOrganizationalUnit()->getNetworkSettings()?->getOgShare()
|
'ogshare' => $client->getOrganizationalUnit()->getNetworkSettings()?->getOgShare()
|
||||||
? $client->getOrganizationalUnit()->getNetworkSettings()?->getOgShare(): $this->ogBootApiUrl,
|
? $client->getOrganizationalUnit()->getNetworkSettings()?->getOgShare(): $this->ogBootIp,
|
||||||
'oglivedir' => $ogLive,
|
'oglivedir' => $ogLive,
|
||||||
'ogprof' => 'false',
|
'ogprof' => 'false',
|
||||||
'hardprofile' => $client->getHardwareProfile() ? $client->getHardwareProfile()->getDescription() : 'default',
|
'hardprofile' => $client->getHardwareProfile() ? $client->getHardwareProfile()->getDescription() : 'default',
|
||||||
|
@ -64,7 +66,7 @@ class PostAction extends AbstractOgBootController
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
$content = $this->createRequest('POST', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxes', $params);
|
$content = $this->createRequest('POST', '/ogboot/v1/pxes', $params);
|
||||||
|
|
||||||
$client->setPxeSync(true);
|
$client->setPxeSync(true);
|
||||||
$this->entityManager->persist($client);
|
$this->entityManager->persist($client);
|
||||||
|
|
|
@ -10,6 +10,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||||
|
@ -30,7 +31,11 @@ class DeleteAction extends AbstractOgBootController
|
||||||
$this->entityManager->remove($data);
|
$this->entityManager->remove($data);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
$content = $this->createRequest('DELETE', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates/'.$data->getName());
|
$content = $this->createRequest('DELETE', '/ogboot/v1/pxe-templates/'.$data->getName());
|
||||||
|
|
||||||
|
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||||
|
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||||
|
}
|
||||||
|
|
||||||
$defaultTemplateEntity = $this->entityManager->getRepository(PxeTemplate::class)->findOneBy(['isDefault' => true]);
|
$defaultTemplateEntity = $this->entityManager->getRepository(PxeTemplate::class)->findOneBy(['isDefault' => true]);
|
||||||
|
|
||||||
|
|
|
@ -25,13 +25,9 @@ class GetAction extends AbstractOgBootController
|
||||||
*/
|
*/
|
||||||
public function __invoke(PxeTemplate $template, HttpClientInterface $httpClient): JsonResponse
|
public function __invoke(PxeTemplate $template, HttpClientInterface $httpClient): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
$response = $this->createRequest('GET', '/ogboot/v1/pxe-templates/'.$template->getName());
|
||||||
$response = $httpClient->request('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates/'.$template->getName(), [
|
|
||||||
'headers' => [
|
if ($response->getStatusCode() !== Response::HTTP_OK) {
|
||||||
'accept' => 'application/json',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
} catch (TransportExceptionInterface $e) {
|
|
||||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||||
|
@ -24,18 +25,12 @@ class GetCollectionAction extends AbstractOgBootController
|
||||||
*/
|
*/
|
||||||
public function __invoke(HttpClientInterface $httpClient): JsonResponse
|
public function __invoke(HttpClientInterface $httpClient): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
$content = $this->createRequest('GET', '/ogboot/v1/pxe-templates');
|
||||||
$response = $httpClient->request('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates', [
|
|
||||||
'headers' => [
|
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||||
'accept' => 'application/json',
|
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||||
],
|
|
||||||
]);
|
|
||||||
} catch (TransportExceptionInterface $e) {
|
|
||||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = json_decode($response->getContent(), true);
|
return new JsonResponse( data: $content, status: Response::HTTP_OK);
|
||||||
|
|
||||||
return new JsonResponse( data: $data, status: Response::HTTP_OK);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||||
|
@ -33,7 +34,11 @@ class PostAction extends AbstractOgBootController
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
$content = $this->createRequest('POST', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates' , $params);
|
$content = $this->createRequest('POST', '/ogboot/v1/pxe-templates' , $params);
|
||||||
|
|
||||||
|
if (isset($content['error']) && $content['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||||
|
throw new ValidatorException('An error occurred: ' . $content['error']);
|
||||||
|
}
|
||||||
|
|
||||||
$data->setSynchronized(true);
|
$data->setSynchronized(true);
|
||||||
$this->entityManager->persist($data);
|
$this->entityManager->persist($data);
|
||||||
|
|
|
@ -28,7 +28,7 @@ class SyncAction extends AbstractOgBootController
|
||||||
*/
|
*/
|
||||||
public function __invoke(): JsonResponse
|
public function __invoke(): JsonResponse
|
||||||
{
|
{
|
||||||
$content = $this->createRequest('GET', 'http://' . $this->ogBootApiUrl . '/ogboot/v1/pxe-templates');
|
$content = $this->createRequest('GET', '/ogboot/v1/pxe-templates');
|
||||||
$templateNamesFromApi = $content['message'];
|
$templateNamesFromApi = $content['message'];
|
||||||
|
|
||||||
$existingTemplates = $this->entityManager->getRepository(PxeTemplate::class)->findAll();
|
$existingTemplates = $this->entityManager->getRepository(PxeTemplate::class)->findAll();
|
||||||
|
@ -49,7 +49,11 @@ class SyncAction extends AbstractOgBootController
|
||||||
$templateEntity->setName($templateName);
|
$templateEntity->setName($templateName);
|
||||||
}
|
}
|
||||||
|
|
||||||
$templateContent = $this->createRequest('GET', 'http://' . $this->ogBootApiUrl . '/ogboot/v1/pxe-templates/' . $templateEntity->getName());
|
$templateContent = $this->createRequest('GET', '/ogboot/v1/pxe-templates/' . $templateEntity->getName());
|
||||||
|
|
||||||
|
if (isset($templateContent['error']) && $templateContent['error'] === Response::HTTP_INTERNAL_SERVER_ERROR ) {
|
||||||
|
throw new ValidatorException('An error occurred: ' . $templateContent['error']);
|
||||||
|
}
|
||||||
|
|
||||||
$templateEntity->setTemplateContent($templateContent['template_content']);
|
$templateEntity->setTemplateContent($templateContent['template_content']);
|
||||||
$templateEntity->setSynchronized(true);
|
$templateEntity->setSynchronized(true);
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Dto\Input;
|
||||||
|
|
||||||
|
class BootClientInput
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -16,8 +16,12 @@ use Symfony\Component\HttpClient\HttpClient;
|
||||||
readonly class StatusService
|
readonly class StatusService
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
#[Autowire(env: 'OG_BOOT_API_URL')]
|
#[Autowire(env: 'OG_BOOT_IP')]
|
||||||
private string $ogBootApiUrl
|
protected string $ogBootIp,
|
||||||
|
#[Autowire(env: 'OG_BOOT_PXE_PORT')]
|
||||||
|
protected string $ogBootPxePort,
|
||||||
|
#[Autowire(env: 'OG_BOOT_API_PORT')]
|
||||||
|
protected string $ogBootApiPort,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -31,12 +35,12 @@ readonly class StatusService
|
||||||
public function __invoke()
|
public function __invoke()
|
||||||
{
|
{
|
||||||
$httpClient = HttpClient::create([
|
$httpClient = HttpClient::create([
|
||||||
'verify_peer' => false, // Ignorar la verificación del certificado SSL
|
'verify_peer' => false,
|
||||||
'verify_host' => false, // Ignorar la verificación del nombre del host
|
'verify_host' => false,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $httpClient->request('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/status', [
|
$response = $httpClient->request('GET', 'http://'.$this->ogBootIp.':'.$this->ogBootApiPort.'/ogboot/v1/status', [
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'accept' => 'application/json',
|
'accept' => 'application/json',
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in New Issue