mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-29 16:54:06 +02:00
IcingaConfig: use new deployment rules
This commit is contained in:
parent
313ac50f81
commit
bc042fc5b1
@ -358,7 +358,8 @@ throw $e;
|
|||||||
$class = 'Icinga\\Module\\Director\\Objects\\Icinga' . ucfirst($type);
|
$class = 'Icinga\\Module\\Director\\Objects\\Icinga' . ucfirst($type);
|
||||||
$objects = $class::loadAll($this->connection);
|
$objects = $class::loadAll($this->connection);
|
||||||
if (empty($objects)) return $this;
|
if (empty($objects)) return $this;
|
||||||
$ourGlobalZone = 'director-global';
|
$masterZone = $this->getMasterZoneName();
|
||||||
|
$globalZone = $this->getGlobalZoneName();
|
||||||
$file = null;
|
$file = null;
|
||||||
|
|
||||||
foreach ($objects as $object) {
|
foreach ($objects as $object) {
|
||||||
@ -369,25 +370,42 @@ throw $e;
|
|||||||
continue;
|
continue;
|
||||||
} elseif ($object->isTemplate()) {
|
} elseif ($object->isTemplate()) {
|
||||||
$filename = strtolower($type) . '_templates';
|
$filename = strtolower($type) . '_templates';
|
||||||
$zone = $ourGlobalZone;
|
|
||||||
} else {
|
} else {
|
||||||
$filename = strtolower($type) . 's';
|
$filename = strtolower($type) . 's';
|
||||||
$zone = $ourGlobalZone;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Zones get special handling
|
||||||
if ($type === 'zone') {
|
if ($type === 'zone') {
|
||||||
$this->zoneMap[$object->id] = $object->object_name;
|
$this->zoneMap[$object->id] = $object->object_name;
|
||||||
|
// If the zone has a parent zone...
|
||||||
|
if ($object->parent_id) {
|
||||||
|
// ...we render the zone object to the parent zone
|
||||||
|
$zone = $object->parent;
|
||||||
|
} elseif ($object->is_global === 'y') {
|
||||||
|
// ...additional global zones are rendered to our global zone...
|
||||||
|
$zone = $globalZone;
|
||||||
|
} else {
|
||||||
|
// ...and all the other zones are rendered to our master zone
|
||||||
|
$zone = $masterZone;
|
||||||
|
}
|
||||||
|
// Zone definitions for all other objects are respected...
|
||||||
} elseif ($object->hasProperty('zone_id') && ($zone_id = $object->zone_id)) {
|
} elseif ($object->hasProperty('zone_id') && ($zone_id = $object->zone_id)) {
|
||||||
$zone = $this->getZoneName($zone_id);
|
$zone = $this->getZoneName($zone_id);
|
||||||
|
// ...and if there is no zone defined, special rules take place
|
||||||
} else {
|
} else {
|
||||||
$zone = $ourGlobalZone;
|
if ($this->typeWantsMasterZone($type)) {
|
||||||
|
$zone = $masterZone;
|
||||||
|
} elseif ($this->typeWantsGlobalZone($type)) {
|
||||||
|
$zone = $globalZone;
|
||||||
|
} else {
|
||||||
|
throw new ProgrammingError(
|
||||||
|
'I have no idea of how to deploy a "%s" object',
|
||||||
|
$type
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($type, array('command', 'zone'))) {
|
$filename = 'zones.d/' . $zone . '/' . $filename;
|
||||||
$filename = 'zones.d/' . $ourGlobalZone . '/' . $filename;
|
|
||||||
} else {
|
|
||||||
$filename = 'zones.d/' . $zone . '/' . $filename;
|
|
||||||
}
|
|
||||||
$file = $this->configFile($filename);
|
$file = $this->configFile($filename);
|
||||||
$file->addObject($object);
|
$file->addObject($object);
|
||||||
}
|
}
|
||||||
@ -398,6 +416,42 @@ throw $e;
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function typeWantsGlobalZone($type)
|
||||||
|
{
|
||||||
|
$types = array(
|
||||||
|
'command',
|
||||||
|
);
|
||||||
|
|
||||||
|
return in_array($type, $types);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function typeWantsMasterZone($type)
|
||||||
|
{
|
||||||
|
$types = array(
|
||||||
|
'host',
|
||||||
|
'hostGroup',
|
||||||
|
'service',
|
||||||
|
'serviceGroup',
|
||||||
|
'endpoint',
|
||||||
|
'user',
|
||||||
|
'userGroup',
|
||||||
|
'timeperiod',
|
||||||
|
'notification'
|
||||||
|
);
|
||||||
|
|
||||||
|
return in_array($type, $types);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getMasterZoneName()
|
||||||
|
{
|
||||||
|
return 'master';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getGlobalZoneName()
|
||||||
|
{
|
||||||
|
return 'director-global';
|
||||||
|
}
|
||||||
|
|
||||||
protected function configFile($name, $suffix = '.conf')
|
protected function configFile($name, $suffix = '.conf')
|
||||||
{
|
{
|
||||||
$filename = $name . $suffix;
|
$filename = $name . $suffix;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user