config/deploy: new controller action

This commit is contained in:
Thomas Gelf 2015-09-30 08:40:09 +02:00
parent 0ee644d0c1
commit 190b783709
1 changed files with 31 additions and 0 deletions

View File

@ -4,9 +4,31 @@ use Icinga\Module\Director\IcingaConfig\IcingaConfig;
use Icinga\Module\Director\Util;
use Icinga\Module\Director\Web\Controller\ActionController;
use Icinga\Web\Url;
use Icinga\Module\Director\Core\RestApiClient;
use Icinga\Module\Director\Core\CoreApi;
use Icinga\Web\Notification;
class Director_ConfigController extends ActionController
{
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(
$this->translate('Config deployment has been failed')
);
$this->redirectNow($url);
}
}
public function showAction()
{
$this->view->config = IcingaConfig::fromDb(Util::hex2binary($this->params->get('checksum')), $this->db());
@ -20,4 +42,13 @@ class Director_ConfigController extends ActionController
array('checksum' => $config->getHexChecksum()))
);
}
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;
}
}