Pārlūkot izejas kodu

FD3-699 Update kea host reservation

Espinoza Guillermo 6 gadi atpakaļ
vecāks
revīzija
1277fbd63c

+ 0 - 2
src/HostBundle/Admin/HostAdmin.php

@@ -181,8 +181,6 @@ class HostAdmin extends BaseAdmin
         if (!$object->getFixedAddress() && $object->getFixedIP() == true) {
             $object->setFixedIP(false);
         }
-        
-        $object->setOptions(json_encode($object->getDHCPOption()));
     
         return parent::preUpdate($object);
     }

+ 1 - 1
src/HostBundle/Entity/Host.php

@@ -142,7 +142,7 @@ class Host implements WorkflowInterface
      */
     public function getMac()
     {
-        return $this->mac ?: ($this->host ? $this->host->getMac() : '');
+        return $this->mac;
     }
 
     /**

+ 26 - 4
src/HostBundle/EventListener/KEAHostReservationSubscriber.php

@@ -85,10 +85,12 @@ class KEAHostReservationSubscriber implements EventSubscriber
                 $query = "
                 INSERT INTO kea.hosts (dhcp_identifier,
                 dhcp_identifier_type,
-                ipv4_address)
+                ipv4_address, 
+                hostname)
                 VALUES (:mac,
                 (SELECT type FROM kea.host_identifier_type WHERE name=:type),
-                INET_ATON(:ip));
+                INET_ATON(:ip),
+                :hostname);
                 ";
             } else {
                 $query = "
@@ -99,9 +101,29 @@ class KEAHostReservationSubscriber implements EventSubscriber
             
             $databaseConnection = $this->serviceContainer->get('database_connection');
             $stmt = $databaseConnection->prepare($query);
-            $stmt->bindValue("mac", hex2bin(str_replace(':', '', $entity->getMac())));
+            $hostType = $entity->getHostType();
+            $shortname = $hostType->getShortname();
+            // calculo el campo dhcp_identifier_type de kea.hosts
+            if ($shortname == 'cablemodem' || $shortname == 'cm') {
+                $stmt->bindValue("mac", hex2bin(str_replace(':', '', $entity->getMac())));
+            } else {
+                // mta|cpe
+                $hex = '';
+                $prefix = $shortname . '-';
+                for ($i = 0; $i < strlen($prefix); $i++){
+                    $ord = ord($prefix[$i]);
+                    $hexCode = dechex($ord);
+                    $hex .= substr('0'.$hexCode, -2);
+                }
+                $stmt->bindValue("mac", hex2bin($hex . str_replace(':', '', $entity->getHost()->getMac())));
+            }
             if ($entity->getFixedAddress() && $remove == false) {
-                $stmt->bindValue("type", 'hw-address');
+                if ($shortname == 'cablemodem' || $shortname == 'cm') {
+                    $stmt->bindValue("type", 'hw-address');
+                } else {
+                    $stmt->bindValue("type", 'flex-id');
+                }
+                $stmt->bindValue("hostname", $entity->getHostName());
                 $stmt->bindValue("ip", $entity->getFixedAddress());
             }
             $stmt->execute();