parent
28320fe6bb
commit
cdcf99592b
|
@ -16,26 +16,26 @@ class ServiceCommand extends ObjectCommand
|
|||
|
||||
protected function load($name)
|
||||
{
|
||||
return parent::load($this->makeServiceKey($this->getName()));
|
||||
return parent::load($this->makeServiceKey($name));
|
||||
}
|
||||
|
||||
protected function exists($name)
|
||||
{
|
||||
return parent::exists($this->makeServiceKey($this->getName()));
|
||||
return parent::exists($this->makeServiceKey($name));
|
||||
}
|
||||
|
||||
protected function makeServiceKey($name)
|
||||
{
|
||||
if ($host = $this->params->get('host')) {
|
||||
return array(
|
||||
return [
|
||||
'object_name' => $name,
|
||||
'host_id' => IcingaHost::load($host, $this->db())->get('id'),
|
||||
);
|
||||
];
|
||||
} else {
|
||||
return array(
|
||||
return [
|
||||
'object_name' => $name,
|
||||
'object_type' => 'template',
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Icinga\Module\Director\Cli;
|
||||
|
||||
use Icinga\Cli\Command as CliCommand;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Module\Director\Application\MemoryLimit;
|
||||
use Icinga\Module\Director\Core\CoreApi;
|
||||
use Icinga\Module\Director\Db;
|
||||
|
@ -19,13 +20,14 @@ class Command extends CliCommand
|
|||
|
||||
protected function renderJson($object, $pretty = true)
|
||||
{
|
||||
if ($pretty && version_compare(PHP_VERSION, '5.4.0') >= 0) {
|
||||
return json_encode($object, JSON_PRETTY_PRINT) . "\n";
|
||||
} else {
|
||||
return json_encode($object) . "\n";
|
||||
}
|
||||
return json_encode($object, $pretty ? JSON_PRETTY_PRINT : null) . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $json
|
||||
* @return mixed
|
||||
* @throws \Icinga\Exception\IcingaException
|
||||
*/
|
||||
protected function parseJson($json)
|
||||
{
|
||||
$res = json_decode($json);
|
||||
|
@ -59,6 +61,12 @@ class Command extends CliCommand
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $endpointName
|
||||
* @return CoreApi|\Icinga\Module\Director\Core\LegacyDeploymentApi
|
||||
* @throws \Icinga\Exception\IcingaException
|
||||
* @throws \Icinga\Exception\NotFoundError
|
||||
*/
|
||||
protected function api($endpointName = null)
|
||||
{
|
||||
if ($this->api === null) {
|
||||
|
@ -95,6 +103,7 @@ class Command extends CliCommand
|
|||
|
||||
/**
|
||||
* @return Db
|
||||
* @throws ConfigurationError
|
||||
*/
|
||||
protected function db()
|
||||
{
|
||||
|
@ -109,7 +118,7 @@ class Command extends CliCommand
|
|||
if ($resourceName) {
|
||||
$this->db = Db::fromResourceName($resourceName);
|
||||
} else {
|
||||
$this->fail('Director is not configured correctly');
|
||||
throw new ConfigurationError('Director is not configured correctly');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Cli;
|
|||
|
||||
use Icinga\Exception\MissingParameterException;
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class ObjectCommand extends Command
|
||||
{
|
||||
|
@ -107,7 +108,7 @@ class ObjectCommand extends Command
|
|||
}
|
||||
|
||||
if (! array_key_exists('object_name', $props)) {
|
||||
$this->fail('Cannot creat an object with at least an object name');
|
||||
$this->fail('Cannot create an object with at least an object name');
|
||||
}
|
||||
|
||||
$object = IcingaObject::createByType(
|
||||
|
@ -396,7 +397,7 @@ class ObjectCommand extends Command
|
|||
if ($this->name === null) {
|
||||
$name = $this->params->shift();
|
||||
if (! $name) {
|
||||
$this->fail('Object name parameter is required');
|
||||
throw new InvalidArgumentException('Object name parameter is required');
|
||||
}
|
||||
|
||||
$this->name = $name;
|
||||
|
|
Loading…
Reference in New Issue