[icinga-checkins] icinga.org: icinga2/feature/cli-global-zone-10120: Add global zone parameter to node wizard/setup cli commands

git at icinga.org git at icinga.org
Tue Aug 16 18:04:45 CEST 2016


Module: icinga2
Branch: feature/cli-global-zone-10120
Commit: f82d9cdfd60d050d69ab4b2033874685e144aa30
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=f82d9cdfd60d050d69ab4b2033874685e144aa30

Author: Tobias Birnbaum <osterd at gmx.de>
Date:   Tue Feb  2 17:02:34 2016 -0800

Add global zone parameter to node wizard/setup cli commands

Node wizard in satellite configuration mode did not ask for
global zones which had to be inserted manually into the file
by the user. Functionality was now added.

refs #10120

Signed-off-by: Michael Friedrich <michael.friedrich at netways.de>

---

 lib/cli/nodesetupcommand.cpp  |    5 +++--
 lib/cli/nodeutility.cpp       |   11 ++++++++++-
 lib/cli/nodeutility.hpp       |    2 +-
 lib/cli/nodewizardcommand.cpp |   37 ++++++++++++++++++++++++++++++++++++-
 4 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/lib/cli/nodesetupcommand.cpp b/lib/cli/nodesetupcommand.cpp
index cf185b3..4a9c555 100644
--- a/lib/cli/nodesetupcommand.cpp
+++ b/lib/cli/nodesetupcommand.cpp
@@ -59,13 +59,14 @@ void NodeSetupCommand::InitParameters(boost::program_options::options_descriptio
 	visibleDesc.add_options()
 		("zone", po::value<std::string>(), "The name of the local zone")
 		("master_host", po::value<std::string>(), "The name of the master host for auto-signing the csr")
-		("endpoint", po::value<std::vector<std::string> >(), "Connect to remote endpoint; syntax: cn[,host,port]")
+		("endpoint", po::value<std::vector<std::string> >(), "Connect to remote endpoint; syntax: cn[,host,port] (can be repeated to add more than one)")
 		("listen", po::value<std::string>(), "Listen on host,port")
 		("ticket", po::value<std::string>(), "Generated ticket number for this request")
 		("trustedcert", po::value<std::string>(), "Trusted master certificate file")
 		("cn", po::value<std::string>(), "The certificate's common name")
 		("accept-config", "Accept config from master")
 		("accept-commands", "Accept commands from master")
+		("global_zone", po::value<std::vector<std::string> >(), "Global zone name (can be repeated to add more than one)")
 		("master", "Use setup for a master instance");
 
 	hiddenDesc.add_options()
@@ -427,7 +428,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> >());
+	NodeUtility::GenerateNodeIcingaConfig(vm["endpoint"].as<std::vector<std::string> >(), vm["global_zone"].as<std::vector<std::string> >());
 
 	/* update constants.conf with NodeName = CN */
 	if (cn != Utility::GetFQDN()) {
diff --git a/lib/cli/nodeutility.cpp b/lib/cli/nodeutility.cpp
index 2bfe808..d134711 100644
--- a/lib/cli/nodeutility.cpp
+++ b/lib/cli/nodeutility.cpp
@@ -255,7 +255,7 @@ void NodeUtility::CollectNodes(const String& node_file, std::vector<Dictionary::
  * Node Setup helpers
  */
 
-int NodeUtility::GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints)
+int NodeUtility::GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints, const std::vector<std::string>& global_zones)
 {
 	Array::Ptr my_config = new Array();
 
@@ -323,6 +323,15 @@ int NodeUtility::GenerateNodeIcingaConfig(const std::vector<std::string>& endpoi
 	my_config->Add(my_endpoint);
 	my_config->Add(my_zone);
 
+	BOOST_FOREACH(const String& global_zone_name, global_zones) {
+		Dictionary::Ptr global_zone = new Dictionary();
+		global_zone->Set("__name", global_zone_name);
+		global_zone->Set("__type", "Zone");
+		global_zone->Set("global", true);
+
+		my_config->Add(global_zone);
+	}
+
 	/* write the newly generated configuration */
 	String zones_path = Application::GetSysconfDir() + "/icinga2/zones.conf";
 
diff --git a/lib/cli/nodeutility.hpp b/lib/cli/nodeutility.hpp
index b82fd6f..41027eb 100644
--- a/lib/cli/nodeutility.hpp
+++ b/lib/cli/nodeutility.hpp
@@ -59,7 +59,7 @@ public:
 	static void UpdateConstant(const String& name, const String& value);
 
 	/* node setup helpers */
-	static int GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints);
+	static int GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints, const std::vector<std::string>& global_zones);
 	static int GenerateNodeMasterIcingaConfig(void);
 
 	/* black/whitelist */
diff --git a/lib/cli/nodewizardcommand.cpp b/lib/cli/nodewizardcommand.cpp
index d592b00..38e2548 100644
--- a/lib/cli/nodewizardcommand.cpp
+++ b/lib/cli/nodewizardcommand.cpp
@@ -134,6 +134,7 @@ int NodeWizardCommand::Run(const boost::program_options::variables_map& vm,
 		String cn = answer;
 		cn = cn.Trim();
 
+		/* endpoints */
 		std::vector<std::string> endpoints;
 
 		String endpoint_buffer;
@@ -350,6 +351,40 @@ wizard_ticket:
 			    << node_cert << "'. Verify it yourself!";
 		}
 
+		/* global zones */
+		std::vector<std::string> global_zones;
+
+		String global_zones_buffer;
+
+		std::cout << ConsoleColorTag(Console_Bold)
+		    << "Please specify the global zones for this node:"
+		    << ConsoleColorTag(Console_Normal) << "\n";
+
+wizard_global_zone_loop_start:
+		std::cout << ConsoleColorTag(Console_Bold)
+		    << "Global zone name [global-templates]:" << ConsoleColorTag(Console_Normal);
+		std::getline(std::cin, answer);
+		boost::algorithm::to_lower(answer);
+
+		global_zones_buffer = answer;
+		global_zones_buffer.Trim();
+
+		if (global_zones_buffer.IsEmpty())
+			global_zones_buffer = "global-templates";
+
+		global_zones.push_back(global_zones_buffer);
+
+		std::cout << ConsoleColorTag(Console_Bold) << "Add more global zones?"
+		    << ConsoleColorTag(Console_Normal) << " [y/N]: ";
+		std::getline (std::cin, answer);
+
+		boost::algorithm::to_lower(answer);
+
+		choice = answer;
+
+		if (choice.Contains("y"))
+			goto wizard_global_zone_loop_start;
+
 		/* apilistener config */
 		std::cout << ConsoleColorTag(Console_Bold)
 		    << "Please specify the API bind host/port"
@@ -442,7 +477,7 @@ wizard_ticket:
 		/* apilistener config */
 		Log(LogInformation, "cli", "Generating local zones.conf.");
 
-		NodeUtility::GenerateNodeIcingaConfig(endpoints);
+		NodeUtility::GenerateNodeIcingaConfig(endpoints, global_zones);
 
 		if (cn != Utility::GetFQDN()) {
 			Log(LogWarning, "cli")



More information about the icinga-checkins mailing list