Forráskód Böngészése

FD3-751 refactory

Espinoza Guillermo 6 éve
szülő
commit
29a9482882

+ 1 - 1
app/DoctrineMigrations/src/action.yml

@@ -6,7 +6,7 @@ insertorupdate:
           workflow_name: "dhcp_workflow"
           event: "a:1:{i:0;s:5:\"enter\";}"
           event_reference: "active"
-          template: "echo \"Config KEA\"\r\nphp /opt/dhcp/bin/console kea:config --set=1"
+          template: "echo \"Config KEA\"\r\nphp /opt/dhcp/bin/console kea:config --set"
           tenancy_id: 1
         -
           id: 2

+ 16 - 7
src/KeaBundle/Command/KeaConfigCommand.php

@@ -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));
         }