diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:43:12 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:43:12 +0000 |
commit | cd989f9c3aff968e19a3aeabc4eb9085787a6673 (patch) | |
tree | fbff2135e7013f196b891bbde54618eb050e4aaf /library/Director/Job/ConfigJob.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.tar.xz icingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.zip |
Adding upstream version 1.10.2.upstream/1.10.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Director/Job/ConfigJob.php')
-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' + ); + } +} |