IcingaConfig(Legacy): Add deployment mode for Icinga 1 config

refs #13049
This commit is contained in:
Markus Frosch 2016-11-04 10:28:11 +01:00
parent 4f2dbdf5e8
commit 003a100b9c
4 changed files with 52 additions and 13 deletions

View File

@ -84,7 +84,6 @@ class SettingsForm extends QuickForm
array(
'v2' => $this->translate('Icinga v2.x'),
'v1' => $this->translate('Icinga v1.x'),
// Hiding for now 'v1-masterless' => $this->translate('Icinga v1.x (no master)'),
)
),
'description' => $this->translate(
@ -96,6 +95,24 @@ class SettingsForm extends QuickForm
'value' => $settings->getStoredValue('config_format')
));
if ($settings->getStoredValue('config_format') === 'v1') {
$this->addElement('select', 'deployment_mode_v1', array(
'label' => $this->translate('Deployment mode'),
'multiOptions' => $this->eventuallyConfiguredEnum(
'deployment_mode_v1',
array(
'active-passive' => $this->translate('Active-Passive'),
'masterless' => $this->translate('Master-less'),
)
),
'description' => $this->translate(
'Deployment mode for Icinga 1 configuration'
),
'value' => $settings->getStoredValue('deployment_mode_v1')
));
}
$this->setSubmitLabel($this->translate('Store'));
}

View File

@ -38,6 +38,8 @@ class IcingaConfig
protected $configFormat;
protected $deploymentModeV1;
public static $table = 'director_generated_config';
public function __construct(Db $connection)
@ -48,6 +50,7 @@ class IcingaConfig
$this->connection = $connection;
$this->db = $connection->getDbAdapter();
$this->configFormat = $this->connection->settings()->config_format;
$this->deploymentModeV1 = $this->connection->settings()->deployment_mode_v1;
}
public function getSize()
@ -74,6 +77,16 @@ class IcingaConfig
return $this->configFormat;
}
public function getDeploymentMode()
{
if ($this->isLegacy()) {
return $this->deploymentModeV1;
}
else {
throw new ProgrammingError('There is no deployment mode for Icinga 2 config format!');
}
}
public function setConfigFormat($format)
{
if (! in_array($format, array('v1', 'v2'))) {
@ -90,7 +103,7 @@ class IcingaConfig
public function isLegacy()
{
return strpos($this->configFormat, 'v1') === 0;
return $this->configFormat === 'v1';
}
public function getObjectCount()

View File

@ -1479,18 +1479,26 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
$filename = $this->getRenderingFilename();
if (
$this->getResolvedProperty('zone_id')
&& array_key_exists('enable_active_checks', $this->defaultProperties)
&& $config->getConfigFormat() !== 'v1-masterless'
) {
$passive = clone($this);
$passive->enable_active_checks = false;
$deploymentMode = $config->getDeploymentMode();
if ($deploymentMode === 'active-passive') {
if (
$this->getResolvedProperty('zone_id')
&& array_key_exists('enable_active_checks', $this->defaultProperties)
) {
$passive = clone($this);
$passive->enable_active_checks = false;
$config->configFile(
'director/master/' . $filename,
'.cfg'
)->addLegacyObject($passive);
$config->configFile(
'director/master/' . $filename,
'.cfg'
)->addLegacyObject($passive);
}
}
elseif ($deploymentMode === 'masterless') {
// no additional config
}
else {
throw new ProgrammingError('Unsupported deployment mode: %s' .$deploymentMode);
}
$config->configFile(

View File

@ -18,6 +18,7 @@ class Settings
'override_services_templatename' => 'host var overrides (Director)',
'disable_all_jobs' => 'n', // 'y'
'enable_audit_log' => 'n',
'deployment_mode_v1' => 'active-passive',
// 'experimental_features' => null, // 'allow'
// 'master_zone' => null,
);