Cli: Require --zone for 'node setup'

refs #7522
This commit is contained in:
Michael Friedrich 2014-10-31 22:21:36 +01:00
parent bc83c9a698
commit 6bc2938996
4 changed files with 22 additions and 7 deletions

View File

@ -291,7 +291,7 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm,
if (!vm.count("ticket")) {
Log(LogCritical, "cli")
<< "Please pass the ticket number generated on master\n"
<< "(Hint: 'icinga2 pki ticket --cn <masterhost> --salt <ticket_salt>').";
<< "(Hint: 'icinga2 pki ticket --cn " << Utility::GetFQDN() << "').";
return 1;
}
@ -300,6 +300,11 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm,
return 1;
}
if (!vm.count("zone")) {
Log(LogCritical, "cli", "You need to specify the local zone (--zone).");
return 1;
}
String ticket = vm["ticket"].as<std::string>();
Log(LogInformation, "cli")
@ -460,7 +465,7 @@ 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> >(), cn);
NodeUtility::GenerateNodeIcingaConfig(vm["endpoint"].as<std::vector<std::string> >(), cn, vm["node"].as<std::string>());
/* update constants.conf with NodeName = CN */
if (cn != Utility::GetFQDN()) {

View File

@ -235,7 +235,7 @@ void NodeUtility::CollectNodes(const String& node_file, std::vector<Dictionary::
* Node Setup helpers
*/
int NodeUtility::GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints, const String& nodename)
int NodeUtility::GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints, const String& nodename, const String& zonename)
{
Array::Ptr my_config = make_shared<Array>();

View File

@ -57,7 +57,7 @@ public:
static void UpdateConstant(const String& name, const String& value);
/* node setup helpers */
static int GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints, const String& nodename);
static int GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints, const String& nodename, const String& zonename);
static int GenerateNodeMasterIcingaConfig(const String& nodename);
/* black/whitelist */

View File

@ -126,6 +126,17 @@ int NodeWizardCommand::Run(const boost::program_options::variables_map& vm, cons
String cn = answer;
cn.Trim();
std::cout << "Please specifiy the local zone name [" << cn << "]: ";
std::getline(std::cin, answer);
boost::algorithm::to_lower(answer);
if (answer.empty())
answer = cn;
String local_zone = answer;
local_zone.Trim();
std::vector<std::string> endpoints;
String endpoint_buffer;
@ -160,7 +171,7 @@ wizard_endpoint_loop_start:
master_endpoint_name = tmp; //store the endpoint name for later
}
std::cout << "Master endpoint port: ";
std::cout << "Master endpoint port (optional) []: ";
std::getline(std::cin, answer);
boost::algorithm::to_lower(answer);
@ -171,7 +182,6 @@ wizard_endpoint_loop_start:
endpoint_buffer += "," + answer;
}
endpoints.push_back(endpoint_buffer);
std::cout << "Add more master endpoints? [y/N]";
@ -388,7 +398,7 @@ wizard_ticket:
/* apilistener config */
std::cout << "Generating local zones.conf.\n";
NodeUtility::GenerateNodeIcingaConfig(endpoints, cn);
NodeUtility::GenerateNodeIcingaConfig(endpoints, cn, local_zone);
if (cn != Utility::GetFQDN()) {
Log(LogWarning, "cli")