|
@@ -10,6 +10,11 @@ use KeaBundle\Interfaces\KeaConfigInterface;
|
|
|
class KeaConfigService
|
|
|
{
|
|
|
|
|
|
+ /**
|
|
|
+ * @var EntityManager
|
|
|
+ */
|
|
|
+ private $em;
|
|
|
+
|
|
|
/**
|
|
|
* @var EntityRepository
|
|
|
*/
|
|
@@ -43,6 +48,7 @@ class KeaConfigService
|
|
|
*/
|
|
|
public function __construct(EntityManager $em, $databaseHost, $databaseName, $databaseNameKea, $databaseUser, $databasePassword, $amqpHost, $amqpUser, $amqpPassword)
|
|
|
{
|
|
|
+ $this->em = $em;
|
|
|
$this->dhcpRepository = $em->getRepository('DHCPBundle:DHCP');
|
|
|
$this->subnetRepository = $em->getRepository('IPv4Bundle:SubNet');
|
|
|
$this->hostRepository = $em->getRepository('HostBundle:Host');
|
|
@@ -80,6 +86,7 @@ class KeaConfigService
|
|
|
'dhcp' => $id ? $this->dhcpRepository->find($id) : null,
|
|
|
'hosts' => $this->hostRepository->findAll(),
|
|
|
'subnets' => $this->subnetRepository->findAll(),
|
|
|
+ 'reservations' => $this->getHostsReservations(),
|
|
|
'library' => $library,
|
|
|
'db' => $this->databaseConfig,
|
|
|
'amqp' => $this->amqpConfig,
|
|
@@ -234,4 +241,50 @@ class KeaConfigService
|
|
|
return $return;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ private function getHostsReservations()
|
|
|
+ {
|
|
|
+ $subnets = $this->subnetRepository->findAll();
|
|
|
+ $reservations = [];
|
|
|
+
|
|
|
+ if(is_null($subnets) || empty($subnets)) {
|
|
|
+ return $reservations;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($subnets as $subnet) {
|
|
|
+
|
|
|
+ foreach ($subnet->getIpPool() as $pool) {
|
|
|
+
|
|
|
+ $start = ip2long($pool->getFirstIp());
|
|
|
+ $end = ip2long($pool->getLastIp());
|
|
|
+
|
|
|
+ $qb = $this->em->createQueryBuilder();
|
|
|
+
|
|
|
+ $qb->select(array('h'))
|
|
|
+ ->from('HostBundle:Host', 'h')
|
|
|
+ ->where(
|
|
|
+ $qb->expr()->andX(
|
|
|
+ $qb->expr()->isNotNull('h.ipv4Address'),
|
|
|
+ $qb->expr()->between('h.ipv4Address',$start,$end)
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ $hosts = $qb->getQuery()->getResult();
|
|
|
+
|
|
|
+ $results = array();
|
|
|
+ if($hosts) {
|
|
|
+ foreach($hosts as $host) {
|
|
|
+ $results[] = ['hw-address' => "{$host->getMac()}",'ip-address' => "{$host->getFixedAddress()}"];
|
|
|
+ }
|
|
|
+
|
|
|
+ $reservations[$subnet->getId()] = $results;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $reservations;
|
|
|
+ }
|
|
|
+
|
|
|
}
|