[icinga-checkins] icinga.org: icingaweb2-module-director/master: CustomVariable*(Legacy): Add toLegacyConfigString

git at icinga.org git at icinga.org
Thu Nov 3 14:23:24 CET 2016


Module: icingaweb2-module-director
Branch: master
Commit: 1592894fd7187a73189c325eaf81651144e68dc0
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=1592894fd7187a73189c325eaf81651144e68dc0

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 25eb3fe..4919e92 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
 {
@@ -79,4 +80,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 6e50d8f..b830048 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
@@ -112,4 +113,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 945bd75..c2abca3 100644
--- a/library/Director/CustomVariable/CustomVariableNull.php
+++ b/library/Director/CustomVariable/CustomVariableNull.php
@@ -44,4 +44,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 1194276..cbc5bc6 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
 {
@@ -44,4 +45,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 cf35a34..d3d3cca 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 Countable;
 use Exception;
@@ -284,6 +286,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;
+    }
+
     /**
      * @param string $key
      * @param CustomVariable $var



More information about the icinga-checkins mailing list