mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-21 20:54:35 +02:00
Unify setting the master zone name for 'node wizard|setup` in master mode
This commit is contained in:
parent
d784a2a899
commit
abdc479d6a
@ -129,6 +129,15 @@ int NodeSetupCommand::SetupMaster(const boost::program_options::variables_map& v
|
|||||||
if (vm.count("cn"))
|
if (vm.count("cn"))
|
||||||
cn = vm["cn"].as<std::string>();
|
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 */
|
/* check whether the user wants to generate a new certificate or not */
|
||||||
String existingPath = ApiListener::GetCertsDir() + "/" + cn + ".crt";
|
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());
|
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.");
|
Log(LogInformation, "cli", "Updating the APIListener feature.");
|
||||||
|
|
||||||
String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
|
String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
|
||||||
|
@ -124,20 +124,21 @@ int NodeUtility::GenerateNodeIcingaConfig(const std::vector<std::string>& endpoi
|
|||||||
return 0;
|
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();
|
Array::Ptr my_config = new Array();
|
||||||
|
|
||||||
/* store the local generated node master configuration */
|
/* store the local generated node master configuration */
|
||||||
my_config->Add(new Dictionary({
|
my_config->Add(new Dictionary({
|
||||||
{ "__name", new ConfigIdentifier("NodeName") },
|
{ "__name", endpointName },
|
||||||
{ "__type", "Endpoint" }
|
{ "__type", "Endpoint" }
|
||||||
}));
|
}));
|
||||||
|
|
||||||
my_config->Add(new Dictionary({
|
my_config->Add(new Dictionary({
|
||||||
{ "__name", new ConfigIdentifier("ZoneName") },
|
{ "__name", zoneName },
|
||||||
{ "__type", "Zone" },
|
{ "__type", "Zone" },
|
||||||
{ "endpoints", new Array({ new ConfigIdentifier("NodeName") }) }
|
{ "endpoints", new Array({ endpointName }) }
|
||||||
}));
|
}));
|
||||||
|
|
||||||
for (const String& globalzone : globalZones) {
|
for (const String& globalzone : globalZones) {
|
||||||
|
@ -47,7 +47,8 @@ public:
|
|||||||
|
|
||||||
/* node setup helpers */
|
/* node setup helpers */
|
||||||
static int GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints, const std::vector<String>& globalZones);
|
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:
|
private:
|
||||||
NodeUtility();
|
NodeUtility();
|
||||||
|
@ -623,6 +623,7 @@ int NodeWizardCommand::MasterSetup() const
|
|||||||
std::cout << ConsoleColorTag(Console_Bold)
|
std::cout << ConsoleColorTag(Console_Bold)
|
||||||
<< "Generating master configuration for Icinga 2.\n"
|
<< "Generating master configuration for Icinga 2.\n"
|
||||||
<< ConsoleColorTag(Console_Normal);
|
<< ConsoleColorTag(Console_Normal);
|
||||||
|
|
||||||
ApiSetupUtility::SetupMasterApiUser();
|
ApiSetupUtility::SetupMasterApiUser();
|
||||||
|
|
||||||
if (!FeatureUtility::CheckFeatureEnabled("api"))
|
if (!FeatureUtility::CheckFeatureEnabled("api"))
|
||||||
@ -630,6 +631,20 @@ int NodeWizardCommand::MasterSetup() const
|
|||||||
else
|
else
|
||||||
std::cout << "'api' feature already enabled.\n";
|
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::vector<String> globalZones { "global-templates", "director-global" };
|
||||||
|
|
||||||
std::cout << "\nDo you want to specify additional global zones? [y/N]: ";
|
std::cout << "\nDo you want to specify additional global zones? [y/N]: ";
|
||||||
@ -671,7 +686,8 @@ wizard_global_zone_loop_start:
|
|||||||
} else
|
} else
|
||||||
Log(LogInformation, "cli", "No additional global Zones have been specified");
|
Log(LogInformation, "cli", "No additional global Zones have been specified");
|
||||||
|
|
||||||
NodeUtility::GenerateNodeMasterIcingaConfig(globalZones);
|
/* Generate master configuration. */
|
||||||
|
NodeUtility::GenerateNodeMasterIcingaConfig(endpointName, zoneName, globalZones);
|
||||||
|
|
||||||
/* apilistener config */
|
/* apilistener config */
|
||||||
std::cout << ConsoleColorTag(Console_Bold)
|
std::cout << ConsoleColorTag(Console_Bold)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user