diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
commit | f66ab8dae2f3d0418759f81a3a64dc9517a62449 (patch) | |
tree | fbff2135e7013f196b891bbde54618eb050e4aaf /library/Director/Job/ConfigJob.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.tar.xz icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.zip |
Adding upstream version 1.10.2.upstream/1.10.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | library/Director/Job/ConfigJob.php | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/library/Director/Job/ConfigJob.php b/library/Director/Job/ConfigJob.php new file mode 100644 index 0000000..fda3043 --- /dev/null +++ b/library/Director/Job/ConfigJob.php @@ -0,0 +1,75 @@ +<?php + +namespace Icinga\Module\Director\Job; + +use Icinga\Module\Director\Deployment\ConditionalConfigRenderer; +use Icinga\Module\Director\Deployment\ConditionalDeployment; +use Icinga\Module\Director\Deployment\DeploymentGracePeriod; +use Icinga\Module\Director\Hook\JobHook; +use Icinga\Module\Director\Web\Form\QuickForm; + +class ConfigJob extends JobHook +{ + public function run() + { + $db = $this->db(); + $deployer = new ConditionalDeployment($db); + $renderer = new ConditionalConfigRenderer($db); + if ($grace = $this->getSetting('grace_period')) { + $deployer->setGracePeriod(new DeploymentGracePeriod((int) $grace, $db)); + } + if ($this->getSetting('force_generate') === 'y') { + $renderer->forceRendering(); + } + + $deployer->deploy($renderer->getConfig()); + } + + public static function addSettingsFormFields(QuickForm $form) + { + $form->addElement('select', 'force_generate', [ + 'label' => $form->translate('Force rendering'), + 'description' => $form->translate( + 'Whether rendering should be forced. If not enforced, this' + . ' job re-renders the configuration only when there have been' + . ' activities since the last rendered config' + ), + 'value' => 'n', + 'multiOptions' => [ + 'y' => $form->translate('Yes'), + 'n' => $form->translate('No'), + ] + ]); + + $form->addElement('select', 'deploy_when_changed', [ + 'label' => $form->translate('Deploy modified config'), + 'description' => $form->translate( + 'This allows you to immediately deploy a modified configuration' + ), + 'value' => 'n', + 'multiOptions' => [ + 'y' => $form->translate('Yes'), + 'n' => $form->translate('No'), + ] + ]); + + $form->addElement('text', 'grace_period', array( + 'label' => $form->translate('Grace period'), + 'description' => $form->translate( + 'When deploying configuration, wait at least this amount of' + . ' seconds unless the next deployment should take place' + ), + 'value' => 600, + )); + + return $form; + } + + public static function getDescription(QuickForm $form) + { + return $form->translate( + 'The Config job allows you to generate and eventually deploy your' + . ' Icinga 2 configuration' + ); + } +} |