KickstartForm: allow endpoint/host to differ

This commit is contained in:
Thomas Gelf 2015-12-21 13:11:38 +01:00
parent 3161cae4a8
commit c162eda1ad
1 changed files with 40 additions and 9 deletions

View File

@ -20,7 +20,12 @@ class KickstartForm extends QuickForm
'Your installation of Icinga Director has not yet been prepared for deployments. This kickstart wizard will assist you with setting up the connection to your Icinga 2 server' 'Your installation of Icinga Director has not yet been prepared for deployments. This kickstart wizard will assist you with setting up the connection to your Icinga 2 server'
) )
); );
// TODO: distinct endpoint name / host
$this->addElement('text', 'endpoint', array(
'label' => $this->translate('Endpoint Name'),
'required' => true,
));
$this->addElement('text', 'host', array( $this->addElement('text', 'host', array(
'label' => $this->translate('Icinga Host'), 'label' => $this->translate('Icinga Host'),
'description' => $this->translate('IP address / hostname of remote node'), 'description' => $this->translate('IP address / hostname of remote node'),
@ -47,8 +52,10 @@ class KickstartForm extends QuickForm
public function onSuccess() public function onSuccess()
{ {
$this->importZones(); $this->importZones()
$this->importEndpoints(); ->importEndpoints()
->importCommands();
$this->apiUser()->store(); $this->apiUser()->store();
parent::onSuccess(); parent::onSuccess();
} }
@ -74,23 +81,41 @@ class KickstartForm extends QuickForm
$object->store(); $object->store();
} }
} }
return $this;
} }
protected function importEndpoints() protected function importEndpoints()
{ {
$db = $this->db; $db = $this->db;
$master = $this->getValue('host'); $master = $this->getValue('endpoint');
foreach ($this->api()->setDb($db)->getEndpointObjects() as $object) { foreach ($this->api()->setDb($db)->getEndpointObjects() as $object) {
if ($object->object_name === 'master') {
$this->apiUser()->store(); if ($object->object_name === $master) {
$object->apiuser = $this->apiUser()->object_name; $apiuser = $this->apiUser();
$apiuser->store();
$object->apiuser = $apiuser->object_name;
} }
if (! $object::exists($object->object_name, $db)) { if (! $object::exists($object->object_name, $db)) {
$object->store(); $object->store();
} }
} }
return $this;
}
protected function importCommands()
{
$db = $this->db;
foreach ($this->api()->setDb($db)->getCheckCommandObjects() as $object) {
if (! $object::exists($object->object_name, $db)) {
$object->store();
}
}
return $this;
} }
public function setDb($db) public function setDb($db)
@ -105,8 +130,14 @@ class KickstartForm extends QuickForm
protected function api() protected function api()
{ {
$client = new RestApiClient($this->getValue('host'), $this->getValue('port')); $client = new RestApiClient(
$client->setCredentials($this->apiUser()->object_name, $this->apiUser()->password); $this->getValue('host'),
$this->getValue('port')
);
$apiuser = $this->apiuser;
$client->setCredentials($apiuser->object_name, $apiuser->password);
$api = new CoreApi($client); $api = new CoreApi($client);
return $api; return $api;
} }