浏览代码

FD3-576 leases por db

Guillermo Espinoza 7 年之前
父节点
当前提交
c72ec65e54

+ 1 - 1
src/KeaBundle/Resources/config/services.yml

@@ -1,7 +1,7 @@
 services:
     kea.config:
         class: KeaBundle\Services\KeaConfigService
-        arguments: ["@webservice", "@doctrine.orm.entity_manager"]
+        arguments: ["@doctrine.orm.entity_manager", "%database_user%", "%database_password%"]
 
     sonata.admin.kea_config:
         class: KeaBundle\Admin\ConfigAdmin

+ 7 - 7
src/KeaBundle/Services/BaseKea.php

@@ -45,8 +45,8 @@ class BaseKea implements KeaConfigInterface
                 'arguments' => array(
                     'Dhcp4' => [
                         'control-socket' => $this->controlSocketConfig(),
-                        'lease-database' => $this->leaseDatabaseConfig(),
-                        'hosts-database' => $this->leaseDatabaseConfig(),
+                        'lease-database' => $this->leaseDatabaseConfig($data),
+                        'hosts-database' => $this->leaseDatabaseConfig($data),
                         'subnet4' => $this->subnet4,
                         'hooks-libraries' => $this->hooks_libraries,
                         'interfaces-config' => $this->getInterfacesConfig(),
@@ -181,14 +181,14 @@ class BaseKea implements KeaConfigInterface
     /**
      * @return array
      */
-    private function leaseDatabaseConfig($type = 'mysql')
+    private function leaseDatabaseConfig($data, $type = 'mysql')
     {
         if ($type == 'mysql') {
             $config = array(
-                "host" => "mysql",
-                "name" => "kea",
-                "user" => "root",
-                "password" => getenv('MYSQL_ROOT_PASSWORD'),
+                "host" => $data['db']['host'],
+                "name" => $data['db']['name'],
+                "user" => $data['db']['user'],
+                "password" => $data['db']['password'],
                 "type" => "mysql",
             );
         } elseif ($type == 'memfile') {

+ 14 - 7
src/KeaBundle/Services/KeaConfigService.php

@@ -6,7 +6,6 @@ use Doctrine\ORM\EntityManager;
 use Doctrine\ORM\EntityRepository;
 use DHCPBundle\Entity\DHCP;
 use KeaBundle\Interfaces\KeaConfigInterface;
-use WebserviceBundle\Services\Webservice;
 
 class KeaConfigService
 {
@@ -27,21 +26,28 @@ class KeaConfigService
     private $hostRepository;
 
     /**
-     * @var Webservice
+     * @var array
      */
-    private $webService;
-
+    private $databaseConfig;
+    
 
     /**
-     * @param Webservice $ws
      * @param EntityManager $em
+     * @param string $databaseUser
+     * @param string $databasePassword
      */
-    public function __construct(Webservice $ws, EntityManager $em)
+    public function __construct(EntityManager $em, $databaseUser, $databasePassword)
     {
         $this->dhcpRepository = $em->getRepository('DHCPBundle:DHCP');
         $this->subnetRepository = $em->getRepository('IPv4Bundle:SubNet');
         $this->hostRepository = $em->getRepository('HostBundle:Host');
-        $this->webService = $ws;
+        
+        $this->databaseConfig = [
+            'host' => 'mysql',
+            'name' => 'kea',
+            'user' => $databaseUser,
+            'password' => $databasePassword,
+        ];
     }
 
     /**
@@ -63,6 +69,7 @@ class KeaConfigService
                     'hosts' => $this->hostRepository->findAll(),
                     'subnets' => $this->subnetRepository->findAll(),
                     'library' => $library,
+                    'db' => $this->databaseConfig,
                 ];
                 $config = $keaConfig->getConfig($data);
             }