entityManager->getRepository(Subnet::class)->findOneBy(['uuid' => $dataOrUuid]); } if (!$data) { throw new \Exception('Subred no encontrada.'); } $dhcpServer = $data->getDhcpServer(); if (!$dhcpServer) { throw new \Exception('La subred no tiene un servidor DHCP asociado.'); } $params = [ 'json' => [ 'subnetId' => $data->getServerId() ?? rand(1, 1000), 'mask' => $data->getNetmask(), 'address' => $data->getIpAddress(), 'nextServer' => $data->getNextServer(), 'bootFileName' => $data->getBootFileName(), 'router' => $data->getRouter(), 'DNS' => $data->getDns() ] ]; $port = $dhcpServer->getApiPort() ?? 8081; $url = sprintf('http://%s:%d/ogdhcp/v1/subnets', $dhcpServer->getIp(), $port); $content = $this->createRequest('POST', $url, $params); $data->setServerId($content['message']['id']); $data->setSynchronized(true); $this->entityManager->persist($data); $this->entityManager->flush(); return new JsonResponse(data: $content, status: Response::HTTP_OK); } }