[icinga-checkins] icinga.org: icingaweb2-module-director/feature/icinga1-config-12919: CustomVariable*(Legacy): Add toLegacyConfigString

git at icinga.org git at icinga.org
Fri Oct 14 15:36:27 CEST 2016


Module: icingaweb2-module-director
Branch: feature/icinga1-config-12919
Commit: 3a387986648dfd3d9f144f43621923aa21e32c82
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=3a387986648dfd3d9f144f43621923aa21e32c82

Author: Markus Frosch <markus.frosch at icinga.com>
Date:   Fri Oct 14 11:53:04 2016 +0200

CustomVariable*(Legacy): Add toLegacyConfigString

refs #12919

---

 .../CustomVariable/CustomVariableArray.php         |    6 ++++
 .../CustomVariable/CustomVariableBoolean.php       |    5 ++++
 .../CustomVariable/CustomVariableDictionary.php    |    6 ++++
 .../Director/CustomVariable/CustomVariableNull.php |    5 ++++
 .../CustomVariable/CustomVariableNumber.php        |    5 ++++
 .../CustomVariable/CustomVariableString.php        |    6 ++++
 .../Director/CustomVariable/CustomVariables.php    |   31 ++++++++++++++++++++
 7 files changed, 64 insertions(+)

diff --git a/library/Director/CustomVariable/CustomVariableArray.php b/library/Director/CustomVariable/CustomVariableArray.php
index 1c18237..ee4cedd 100644
--- a/library/Director/CustomVariable/CustomVariableArray.php
+++ b/library/Director/CustomVariable/CustomVariableArray.php
@@ -3,6 +3,7 @@
 namespace Icinga\Module\Director\CustomVariable;
 
 use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
+use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1;
 
 class CustomVariableArray extends CustomVariable
 {
@@ -76,4 +77,9 @@ class CustomVariableArray extends CustomVariable
             $this->value[$key] = clone($value);
         }
     }
+
+    public function toLegacyConfigString()
+    {
+        return c1::renderArray($this->value);
+    }
 }
diff --git a/library/Director/CustomVariable/CustomVariableBoolean.php b/library/Director/CustomVariable/CustomVariableBoolean.php
index e1af626..463751a 100644
--- a/library/Director/CustomVariable/CustomVariableBoolean.php
+++ b/library/Director/CustomVariable/CustomVariableBoolean.php
@@ -45,4 +45,9 @@ class CustomVariableBoolean extends CustomVariable
     {
         return $this->value ? 'true' : 'false';
     }
+
+    public function toLegacyConfigString()
+    {
+        return $this->toConfigString();
+    }
 }
diff --git a/library/Director/CustomVariable/CustomVariableDictionary.php b/library/Director/CustomVariable/CustomVariableDictionary.php
index ec94a33..e7303ac 100644
--- a/library/Director/CustomVariable/CustomVariableDictionary.php
+++ b/library/Director/CustomVariable/CustomVariableDictionary.php
@@ -3,6 +3,7 @@
 namespace Icinga\Module\Director\CustomVariable;
 
 use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
+use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1;
 use Countable;
 
 class CustomVariableDictionary extends CustomVariable implements Countable
@@ -109,4 +110,9 @@ class CustomVariableDictionary extends CustomVariable implements Countable
     {
         return c::renderDictionary($this->value);
     }
+
+    public function toLegacyConfigString()
+    {
+        return c1::renderDictionary($this->value);
+    }
 }
diff --git a/library/Director/CustomVariable/CustomVariableNull.php b/library/Director/CustomVariable/CustomVariableNull.php
index 6a0397a..5fa4cf0 100644
--- a/library/Director/CustomVariable/CustomVariableNull.php
+++ b/library/Director/CustomVariable/CustomVariableNull.php
@@ -45,4 +45,9 @@ class CustomVariableNull extends CustomVariable
     {
         return 'null';
     }
+
+    public function toLegacyConfigString()
+    {
+        return $this->toConfigString();
+    }
 }
diff --git a/library/Director/CustomVariable/CustomVariableNumber.php b/library/Director/CustomVariable/CustomVariableNumber.php
index 7c6703a..156a572 100644
--- a/library/Director/CustomVariable/CustomVariableNumber.php
+++ b/library/Director/CustomVariable/CustomVariableNumber.php
@@ -65,4 +65,9 @@ class CustomVariableNumber extends CustomVariable
             return sprintf(self::PRECISION, $this->value);
         }
     }
+
+    public function toLegacyConfigString()
+    {
+        return $this->toConfigString();
+    }
 }
diff --git a/library/Director/CustomVariable/CustomVariableString.php b/library/Director/CustomVariable/CustomVariableString.php
index b67b332..4033214 100644
--- a/library/Director/CustomVariable/CustomVariableString.php
+++ b/library/Director/CustomVariable/CustomVariableString.php
@@ -3,6 +3,7 @@
 namespace Icinga\Module\Director\CustomVariable;
 
 use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
+use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1;
 
 class CustomVariableString extends CustomVariable
 {
@@ -40,4 +41,9 @@ class CustomVariableString extends CustomVariable
     {
         return c::renderString($this->getValue());
     }
+
+    public function toLegacyConfigString()
+    {
+        return c1::renderString($this->getValue());
+    }
 }
diff --git a/library/Director/CustomVariable/CustomVariables.php b/library/Director/CustomVariable/CustomVariables.php
index 3ce0bb0..2c88f1e 100644
--- a/library/Director/CustomVariable/CustomVariables.php
+++ b/library/Director/CustomVariable/CustomVariables.php
@@ -4,7 +4,9 @@ namespace Icinga\Module\Director\CustomVariable;
 
 use Icinga\Module\Director\Db;
 use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
+use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1;
 use Icinga\Module\Director\IcingaConfig\IcingaConfigRenderer;
+use Icinga\Module\Director\Objects\IcingaHostVar;
 use Icinga\Module\Director\Objects\IcingaObject;
 use Iterator;
 use Countable;
@@ -281,6 +283,35 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
         return $out;
     }
 
+    public function toLegacyConfigString()
+    {
+        $out = '';
+
+        ksort($this->vars);
+        foreach ($this->vars as $key => $var) {
+            /** @var CustomVariable $var */
+            // TODO: ctype_alnum + underscore?
+            $value = null;
+            switch ($type = $var->getType()) {
+                case 'String':
+                    # TODO: Make Prefetchable
+                    $value = $var->toLegacyConfigString();
+                    break;
+                default:
+                    $out .= sprintf("# Unsupported var: %s (%s)\n", $key, $type);
+            }
+
+            if ($value !== null) {
+                $out .= c1::renderKeyValue('_' . $key, $value);
+            }
+        }
+        if ($out !== '') {
+            $out = "\n".$out;
+        }
+
+        return $out;
+    }
+
     protected function renderSingleVar($key, $var)
     {
         return c::renderKeyValue(



More information about the icinga-checkins mailing list