Pārlūkot izejas kodu

FD3-790 kea config service updated

Guillermo Espinoza 6 gadi atpakaļ
vecāks
revīzija
2d722f5583

+ 3 - 1
src/HostBundle/Form/HostType.php

@@ -27,7 +27,9 @@ class HostType extends AbstractType
             ->add('fixedIP', TextType::class, [
                 'required' => false,
             ])
-            ->add('mtaEnabled')
+            ->add('mtaEnabled', null, [
+                'required' => false,
+            ])
             ;
         foreach (DHCPOptions::getConstants() as $opt) {
             $builder->add($opt, TextType::class, array(

+ 1 - 1
src/KeaBundle/Command/KeaConfigCommand.php

@@ -18,7 +18,7 @@ class KeaConfigCommand extends ContainerAwareCommand
             ->setHelp('Create Kea DHCP Config')
             ->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('library', null, InputOption::VALUE_OPTIONAL, 'Hook library path', '/opt/hooks/kea-cm-hook/kea-hook-flowdat.so')
             ->addOption('set', null, InputOption::VALUE_NONE, 'Send Config DHCP4 to KEA')
             ;
     }

+ 38 - 34
src/KeaBundle/Services/BaseKea.php

@@ -196,45 +196,49 @@ class BaseKea implements KeaConfigInterface
         $dhcp = $data['dhcp'];
         $hosts = $data['hosts'];
 
-        $hook = [
-            'library' => $data['library'],
-        ];
-
-        $dhcpModelParams = $dhcp && $dhcp->getDhcpModel() ? $dhcp->getDhcpModel()->getData('parameters') : null;
-
-        $option122 = isset($dhcpModelParams['option122']) ? $dhcpModelParams['option122'] : null;
-        $ip = isset($dhcpModelParams['ip']) ? $dhcpModelParams['ip'] : null;
-        if ($option122 && $ip) {
-            $macs = [];
-            foreach ($hosts as $host) {
-                if ($host->getMac() != '' && $host->getMtaEnabled() == true) {
-                    $macs[] = $host->getMac();
+        if ($hosts) {
+            $hook = [
+                'library' => $data['library'],
+            ];
+    
+            $dhcpModelParams = $dhcp && $dhcp->getDhcpModel() ? $dhcp->getDhcpModel()->getData('parameters') : null;
+    
+            $option122 = isset($dhcpModelParams['option122']) ? $dhcpModelParams['option122'] : null;
+            $ip = isset($dhcpModelParams['ip']) ? $dhcpModelParams['ip'] : null;
+            if ($option122 && $ip) {
+                $macs = [];
+                foreach ($hosts as $host) {
+                    if ($host->getMac() != '' && $host->getMtaEnabled() == true) {
+                        $macs[] = $host->getMac();
+                    }
+                }
+                
+                if (!empty($macs)) {
+                    $hook['parameters']['option122'] = [
+                        $ip => $macs
+                    ];
                 }
             }
-
-            $hook['parameters']['option122'] = [
-                $ip => $macs
-            ];
-        }
-
-        $remote_id_map = isset($dhcpModelParams['remote-id-map']) ? $dhcpModelParams['remote-id-map'] : null;
-        if ($remote_id_map) {
-            $hostConfig = [];
-            foreach ($hosts as $host) {
-                if ($host->getMac()) {
-                    $mac = $host->getMac();
-                    $state = $host->getState();
-                    $shortname = $host->getHostType()->getShortname();
-
-                    $client_class = $state != HostStatus::STATE_NONE ? $state : $shortname;
-
-                    $hostConfig[$client_class][] = $mac;
+    
+            $remote_id_map = isset($dhcpModelParams['remote-id-map']) ? $dhcpModelParams['remote-id-map'] : null;
+            if ($remote_id_map) {
+                $hostConfig = [];
+                foreach ($hosts as $host) {
+                    if ($host->getMac()) {
+                        $mac = $host->getMac();
+                        $state = $host->getState();
+                        $shortname = $host->getHostType()->getShortname();
+    
+                        $client_class = $state != HostStatus::STATE_NONE ? $state : $shortname;
+    
+                        $hostConfig[$client_class][] = $mac;
+                    }
                 }
+                $hook['parameters']['remote-id-map'] = $hostConfig;
             }
-            $hook['parameters']['remote-id-map'] = $hostConfig;
+    
+            $this->hooks_libraries[] = $hook;
         }
-
-        $this->hooks_libraries[] = $hook;
     }
 
     /**