Merge pull request #5710 from mcktr/feature/add-global-zones-during-wizard

Include default global zones during node wizard/setup
This commit is contained in:
Michael Friedrich 2017-10-31 12:24:16 +01:00 committed by GitHub
commit 3cb92bb900
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 8 deletions

View File

@ -159,7 +159,12 @@ int NodeSetupCommand::SetupMaster(const boost::program_options::variables_map& v
/* write zones.conf and update with zone + endpoint information */
Log(LogInformation, "cli", "Generating zone and object configuration.");
NodeUtility::GenerateNodeMasterIcingaConfig();
std::vector<String> globalZones;
globalZones.push_back("global-templates");
globalZones.push_back("director-global");
NodeUtility::GenerateNodeMasterIcingaConfig(globalZones);
/* update the ApiListener config - SetupMaster() will always enable it */
Log(LogInformation, "cli", "Updating the APIListener feature.");
@ -419,7 +424,12 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm,
Log(LogInformation, "cli", "Generating zone and object configuration.");
NodeUtility::GenerateNodeIcingaConfig(vm["endpoint"].as<std::vector<std::string> >());
std::vector<String> globalZones;
globalZones.push_back("global-templates");
globalZones.push_back("director-global");
NodeUtility::GenerateNodeIcingaConfig(vm["endpoint"].as<std::vector<std::string> >(), globalZones);
/* update constants.conf with NodeName = CN */
if (cn != Utility::GetFQDN()) {

View File

@ -47,7 +47,7 @@ using namespace icinga;
* Node Setup helpers
*/
int NodeUtility::GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints)
int NodeUtility::GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints, const std::vector<String>& globalZones)
{
Array::Ptr my_config = new Array();
@ -111,6 +111,16 @@ int NodeUtility::GenerateNodeIcingaConfig(const std::vector<std::string>& endpoi
my_zone->Set("endpoints", my_zone_members);
for (const String& globalzone : globalZones) {
Dictionary::Ptr myGlobalZone = new Dictionary();
myGlobalZone->Set("__name", globalzone);
myGlobalZone->Set("__type", "Zone");
myGlobalZone->Set("global", true);
my_config->Add(myGlobalZone);
}
/* store the local config */
my_config->Add(my_endpoint);
my_config->Add(my_zone);
@ -123,13 +133,14 @@ int NodeUtility::GenerateNodeIcingaConfig(const std::vector<std::string>& endpoi
return 0;
}
int NodeUtility::GenerateNodeMasterIcingaConfig(void)
int NodeUtility::GenerateNodeMasterIcingaConfig(const std::vector<String>& globalZones)
{
Array::Ptr my_config = new Array();
/* store the local generated node master configuration */
Dictionary::Ptr my_master_endpoint = new Dictionary();
Dictionary::Ptr my_master_zone = new Dictionary();
Array::Ptr my_master_zone_members = new Array();
my_master_endpoint->Set("__name", new ConfigIdentifier("NodeName"));
@ -145,6 +156,16 @@ int NodeUtility::GenerateNodeMasterIcingaConfig(void)
my_config->Add(my_master_endpoint);
my_config->Add(my_master_zone);
for (const String& globalzone : globalZones) {
Dictionary::Ptr myGlobalZone = new Dictionary();
myGlobalZone->Set("__name", globalzone);
myGlobalZone->Set("__type", "Zone");
myGlobalZone->Set("global", true);
my_config->Add(myGlobalZone);
}
/* write the newly generated configuration */
String zones_path = Application::GetSysconfDir() + "/icinga2/zones.conf";

View File

@ -44,8 +44,8 @@ public:
static void UpdateConstant(const String& name, const String& value);
/* node setup helpers */
static int GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints);
static int GenerateNodeMasterIcingaConfig(void);
static int GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints, const std::vector<String>& globalZones);
static int GenerateNodeMasterIcingaConfig(const std::vector<String>& globalZones);
private:
NodeUtility(void);

View File

@ -498,7 +498,12 @@ wizard_ticket:
/* apilistener config */
Log(LogInformation, "cli", "Generating local zones.conf.");
NodeUtility::GenerateNodeIcingaConfig(endpoints);
std::vector<String> globalZones;
globalZones.push_back("global-templates");
globalZones.push_back("director-global");
NodeUtility::GenerateNodeIcingaConfig(endpoints, globalZones);
if (cn != Utility::GetFQDN()) {
Log(LogWarning, "cli")
@ -594,7 +599,12 @@ int NodeWizardCommand::MasterSetup(void) const
else
std::cout << "'api' feature already enabled.\n";
NodeUtility::GenerateNodeMasterIcingaConfig();
std::vector<String> globalZones;
globalZones.push_back("global-templates");
globalZones.push_back("director-global");
NodeUtility::GenerateNodeMasterIcingaConfig(globalZones);
/* apilistener config */
std::cout << ConsoleColorTag(Console_Bold)