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