[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaConfig: accept legacy config objects/files

git at icinga.org git at icinga.org
Sat Jul 23 10:13:39 CEST 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Fri Jul 22 18:15:22 2016 +0200

IcingaConfig: accept legacy config objects/files

---

 library/Director/IcingaConfig/IcingaConfig.php     |   27 ++++++++++++++++++++
 library/Director/IcingaConfig/IcingaConfigFile.php |   20 +++++++++++++++
 2 files changed, 47 insertions(+)

diff --git a/library/Director/IcingaConfig/IcingaConfig.php b/library/Director/IcingaConfig/IcingaConfig.php
index 1c774f6..87651ee 100644
--- a/library/Director/IcingaConfig/IcingaConfig.php
+++ b/library/Director/IcingaConfig/IcingaConfig.php
@@ -5,6 +5,7 @@ namespace Icinga\Module\Director\IcingaConfig;
 use Icinga\Application\Benchmark;
 use Icinga\Application\Hook;
 use Icinga\Application\Icinga;
+use Icinga\Exception\ConfigurationError;
 use Icinga\Exception\IcingaException;
 use Icinga\Exception\ProgrammingError;
 use Icinga\Module\Director\Db\Cache\PrefetchCache;
@@ -34,6 +35,8 @@ class IcingaConfig
 
     protected $generationTime;
 
+    protected $configFormat = 'v2';
+
     public static $table = 'director_generated_config';
 
     public function __construct(Db $connection)
@@ -64,6 +67,30 @@ class IcingaConfig
         return count($this->files);
     }
 
+    public function getConfigFormat()
+    {
+        return $this->configFormat;
+    }
+
+    public function setConfigFormat($format)
+    {
+        if (! in_array($format, array('v1', 'v2'))) {
+            throw new ConfigurationError(
+                'Only Icinga v1 and v2 config format is supported, got "%s"',
+                $format
+            );
+        }
+
+        $this->configFormat = $format;
+
+        return $this;
+    }
+
+    public function isLegacy()
+    {
+        return $this->configFormat === 'v1';
+    }
+
     public function getObjectCount()
     {
         $cnt = 0;
diff --git a/library/Director/IcingaConfig/IcingaConfigFile.php b/library/Director/IcingaConfig/IcingaConfigFile.php
index d9f8960..ae5f395 100644
--- a/library/Director/IcingaConfig/IcingaConfigFile.php
+++ b/library/Director/IcingaConfig/IcingaConfigFile.php
@@ -81,6 +81,15 @@ class IcingaConfigFile
         return $this->checksum;
     }
 
+    public function addLegacyObjects($objects)
+    {
+        foreach ($objects as $object) {
+            $this->addLegacyObject($object);
+        }
+
+        return $this;
+    }
+
     public function addObjects($objects)
     {
         foreach ($objects as $object) {
@@ -94,7 +103,18 @@ class IcingaConfigFile
     {
         $this->content .= $object->toConfigString();
         $this->checksum = null;
+        return $this->addObjectStats($object);
+    }
+
+    public function addLegacyObject(IcingaObject $object)
+    {
+        $this->content .= $object->toLegacyConfigString();
+        $this->checksum = null;
+        return $this->addObjectStats($object);
+    }
 
+    protected function addObjectStats(IcingaObject $object)
+    {
         if ($object->hasProperty('object_type')) {
             $type = $object->object_type;
 



More information about the icinga-checkins mailing list