[icinga-checkins] icinga.org: icingaweb2-module-director/next: IcingaConfig(Legacy): Add deployment mode for Icinga 1 config

git at icinga.org git at icinga.org
Fri Nov 4 10:28:15 CET 2016


Module: icingaweb2-module-director
Branch: next
Commit: 003a100b9c5fdf756fa306fd5a3605f47ae1618c
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=003a100b9c5fdf756fa306fd5a3605f47ae1618c

Author: Markus Frosch <markus.frosch at icinga.com>
Date:   Fri Nov  4 10:28:11 2016 +0100

IcingaConfig(Legacy): Add deployment mode for Icinga 1 config

refs #13049

---

 application/forms/SettingsForm.php             |   19 ++++++++++++++-
 library/Director/IcingaConfig/IcingaConfig.php |   15 +++++++++++-
 library/Director/Objects/IcingaObject.php      |   30 +++++++++++++++---------
 library/Director/Settings.php                  |    1 +
 4 files changed, 52 insertions(+), 13 deletions(-)

diff --git a/application/forms/SettingsForm.php b/application/forms/SettingsForm.php
index 4a0e81a..2881356 100644
--- a/application/forms/SettingsForm.php
+++ b/application/forms/SettingsForm.php
@@ -84,7 +84,6 @@ class SettingsForm extends QuickForm
                 array(
                     'v2' => $this->translate('Icinga v2.x'),
                     'v1' => $this->translate('Icinga v1.x'),
-                    // Hiding for now 'v1-masterless' => $this->translate('Icinga v1.x (no master)'),
                 )
             ),
             'description'  => $this->translate(
@@ -96,6 +95,24 @@ class SettingsForm extends QuickForm
             'value' => $settings->getStoredValue('config_format')
         ));
 
+        if ($settings->getStoredValue('config_format') === 'v1') {
+            $this->addElement('select', 'deployment_mode_v1', array(
+                'label'        => $this->translate('Deployment mode'),
+                'multiOptions' => $this->eventuallyConfiguredEnum(
+                    'deployment_mode_v1',
+                    array(
+                        'active-passive' => $this->translate('Active-Passive'),
+                        'masterless'     => $this->translate('Master-less'),
+                    )
+                ),
+                'description'  => $this->translate(
+                    'Deployment mode for Icinga 1 configuration'
+                ),
+                'value' => $settings->getStoredValue('deployment_mode_v1')
+            ));
+
+        }
+
         $this->setSubmitLabel($this->translate('Store'));
     }
 
diff --git a/library/Director/IcingaConfig/IcingaConfig.php b/library/Director/IcingaConfig/IcingaConfig.php
index b14c5a7..5f61c3a 100644
--- a/library/Director/IcingaConfig/IcingaConfig.php
+++ b/library/Director/IcingaConfig/IcingaConfig.php
@@ -38,6 +38,8 @@ class IcingaConfig
 
     protected $configFormat;
 
+    protected $deploymentModeV1;
+
     public static $table = 'director_generated_config';
 
     public function __construct(Db $connection)
@@ -48,6 +50,7 @@ class IcingaConfig
         $this->connection = $connection;
         $this->db = $connection->getDbAdapter();
         $this->configFormat = $this->connection->settings()->config_format;
+        $this->deploymentModeV1 = $this->connection->settings()->deployment_mode_v1;
     }
 
     public function getSize()
@@ -74,6 +77,16 @@ class IcingaConfig
         return $this->configFormat;
     }
 
+    public function getDeploymentMode()
+    {
+        if ($this->isLegacy()) {
+            return $this->deploymentModeV1;
+        }
+        else {
+            throw new ProgrammingError('There is no deployment mode for Icinga 2 config format!');
+        }
+    }
+
     public function setConfigFormat($format)
     {
         if (! in_array($format, array('v1', 'v2'))) {
@@ -90,7 +103,7 @@ class IcingaConfig
 
     public function isLegacy()
     {
-        return strpos($this->configFormat, 'v1') === 0;
+        return $this->configFormat === 'v1';
     }
 
     public function getObjectCount()
diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php
index 280fb77..5961d77 100644
--- a/library/Director/Objects/IcingaObject.php
+++ b/library/Director/Objects/IcingaObject.php
@@ -1479,18 +1479,26 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
 
         $filename = $this->getRenderingFilename();
 
-        if (
-            $this->getResolvedProperty('zone_id')
-            && array_key_exists('enable_active_checks', $this->defaultProperties)
-            && $config->getConfigFormat() !== 'v1-masterless'
-        ) {
-            $passive = clone($this);
-            $passive->enable_active_checks = false;
+        $deploymentMode = $config->getDeploymentMode();
+        if ($deploymentMode === 'active-passive') {
+            if (
+                $this->getResolvedProperty('zone_id')
+                && array_key_exists('enable_active_checks', $this->defaultProperties)
+            ) {
+                $passive = clone($this);
+                $passive->enable_active_checks = false;
 
-            $config->configFile(
-                'director/master/' . $filename,
-                '.cfg'
-            )->addLegacyObject($passive);
+                $config->configFile(
+                    'director/master/' . $filename,
+                    '.cfg'
+                )->addLegacyObject($passive);
+            }
+        }
+        elseif ($deploymentMode === 'masterless') {
+            // no additional config
+        }
+        else {
+            throw new ProgrammingError('Unsupported deployment mode: %s' .$deploymentMode);
         }
 
         $config->configFile(
diff --git a/library/Director/Settings.php b/library/Director/Settings.php
index 5fe19d5..f2e2d1c 100644
--- a/library/Director/Settings.php
+++ b/library/Director/Settings.php
@@ -18,6 +18,7 @@ class Settings
         'override_services_templatename' => 'host var overrides (Director)',
         'disable_all_jobs'               => 'n', // 'y'
         'enable_audit_log'               => 'n',
+        'deployment_mode_v1'             => 'active-passive',
         // 'experimental_features'       => null, // 'allow'
         // 'master_zone'                 => null,
     );



More information about the icinga-checkins mailing list