[icinga-checkins] icinga.org: icingaweb2-module-director/master: kickstart: add new route / kickstart allowing one...

git at icinga.org git at icinga.org
Mon Oct 31 09:35:11 CET 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Mon Oct 31 08:34:26 2016 +0000

kickstart: add new route /kickstart allowing one...

...to re-run the kickstart wizard

fixes #13014

---

 application/controllers/KickstartController.php |   18 ++++++++++
 application/forms/KickstartForm.php             |   42 ++++++++++++++++++++---
 application/views/scripts/kickstart/index.phtml |   15 ++++++++
 3 files changed, 70 insertions(+), 5 deletions(-)

diff --git a/application/controllers/KickstartController.php b/application/controllers/KickstartController.php
new file mode 100644
index 0000000..e665aa1
--- /dev/null
+++ b/application/controllers/KickstartController.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace Icinga\Module\Director\Controllers;
+
+use Exception;
+use Icinga\Module\Director\Db\Migrations;
+
+class KickstartController extends DashboardController
+{
+    public function indexAction()
+    {
+        $this->singleTab($this->view->title = $this->translate('Kickstart'));
+        $this->view->form = $this
+            ->loadForm('kickstart')
+            ->setEndpoint($this->db()->getDeploymentEndpoint())
+            ->handleRequest();
+    }
+}
diff --git a/application/forms/KickstartForm.php b/application/forms/KickstartForm.php
index b1da43c..c829856 100644
--- a/application/forms/KickstartForm.php
+++ b/application/forms/KickstartForm.php
@@ -7,18 +7,22 @@ use Icinga\Application\Config;
 use Icinga\Data\ResourceFactory;
 use Icinga\Module\Director\Db;
 use Icinga\Module\Director\Db\Migrations;
+use Icinga\Module\Director\Objects\IcingaEndpoint;
 use Icinga\Module\Director\KickstartHelper;
 use Icinga\Module\Director\Web\Form\QuickForm;
 
 class KickstartForm extends QuickForm
 {
-    protected $config;
+    private $config;
 
-    protected $storeConfigLabel;
+    private $storeConfigLabel;
 
-    protected $createDbLabel;
+    private $createDbLabel;
 
-    protected $migrateDbLabel;
+    private $migrateDbLabel;
+
+    /** @var IcingaEndpoint */
+    private $endpoint;
 
     public function setup()
     {
@@ -56,7 +60,7 @@ class KickstartForm extends QuickForm
             return;
         }
 
-        if ($this->getDb()->hasDeploymentEndpoint()) {
+        if (! $this->endpoint && $this->getDb()->hasDeploymentEndpoint()) {
             $hint = sprintf($this->translate(
                 'Your database looks good, you are ready to %s'
             ), $this->getView()->qlink(
@@ -136,6 +140,24 @@ class KickstartForm extends QuickForm
             'required'    => true,
         ));
 
+        if ($ep = $this->endpoint) {
+            $user = $ep->getApiUser();
+            $this->setDefaults(array(
+                'endpoint' => $ep->object_name,
+                'host'     => $ep->host,
+                'port'     => $ep->port,
+                'username' => $user->object_name,
+                'password' => $user->password,
+            ));
+
+            if (! empty($user->password)) {
+                $this->getElement('password')->setAttrib(
+                    'placeholder',
+                    '(use stored password)'
+                )->setRequired(false);
+            }
+        }
+
         $this->addKickstartDisplayGroup();
         $this->setSubmitLabel($this->translate('Run import'));
     }
@@ -288,6 +310,12 @@ class KickstartForm extends QuickForm
         }
     }
 
+    public function setEndpoint(IcingaEndpoint $endpoint)
+    {
+        $this->endpoint = $endpoint;
+        return $this;
+    }
+
     public function onSuccess()
     {
         try {
@@ -306,6 +334,10 @@ class KickstartForm extends QuickForm
             }
 
             $values = $this->getValues();
+            if ($this->endpoint && empty($values['password'])) {
+                $values['password'] = $this->endpoint->getApiUser()->password;
+            }
+
             $kickstart = new KickstartHelper($this->getDb());
             unset($values['resource']);
             $kickstart->setConfig($values)->run();
diff --git a/application/views/scripts/kickstart/index.phtml b/application/views/scripts/kickstart/index.phtml
new file mode 100644
index 0000000..822e433
--- /dev/null
+++ b/application/views/scripts/kickstart/index.phtml
@@ -0,0 +1,15 @@
+<div class="controls">
+<?= $this->tabs ?>
+<h1><?= $this->escape($this->title) ?><?php
+if ($this->subtitle) {
+    echo ' <small>' . $this->escape($this->subtitle) . '</small>';
+}
+?></h1>
+<span class="action-links">
+<?= $this->actionLinks ?>
+</span>
+</div>
+
+<div class="content">
+<?= $this->form ?>
+</div>



More information about the icinga-checkins mailing list