ソースを参照

FD3-544 update config kea

Espinoza Guillermo 7 年 前
コミット
22d2904ca8

+ 2 - 5
src/IPv4Bundle/Admin/SubNetAdmin.php

@@ -8,6 +8,7 @@ use Sonata\AdminBundle\Datagrid\ListMapper;
 use Sonata\AdminBundle\Form\FormMapper;
 use Sonata\AdminBundle\Show\ShowMapper;
 use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
+use IPv4Bundle\Utils\HostStatus;
 
 class SubNetAdmin extends BaseAdmin
 {
@@ -57,11 +58,7 @@ class SubNetAdmin extends BaseAdmin
                 ->add('allowedHostType')
                 ->add('status', ChoiceType::class, [
                     'required' => false,
-                    'choices' => [
-                        'none' => '',
-                        'active' => 'active',
-                        'suspended' => 'suspended',
-                    ],
+                    'choices' => HostStatus::getChoices(),
                 ])
                 ->add('netGroup')
             ->end()

+ 3 - 5
src/IPv4Bundle/Entity/Host.php

@@ -6,6 +6,7 @@ use Doctrine\ORM\Mapping as ORM;
 use JMS\Serializer\Annotation as JMS;
 use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
 use IPv4Bundle\Traits\DHCPOptionTrait;
+use IPv4Bundle\Utils\HostStatus;
 use WorkflowBundle\Entity\Interfaces\WorkflowInterface;
 use WorkflowBundle\Entity\Traits\WorkflowTrait;
 
@@ -20,9 +21,6 @@ class Host implements WorkflowInterface
     use DHCPOptionTrait;
     use WorkflowTrait;
 
-    const STATE_ACTIVE = 'active';
-    const STATE_SUSPENDED = 'suspended';
-
     /**
      * @var bigint $id
      *
@@ -61,7 +59,7 @@ class Host implements WorkflowInterface
      *
      * @ORM\Column(type="string", options={"default": "active"})
      */
-    protected $state = self::STATE_ACTIVE;
+    protected $state = HostStatus::STATE_ACTIVE;
 
     /**
      * @ORM\ManyToOne(targetEntity="\WorkflowBundle\Entity\Workflow", fetch="EXTRA_LAZY")
@@ -168,7 +166,7 @@ class Host implements WorkflowInterface
      *
      * @return Host
      */
-    public function setState($state = self::STATE_ACTIVE)
+    public function setState($state = HostStatus::STATE_ACTIVE)
     {
         $this->state = $state;
 

+ 16 - 0
src/IPv4Bundle/Utils/HostStatus.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace IPv4Bundle\Utils;
+
+use DeviceBundle\Utils\ChoiceTrait;
+
+class HostStatus
+{
+
+    use ChoiceTrait;
+
+    const STATE_ACTIVE = 'active';
+    const STATE_SUSPENDED = 'suspended';
+    const STATE_NONE = 'none';
+
+}

+ 26 - 14
src/KeaBundle/Services/BaseKea.php

@@ -2,7 +2,7 @@
 
 namespace KeaBundle\Services;
 
-use IPv4Bundle\Entity\Host;
+use IPv4Bundle\Utils\HostStatus;
 use KeaBundle\Interfaces\KeaConfigInterface;
 
 class BaseKea implements KeaConfigInterface
@@ -66,10 +66,27 @@ class BaseKea implements KeaConfigInterface
                     'pool' => $pool->getFirstIp() . ' - ' . $pool->getLastIp(),
                 ];
             }
-            $this->subnet4[] = [
+
+            $hostType = $subnet->getAllowedHostType();
+            $client_class = '';
+            if ($hostType) {
+                $client_class = $hostType->getShortname();
+            }
+            if ($subnet->getStatus() != HostStatus::STATE_NONE && $subnet->getStatus() != '') {
+                if ($client_class != '') {
+                    $client_class .= '-';
+                }
+                $client_class .= $subnet->getStatus();
+            }
+
+            $subnetConf = [
                 'subnet' => $subnet->getAddress(),
                 'pools' => $pools,
             ];
+            if ($client_class != '') {
+                $subnetConf['client-class'] = $client_class;
+            }
+            $this->subnet4[] = $subnetConf;
         }
     }
 
@@ -102,22 +119,17 @@ class BaseKea implements KeaConfigInterface
 
         $remote_id_map = isset($dhcpModelParams['remote-id-map']) ? $dhcpModelParams['remote-id-map'] : null;
         if ($remote_id_map) {
-            $active = [];
-            $suspended = [];
+            $hostConfig = [];
             foreach ($hosts as $host) {
                 $mac = $host->getMac();
                 $state = $host->getState();
-                if ($state == Host::STATE_ACTIVE) {
-                    $active[] = $mac;
-                } elseif ($state == Host::STATE_SUSPENDED) {
-                    $suspended[] = $mac;
-                }
-            }
+                $shortname = $host->getHostType()->getShortname();
 
-            $hook['parameters']['remote-id-map'] = [
-                'active' => $active,
-                'suspended' => $suspended,
-            ];
+                $client_class = $state != HostStatus::STATE_NONE ? $state : $shortname;
+
+                $hostConfig[$client_class][] = $mac;
+            }
+            $hook['parameters']['remote-id-map'] = $hostConfig;
         }
 
         $this->hooks_libraries[] = $hook;