Ver Fonte

FD3-790 ip range from pool static by host type and status of the subnet

Guillermo Espinoza há 6 anos atrás
pai
commit
3f7da1f3d5

+ 3 - 1
src/HostBundle/Controller/REST/HostRESTController.php

@@ -47,10 +47,12 @@ class HostRESTController extends RESTController
         } else {
             return [];
         }
+        // host status for static pool filter
+        $status = $request->get('status');
         
         $ips = [];
         if ($hostType) {
-            $ips = $this->get('dhcp.host_service')->getFreeFixedIP($hostType);
+            $ips = $this->get('dhcp.host_service')->getFreeFixedIP($hostType, true, $status);
         }
         
         return compact('ips');

+ 7 - 1
src/HostBundle/Resources/views/CRUD/edit.html.twig

@@ -29,6 +29,7 @@ $(document).ready(function() {
     showHostField();
 
     $("select[id$='hostType']").on('change', showHostField);
+    $("select[id$='state']").on('change', showHostField);
 
 });
 
@@ -70,6 +71,8 @@ function updateFixedIPs()
 {
     var $hostTypeField = $("select[id$='hostType'] :selected");
     var $hostTypeId = $hostTypeField.val();
+    var $hostStateField = $("select[id$='state'] :selected");
+    var $hostState = $hostStateField.val();
 
     var option = '<option value=""></option>';
 
@@ -83,7 +86,10 @@ function updateFixedIPs()
     $.ajax({
         url: '{{ path ('post_host_ipv4_range') }}',
         type: 'POST',
-        data: {id: $hostTypeId},
+        data: {
+            id: $hostTypeId,
+            status: $hostState
+        },
         success: function(data) {
 
             $('select[id$="_fixed_address"]').html(option);

+ 3 - 2
src/HostBundle/Services/HostService.php

@@ -63,12 +63,13 @@ class HostService
     /**
      * @param HostType $hostType
      * @param boolean $hostFixed
+     * @param string $status
      *
      * @return array
      */
-    public function getFreeFixedIP(HostType $hostType = null, $hostFixed = true)
+    public function getFreeFixedIP(HostType $hostType = null, $hostFixed = true, $status = null)
     {
-        $range = $this->poolService->getStaticPoolIPRange($hostType);
+        $range = $this->poolService->getStaticPoolIPRange($hostType, $status);
         $leases = $this->lease4Repository->getAllAddress();
         $hostsFixedIP = $hostFixed ? $this->getHostsFixedIp($hostType) : [];
         

+ 22 - 0
src/IPv4Bundle/Repository/PoolRepository.php

@@ -28,4 +28,26 @@ class PoolRepository extends \Doctrine\ORM\EntityRepository
         return $qb->getQuery()->getResult();
     }
 
+    /**
+     * @param HostType $hostType
+     * @param string $status
+     *
+     * @return array
+     */
+    public function findAllStaticByHostTypeAndStatus(HostType $hostType = null, $status = null)
+    {
+        $qb = $this->createQueryBuilder('Pool')
+            ->where('Pool.isStatic = :isStatic')->setParameter('isStatic', true);
+            
+        if ($hostType) {
+            $qb->join('Pool.subNet', 'Subnet')
+               ->join('Subnet.allowedHostType', 'HostType')
+               ->andWhere('HostType.id = :id')->setParameter('id', $hostType->getId())
+               ->andWhere('Subnet.status = :status')->setParameter('status', $status)
+               ;
+        }
+        
+        return $qb->getQuery()->getResult();
+    }
+
 }

+ 3 - 2
src/IPv4Bundle/Services/PoolService.php

@@ -74,14 +74,15 @@ class PoolService
     
     /**
      * @param HostType $hostType
+     * @param string $status
      *
      * @return array
      */
-    public function getStaticPoolIPRange(HostType $hostType = null)
+    public function getStaticPoolIPRange(HostType $hostType = null, $status = null)
     {
         $count = 1;
         $range = [];
-        $pools = $this->poolRepository->findAllStaticByHostType($hostType);
+        $pools = $this->poolRepository->findAllStaticByHostTypeAndStatus($hostType, $status);
         foreach ($pools as $pool) {
             $range[] = $pool->getFirstIp();
             $firstIp = ip2long($pool->getFirstIp());