Unify setting the master zone name for 'node wizard|setup` in master mode

This commit is contained in:
Michael Friedrich 2018-04-06 17:29:37 +02:00
parent d784a2a899
commit abdc479d6a
4 changed files with 36 additions and 8 deletions

View File

@ -129,6 +129,15 @@ int NodeSetupCommand::SetupMaster(const boost::program_options::variables_map& v
if (vm.count("cn"))
cn = vm["cn"].as<std::string>();
/* Setup command hardcodes this as FQDN */
String endpointName = cn;
/* Allow to specify zone name. */
String zoneName = "master";
if (vm.count("zone"))
zoneName = vm["zone"].as<std::string>();
/* check whether the user wants to generate a new certificate or not */
String existingPath = ApiListener::GetCertsDir() + "/" + cn + ".crt";
@ -174,9 +183,10 @@ int NodeSetupCommand::SetupMaster(const boost::program_options::variables_map& v
globalZones.insert(globalZones.end(), setupGlobalZones.begin(), setupGlobalZones.end());
NodeUtility::GenerateNodeMasterIcingaConfig(globalZones);
/* Generate master configuration. */
NodeUtility::GenerateNodeMasterIcingaConfig(endpointName, zoneName, globalZones);
/* update the ApiListener config - SetupMaster() will always enable it */
/* Update the ApiListener config. */
Log(LogInformation, "cli", "Updating the APIListener feature.");
String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";

View File

@ -124,20 +124,21 @@ int NodeUtility::GenerateNodeIcingaConfig(const std::vector<std::string>& endpoi
return 0;
}
int NodeUtility::GenerateNodeMasterIcingaConfig(const std::vector<String>& globalZones)
int NodeUtility::GenerateNodeMasterIcingaConfig(const String& endpointName, const String& zoneName,
const std::vector<String>& globalZones)
{
Array::Ptr my_config = new Array();
/* store the local generated node master configuration */
my_config->Add(new Dictionary({
{ "__name", new ConfigIdentifier("NodeName") },
{ "__name", endpointName },
{ "__type", "Endpoint" }
}));
my_config->Add(new Dictionary({
{ "__name", new ConfigIdentifier("ZoneName") },
{ "__name", zoneName },
{ "__type", "Zone" },
{ "endpoints", new Array({ new ConfigIdentifier("NodeName") }) }
{ "endpoints", new Array({ endpointName }) }
}));
for (const String& globalzone : globalZones) {

View File

@ -47,7 +47,8 @@ public:
/* node setup helpers */
static int GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints, const std::vector<String>& globalZones);
static int GenerateNodeMasterIcingaConfig(const std::vector<String>& globalZones);
static int GenerateNodeMasterIcingaConfig(const String& endpointName, const String& zoneName,
const std::vector<String>& globalZones);
private:
NodeUtility();

View File

@ -623,6 +623,7 @@ int NodeWizardCommand::MasterSetup() const
std::cout << ConsoleColorTag(Console_Bold)
<< "Generating master configuration for Icinga 2.\n"
<< ConsoleColorTag(Console_Normal);
ApiSetupUtility::SetupMasterApiUser();
if (!FeatureUtility::CheckFeatureEnabled("api"))
@ -630,6 +631,20 @@ int NodeWizardCommand::MasterSetup() const
else
std::cout << "'api' feature already enabled.\n";
/* Setup command hardcodes this as FQDN */
String endpointName = cn;
/* Different zone name. */
std::cout << "\nMaster zone name [master]: ";
std::getline(std::cin, answer);
if (answer.empty())
answer = "master";
String zoneName = answer;
zoneName = zoneName.Trim();
/* Global zones. */
std::vector<String> globalZones { "global-templates", "director-global" };
std::cout << "\nDo you want to specify additional global zones? [y/N]: ";
@ -671,7 +686,8 @@ wizard_global_zone_loop_start:
} else
Log(LogInformation, "cli", "No additional global Zones have been specified");
NodeUtility::GenerateNodeMasterIcingaConfig(globalZones);
/* Generate master configuration. */
NodeUtility::GenerateNodeMasterIcingaConfig(endpointName, zoneName, globalZones);
/* apilistener config */
std::cout << ConsoleColorTag(Console_Bold)