|
@@ -19,7 +19,7 @@ class KeaConfigCommand extends ContainerAwareCommand
|
|
|
->addOption('class', null, InputOption::VALUE_OPTIONAL, 'Kea Class Config in KeaBundle\Services. e.g. BaseKea', 'BaseKea')
|
|
|
->addOption('id', null, InputOption::VALUE_OPTIONAL, 'DHCP Entity ID. e.g.: 1', 1)
|
|
|
->addOption('library', null, InputOption::VALUE_OPTIONAL, 'Hook library path', '/kea-cm-hook/kea-hook-flowdat.so')
|
|
|
- ->addOption('set', null, InputOption::VALUE_REQUIRED, 'Send Config DHCP4 to KEA', 0)
|
|
|
+ ->addOption('set', null, InputOption::VALUE_NONE, 'Send Config DHCP4 to KEA')
|
|
|
;
|
|
|
}
|
|
|
|
|
@@ -29,18 +29,27 @@ class KeaConfigCommand extends ContainerAwareCommand
|
|
|
*/
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
{
|
|
|
- $setConfig = (int) $input->getOption('set');
|
|
|
-
|
|
|
$this->output = $output;
|
|
|
$class = $input->getOption('class');
|
|
|
$id = $input->getOption('id');
|
|
|
$library = $input->getOption('library');
|
|
|
$keaConfigService = $this->getContainer()->get('kea.config');
|
|
|
|
|
|
- if($setConfig) {
|
|
|
- $config = $keaConfigService->getConfig($id, $class, $library);
|
|
|
- $dhcp = $this->getContainer()->get("doctrine.orm.entity_manager")->getRepository("DHCPBundle\Entity\DHCP")->findOneById($id);
|
|
|
- $output->writeln($keaConfigService->setConfig($dhcp, $config));
|
|
|
+ $setConfig = (int) $input->getOption('set');
|
|
|
+ if ($setConfig) {
|
|
|
+ $dhcpRepository = $this->getContainer()->get("doctrine.orm.entity_manager")->getRepository("DHCPBundle\Entity\DHCP");
|
|
|
+ $dhcp = $dhcpRepository->findOneById($id);
|
|
|
+ // selecciono el primer KEA DHCP que se encuentre
|
|
|
+ if (!$dhcp) {
|
|
|
+ $dhcpAll = $dhcpRepository->findAll();
|
|
|
+ $dhcp = count($dhcpAll) ? current($dhcpAll) : null;
|
|
|
+ }
|
|
|
+ if ($dhcp) {
|
|
|
+ $config = $keaConfigService->getConfig($id, $class, $library);
|
|
|
+ $output->writeln($keaConfigService->setConfig($dhcp, $config));
|
|
|
+ } else {
|
|
|
+ $output->writeln("KEA DHCP id:{$id} <error>not found!</error>");
|
|
|
+ }
|
|
|
} else {
|
|
|
$output->writeln($keaConfigService->getConfig($id, $class, $library));
|
|
|
}
|