From a0aa7814176cafdd461f7087208023698a0f31a9 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 15 Nov 2017 18:42:29 +0100 Subject: [PATCH] Implement ability to make global zones configurable This adds the ability to make global zones configurable during the node wizard/setup. The implementation will add the given global zones to the default included global zones. --- lib/cli/nodesetupcommand.cpp | 45 +++++++++++++++-- lib/cli/nodewizardcommand.cpp | 92 ++++++++++++++++++++++++++++++++++- 2 files changed, 132 insertions(+), 5 deletions(-) diff --git a/lib/cli/nodesetupcommand.cpp b/lib/cli/nodesetupcommand.cpp index afb406154..480fdfc5a 100644 --- a/lib/cli/nodesetupcommand.cpp +++ b/lib/cli/nodesetupcommand.cpp @@ -64,7 +64,8 @@ void NodeSetupCommand::InitParameters(boost::program_options::options_descriptio ("cn", po::value(), "The certificate's common name") ("accept-config", "Accept config from master") ("accept-commands", "Accept commands from master") - ("master", "Use setup for a master instance"); + ("master", "Use setup for a master instance") + ("global_zones", po::value >(), "The names of the additional global zones."); hiddenDesc.add_options() ("master_zone", po::value(), "The name of the master zone"); @@ -157,7 +158,26 @@ 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({ "global-templates", "director-global" }); + std::vector globalZones; + std::vector setupGlobalZones; + + if (vm.count("global_zones")) + setupGlobalZones = vm["global_zones"].as >(); + + globalZones.push_back("global-templates"); + globalZones.push_back("director-global"); + + for (int i = 0; i < setupGlobalZones.size(); i++) { + if (std::find(globalZones.begin(), globalZones.end(), setupGlobalZones[i]) != globalZones.end()) { + Log(LogCritical, "cli") + << "The global zone '" << setupGlobalZones[i] << "' is already specified."; + return 1; + } + } + + globalZones.insert(globalZones.end(), setupGlobalZones.begin(), setupGlobalZones.end()); + + NodeUtility::GenerateNodeMasterIcingaConfig(globalZones); /* update the ApiListener config - SetupMaster() will always enable it */ Log(LogInformation, "cli", "Updating the APIListener feature."); @@ -409,7 +429,26 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm, Log(LogInformation, "cli", "Generating zone and object configuration."); - NodeUtility::GenerateNodeIcingaConfig(vm["endpoint"].as >(), { "global-templates", "director-global" }); + std::vector globalZones; + std::vector setupGlobalZones; + + if (vm.count("global_zones")) + setupGlobalZones = vm["global_zones"].as >(); + + globalZones.push_back("global-templates"); + globalZones.push_back("director-global"); + + for (int i = 0; i < setupGlobalZones.size(); i++) { + if (std::find(globalZones.begin(), globalZones.end(), setupGlobalZones[i]) != globalZones.end()) { + Log(LogCritical, "cli") + << "The global zone '" << setupGlobalZones[i] << "' is already specified."; + return 1; + } + } + + globalZones.insert(globalZones.end(), setupGlobalZones.begin(), setupGlobalZones.end()); + + NodeUtility::GenerateNodeIcingaConfig(vm["endpoint"].as >(), globalZones); /* update constants.conf with NodeName = CN */ if (cn != Utility::GetFQDN()) { diff --git a/lib/cli/nodewizardcommand.cpp b/lib/cli/nodewizardcommand.cpp index a91688644..b08dcbc31 100644 --- a/lib/cli/nodewizardcommand.cpp +++ b/lib/cli/nodewizardcommand.cpp @@ -499,7 +499,51 @@ wizard_ticket: /* apilistener config */ Log(LogInformation, "cli", "Generating local zones.conf."); - NodeUtility::GenerateNodeIcingaConfig(endpoints, { "global-templates", "director-global" }); + std::vector globalZones; + + globalZones.push_back("global-templates"); + globalZones.push_back("director-global"); + + std::cout << "\nDo you want to specify additional global zones? [y/N]: "; + + std::getline(std::cin, answer); + boost::algorithm::to_lower(answer); + choice = answer; + +wizard_global_zone_loop_start: + if (choice.Contains("y")) { + std::cout << "\nPlease specify the name of the global Zone: "; + + std::getline(std::cin, answer); + + if (answer.empty()) { + std::cout << "\nName of the global Zone is required! Please retry."; + goto wizard_global_zone_loop_start; + } + + String globalZoneName = answer; + globalZoneName = globalZoneName.Trim(); + + if (std::find(globalZones.begin(), globalZones.end(), globalZoneName) != globalZones.end()) { + std::cout << "The global zone '" << globalZoneName << "' is already specified." + << " Please retry."; + goto wizard_global_zone_loop_start; + } + + globalZones.push_back(globalZoneName); + + std::cout << "\nDo you want to specify another global zone? [y/N]: "; + + std::getline(std::cin, answer); + boost::algorithm::to_lower(answer); + choice = answer; + + if (choice.Contains("y")) + goto wizard_global_zone_loop_start; + } else + Log(LogInformation, "cli", "No additional global Zones have been specified"); + + NodeUtility::GenerateNodeIcingaConfig(endpoints, globalZones); if (cn != Utility::GetFQDN()) { Log(LogWarning, "cli") @@ -589,7 +633,51 @@ int NodeWizardCommand::MasterSetup() const else std::cout << "'api' feature already enabled.\n"; - NodeUtility::GenerateNodeMasterIcingaConfig({ "global-templates", "director-global" }); + std::vector globalZones; + + globalZones.push_back("global-templates"); + globalZones.push_back("director-global"); + + std::cout << "\nDo you want to specify additional global zones? [y/N]: "; + + std::getline(std::cin, answer); + boost::algorithm::to_lower(answer); + choice = answer; + +wizard_global_zone_loop_start: + if (choice.Contains("y")) { + std::cout << "\nPlease specify the name of the global Zone: "; + + std::getline(std::cin, answer); + + if (answer.empty()) { + std::cout << "\nName of the global Zone is required! Please retry."; + goto wizard_global_zone_loop_start; + } + + String globalZoneName = answer; + globalZoneName = globalZoneName.Trim(); + + if (std::find(globalZones.begin(), globalZones.end(), globalZoneName) != globalZones.end()) { + std::cout << "The global zone '" << globalZoneName << "' is already specified." + << " Please retry."; + goto wizard_global_zone_loop_start; + } + + globalZones.push_back(globalZoneName); + + std::cout << "\nDo you want to specify another global zone? [y/N]: "; + + std::getline(std::cin, answer); + boost::algorithm::to_lower(answer); + choice = answer; + + if (choice.Contains("y")) + goto wizard_global_zone_loop_start; + } else + Log(LogInformation, "cli", "No additional global Zones have been specified"); + + NodeUtility::GenerateNodeMasterIcingaConfig(globalZones); /* apilistener config */ std::cout << ConsoleColorTag(Console_Bold)