KickstartForm: catch errors gracefully...

...and provide better documentation
This commit is contained in:
Thomas Gelf 2016-03-07 01:10:56 +01:00
parent e3699ac294
commit 73eced1b11
1 changed files with 34 additions and 7 deletions

View File

@ -2,6 +2,7 @@
namespace Icinga\Module\Director\Forms;
use Exception;
use Icinga\Module\Director\KickstartHelper;
use Icinga\Module\Director\Web\Form\QuickForm;
@ -20,38 +21,64 @@ class KickstartForm extends QuickForm
$this->addElement('text', 'endpoint', array(
'label' => $this->translate('Endpoint Name'),
'description' => $this->translate(
'This is the name of the Endpoint object (and certificate name) you'
. ' created for your ApiListener object. In case you are unsure what'
. ' this means please make sure to read the documentation first'
),
'required' => true,
));
$this->addElement('text', 'host', array(
'label' => $this->translate('Icinga Host'),
'description' => $this->translate('IP address / hostname of remote node'),
'required' => true,
'description' => $this->translate(
'IP address / hostname of your Icinga node. Please note that this'
. ' information will only be used for the very first connection to'
. ' your Icinga instance. The Director then relies on a correctly'
. ' configured Endpoint object. Correctly configures means that either'
. ' it\'s name is resolvable or that it\'s host property contains'
. ' either an IP address or a resolvable host name. Your Director must'
. ' be able to reach this endpoint'
),
'required' => false,
));
$this->addElement('text', 'port', array(
'label' => $this->translate('Port'),
'value' => '5665',
'description' => $this->translate('The port your '),
'required' => true,
'description' => $this->translate(
'The port you are going to use. The default port 5665 will be used'
. ' if none is set'
),
'required' => false,
));
$this->addElement('text', 'username', array(
'label' => $this->translate('API user'),
'description' => $this->translate(
'Your Icinga 2 API username'
),
'required' => true,
));
$this->addElement('password', 'password', array(
'label' => $this->translate('Password'),
'description' => $this->translate(
'The corresponding password'
),
'required' => true,
));
}
public function onSuccess()
{
$kickstart = new KickstartHelper($this->db);
$kickstart->setConfig($this->getValues())->run();
parent::onSuccess();
try {
$kickstart = new KickstartHelper($this->db);
$kickstart->setConfig($this->getValues())->run();
parent::onSuccess();
} catch (Exception $e) {
$this->getElement('endpoint')->addError($e->getMessage());
}
}
public function setDb($db)