icingaweb2-module-director/application/controllers/ConfigController.php

55 lines
1.8 KiB
PHP
Raw Normal View History

<?php
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
2015-06-23 14:37:23 +02:00
use Icinga\Module\Director\Util;
use Icinga\Module\Director\Web\Controller\ActionController;
2015-06-29 10:13:39 +02:00
use Icinga\Web\Url;
2015-09-30 08:40:09 +02:00
use Icinga\Module\Director\Core\RestApiClient;
use Icinga\Module\Director\Core\CoreApi;
use Icinga\Web\Notification;
2015-06-17 18:57:51 +02:00
class Director_ConfigController extends ActionController
{
2015-09-30 08:40:09 +02:00
public function deployAction()
{
$checksum = $this->params->get('checksum');
$config = IcingaConfig::fromDb(Util::hex2binary($checksum), $this->db());
if ($this->api()->dumpConfig($config, $this->db())) {
$url = Url::fromPath('director/list/deploymentlog');
Notification::success(
$this->translate('Config has been submitted, validation is going on')
);
$this->redirectNow($url);
} else {
$url = Url::fromPath('director/config/show', array('checksum' => $checksum));
Notification::success(
2015-10-13 17:24:50 +02:00
$this->translate('Config deployment failed')
2015-09-30 08:40:09 +02:00
);
$this->redirectNow($url);
}
}
public function showAction()
{
2015-06-23 14:37:23 +02:00
$this->view->config = IcingaConfig::fromDb(Util::hex2binary($this->params->get('checksum')), $this->db());
}
2015-06-17 18:57:51 +02:00
public function storeAction()
{
$config = IcingaConfig::generate($this->db());
2015-06-29 10:13:39 +02:00
$this->redirectNow(
Url::fromPath('director/config/show',
array('checksum' => $config->getHexChecksum()))
);
2015-06-17 18:57:51 +02:00
}
2015-09-30 08:40:09 +02:00
protected function api()
{
$apiconfig = $this->Config()->getSection('api');
$client = new RestApiClient($apiconfig->get('address'), $apiconfig->get('port'));
$client->setCredentials($apiconfig->get('username'), $apiconfig->get('password'));
$api = new CoreApi($client);
return $api;
}
}