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.
This commit is contained in:
Michael 2017-11-15 18:42:29 +01:00 committed by Gunnar Beutner
parent 91241e5f46
commit a0aa781417
2 changed files with 132 additions and 5 deletions

View File

@ -64,7 +64,8 @@ void NodeSetupCommand::InitParameters(boost::program_options::options_descriptio
("cn", po::value<std::string>(), "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<std::vector<String> >(), "The names of the additional global zones.");
hiddenDesc.add_options()
("master_zone", po::value<std::string>(), "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<String> globalZones;
std::vector<String> setupGlobalZones;
if (vm.count("global_zones"))
setupGlobalZones = vm["global_zones"].as<std::vector<String> >();
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<std::vector<std::string> >(), { "global-templates", "director-global" });
std::vector<String> globalZones;
std::vector<String> setupGlobalZones;
if (vm.count("global_zones"))
setupGlobalZones = vm["global_zones"].as<std::vector<String> >();
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<std::vector<std::string> >(), globalZones);
/* update constants.conf with NodeName = CN */
if (cn != Utility::GetFQDN()) {

View File

@ -499,7 +499,51 @@ wizard_ticket:
/* apilistener config */
Log(LogInformation, "cli", "Generating local zones.conf.");
NodeUtility::GenerateNodeIcingaConfig(endpoints, { "global-templates", "director-global" });
std::vector<String> 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<String> 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)