mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-09-26 03:09:11 +02:00
cli: add config deploy command
This commit is contained in:
parent
65b048d78b
commit
7eb7f1324c
@ -7,8 +7,14 @@ use Icinga\Module\Director\Cli\Command;
|
|||||||
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
||||||
use Icinga\Module\Director\Data\Db\DbObject;
|
use Icinga\Module\Director\Data\Db\DbObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate, show and deploy Icinga 2 configuration
|
||||||
|
*/
|
||||||
class ConfigCommand extends Command
|
class ConfigCommand extends Command
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Re-render the current configuration
|
||||||
|
*/
|
||||||
public function renderAction()
|
public function renderAction()
|
||||||
{
|
{
|
||||||
$config = new IcingaConfig($this->db());
|
$config = new IcingaConfig($this->db());
|
||||||
@ -31,6 +37,41 @@ class ConfigCommand extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deployAction()
|
||||||
|
{
|
||||||
|
$api = $this->api();
|
||||||
|
$db = $this->db();
|
||||||
|
|
||||||
|
$checksum = $this->params->get('checksum');
|
||||||
|
if ($checksum) {
|
||||||
|
$config = IcingaConfig::load(Util::hex2binary($checksum), $db);
|
||||||
|
} else {
|
||||||
|
$config = IcingaConfig::generate($db);
|
||||||
|
$checksum = $config->getHexChecksum();
|
||||||
|
}
|
||||||
|
|
||||||
|
$api->wipeInactiveStages($db);
|
||||||
|
$current = $api->getActiveChecksum($db);
|
||||||
|
if ($current === $checksum) {
|
||||||
|
if ($this->params->get('force')) {
|
||||||
|
echo "Config matches active stage, deploying anyway\n";
|
||||||
|
} else {
|
||||||
|
echo "Config matches active stage, nothing to do\n";
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if ($api->dumpConfig($config, $db)) {
|
||||||
|
printf("Config '%s' has been deployed\n", $checksum);
|
||||||
|
} else {
|
||||||
|
$this->fail(
|
||||||
|
sprintf("Failed to deploy config '%s'\n", $checksum)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function filesAction()
|
public function filesAction()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user