From 190b78370925bb985e506e27cbde12f59121538c Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 30 Sep 2015 08:40:09 +0200 Subject: [PATCH] config/deploy: new controller action --- application/controllers/ConfigController.php | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index a2b07bb6..163bad74 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -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; + } }