|
@@ -5,6 +5,7 @@ namespace HostBundle\Services;
|
|
|
use Doctrine\ORM\EntityManager;
|
|
|
use Doctrine\ORM\EntityRepository;
|
|
|
use HostBundle\Entity\Host;
|
|
|
+use HostBundle\Entity\HostType;
|
|
|
use IPv4Bundle\Services\PoolService;
|
|
|
use KeaBundle\Entity\Lease4;
|
|
|
|
|
@@ -20,7 +21,7 @@ class HostService
|
|
|
* @var EntityRepository
|
|
|
*/
|
|
|
private $hostRepository;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @var EntityRepository
|
|
|
*/
|
|
@@ -45,11 +46,13 @@ class HostService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * @param HostType $hostType
|
|
|
+ *
|
|
|
* @return string
|
|
|
*/
|
|
|
- public function getFirstFreeFixedIP()
|
|
|
+ public function getFirstFreeFixedIP(HostType $hostType = null)
|
|
|
{
|
|
|
- $diff = $this->getFreeFixedIP();
|
|
|
+ $diff = $this->getFreeFixedIP($hostType);
|
|
|
if (count($diff)) {
|
|
|
return current($diff);
|
|
|
}
|
|
@@ -58,26 +61,29 @@ class HostService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * @param HostType $hostType
|
|
|
+ * @param boolean $hostFixed
|
|
|
+ *
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function getFreeFixedIP($hostFixed = true)
|
|
|
+ public function getFreeFixedIP(HostType $hostType = null, $hostFixed = true)
|
|
|
{
|
|
|
- $range = $this->poolService->getStaticPoolIPRange();
|
|
|
+ $range = $this->poolService->getStaticPoolIPRange($hostType);
|
|
|
$leases = $this->lease4Repository->getAllAddress();
|
|
|
- $hostsFixedIP = $hostFixed ? $this->getHostsFixedIp() : [];
|
|
|
+ $hostsFixedIP = $hostFixed ? $this->getHostsFixedIp($hostType) : [];
|
|
|
|
|
|
return array_diff($range, $leases, $hostsFixedIP);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * @param HostType $hostType
|
|
|
+ *
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function getHostsFixedIp()
|
|
|
+ public function getHostsFixedIp(HostType $hostType = null)
|
|
|
{
|
|
|
$hostsFixedIP = [];
|
|
|
- $hosts = $this->hostRepository->findBy([
|
|
|
- 'fixedIP' => true,
|
|
|
- ]);
|
|
|
+ $hosts = $this->hostRepository->findAllFixedIPByHostType($hostType);
|
|
|
foreach ($hosts as $host) {
|
|
|
if ($host->getFixedAddress()) {
|
|
|
$hostsFixedIP[] = $host->getFixedAddress();
|