|
@@ -29,24 +29,36 @@ class KeaConfigService
|
|
|
* @var array
|
|
|
*/
|
|
|
private $databaseConfig;
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var array
|
|
|
+ */
|
|
|
+ private $amqpConfig;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* @param EntityManager $em
|
|
|
* @param string $databaseUser
|
|
|
* @param string $databasePassword
|
|
|
*/
|
|
|
- public function __construct(EntityManager $em, $databaseUser, $databasePassword)
|
|
|
+ public function __construct(EntityManager $em, $databaseHost, $databaseName, $databaseNameKea, $databaseUser, $databasePassword, $amqpHost, $amqpUser, $amqpPassword)
|
|
|
{
|
|
|
$this->dhcpRepository = $em->getRepository('DHCPBundle:DHCP');
|
|
|
$this->subnetRepository = $em->getRepository('IPv4Bundle:SubNet');
|
|
|
$this->hostRepository = $em->getRepository('HostBundle:Host');
|
|
|
-
|
|
|
+
|
|
|
$this->databaseConfig = [
|
|
|
- 'host' => 'mysql',
|
|
|
- 'name' => 'kea',
|
|
|
+ 'host' => $databaseHost,
|
|
|
+ 'name' => $databaseNameKea,
|
|
|
'user' => $databaseUser,
|
|
|
'password' => $databasePassword,
|
|
|
+ 'database' => $databaseName,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $this->amqpConfig = [
|
|
|
+ 'host' => $amqpHost,
|
|
|
+ 'user' => $amqpUser,
|
|
|
+ 'password' => $amqpPassword,
|
|
|
];
|
|
|
}
|
|
|
|
|
@@ -70,6 +82,7 @@ class KeaConfigService
|
|
|
'subnets' => $this->subnetRepository->findAll(),
|
|
|
'library' => $library,
|
|
|
'db' => $this->databaseConfig,
|
|
|
+ 'amqp' => $this->amqpConfig,
|
|
|
];
|
|
|
$config = $keaConfig->getConfig($data);
|
|
|
}
|
|
@@ -88,14 +101,14 @@ class KeaConfigService
|
|
|
{
|
|
|
$host = $dhcp->getHost();
|
|
|
if (is_null($host)) $host = "kea:8080";
|
|
|
-
|
|
|
+
|
|
|
$_params = array(
|
|
|
- "command" => "config-get",
|
|
|
+ "command" => "config-get",
|
|
|
"service" => array($service),
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
$params = json_encode($_params);
|
|
|
-
|
|
|
+
|
|
|
$config = $this->curlPost($host, $params);
|
|
|
|
|
|
return $config;
|
|
@@ -111,14 +124,14 @@ class KeaConfigService
|
|
|
{
|
|
|
$host = $dhcp->getHost();
|
|
|
if(is_null($host)) $host = "kea:8080";
|
|
|
-
|
|
|
+
|
|
|
$_params = array(
|
|
|
- "command" => "config-reload",
|
|
|
+ "command" => "config-reload",
|
|
|
"service" => array($service),
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
$params = json_encode($_params);
|
|
|
-
|
|
|
+
|
|
|
$config = $this->curlPost($host, $params);
|
|
|
|
|
|
return $config;
|
|
@@ -134,14 +147,14 @@ class KeaConfigService
|
|
|
{
|
|
|
$host = $dhcp->getHost();
|
|
|
if(is_null($host)) $host = "kea:8080";
|
|
|
-
|
|
|
+
|
|
|
$_params = array(
|
|
|
- "command" => "libreload",
|
|
|
+ "command" => "libreload",
|
|
|
"service" => array($service),
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
$params = json_encode($_params);
|
|
|
-
|
|
|
+
|
|
|
$config = $this->curlPost($host, $params);
|
|
|
|
|
|
return $config;
|
|
@@ -152,7 +165,7 @@ class KeaConfigService
|
|
|
* que está montado como volumen en el docker de KEA
|
|
|
*
|
|
|
* @param json params
|
|
|
- *
|
|
|
+ *
|
|
|
* @return boolean
|
|
|
*/
|
|
|
public function saveFileConfig($params = null)
|
|
@@ -161,17 +174,17 @@ class KeaConfigService
|
|
|
if(isset($_params[0]) && isset($_params[0]['arguments'])) {
|
|
|
$json = json_encode($_params[0]['arguments'], JSON_PRETTY_PRINT);
|
|
|
file_put_contents("kea/kea-dhcp4.conf", $json);
|
|
|
-
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param DHCP $dhcp
|
|
|
* @param json params
|
|
|
- *
|
|
|
+ *
|
|
|
* @return string
|
|
|
*/
|
|
|
public function setConfig(DHCP $dhcp, $params = null)
|
|
@@ -184,13 +197,13 @@ class KeaConfigService
|
|
|
|
|
|
if(isset($_params[0]) && isset($_params[0]['arguments'])) {
|
|
|
$_params = array(
|
|
|
- "command" => "config-set",
|
|
|
- "service" => array("dhcp4"),
|
|
|
+ "command" => "config-set",
|
|
|
+ "service" => array("dhcp4"),
|
|
|
"arguments" => $_params[0]['arguments']);
|
|
|
} else {
|
|
|
return json_encode(array("error" => "Config Error. Check template DHCP"));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$config = $this->curlPost($host, json_encode($_params));
|
|
|
|
|
|
return $config;
|
|
@@ -202,7 +215,7 @@ class KeaConfigService
|
|
|
*
|
|
|
* @return string
|
|
|
*/
|
|
|
- private function curlPost($host, $params)
|
|
|
+ private function curlPost($host, $params)
|
|
|
{
|
|
|
$ch = curl_init();
|
|
|
|