]> granicus.if.org Git - icinga2/commitdiff
Cli: Add repository add --{zone,template} support for repo objects
authorMichael Friedrich <michael.friedrich@netways.de>
Thu, 23 Oct 2014 17:06:02 +0000 (19:06 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Thu, 23 Oct 2014 17:08:27 +0000 (19:08 +0200)
refs #7255

lib/cli/repositoryobjectcommand.cpp
lib/cli/repositoryutility.cpp

index c8db201740a99ef3a2de0394edc8fbbe9b969939..d2524113a74c000cd92ddb181b9d248c81c433bd 100644 (file)
@@ -120,7 +120,15 @@ void RepositoryObjectCommand::InitParameters(boost::program_options::options_des
     boost::program_options::options_description& hiddenDesc) const
 {
        visibleDesc.add_options()
+               ("name", po::value<std::string>(), "The name of the object")
+               ("zone", po::value<std::string>(), "The name of the zone, e.g. the agent where this object is bound to")
+               ("template", po::value<std::string>(), "Import the defined template into the object. This template must be defined and included separately in Icinga 2")
                ("name", po::value<std::string>(), "The name of the object");
+
+       if (m_Type == "Service") {
+               visibleDesc.add_options()
+                       ("host", po::value<std::string>(), "The host name related to this service object");
+       }
 }
 
 std::vector<String> RepositoryObjectCommand::GetPositionalSuggestions(const String& word) const
@@ -164,6 +172,12 @@ int RepositoryObjectCommand::Run(const boost::program_options::variables_map& vm
                            << "Cannot parse passed attributes for object '" << name << "': " << boost::algorithm::join(tokens, "=");
        }
 
+       if (vm.count("zone"))
+               attr->Set("zone", String(vm["zone"].as<std::string>()));
+
+       if (vm.count("template"))
+               attr->Set("templates", String(vm["template"].as<std::string>()));
+
        if (m_Command == RepositoryCommandList) {
                RepositoryUtility::PrintObjects(std::cout, m_Type);
        }
index 64a807bc68abc876e48ecf2bf48cf3169c349ff7..70177f1f7d9d174fee92a7f02b2a3ea8cd08d388 100644 (file)
@@ -370,9 +370,17 @@ void RepositoryUtility::CollectChange(const Dictionary::Ptr& change, Array::Ptr&
 void RepositoryUtility::SerializeObject(std::ostream& fp, const String& name, const String& type, const Dictionary::Ptr& object)
 {
        fp << "object " << type << " \"" << name << "\" {\n";
+
+       if (object->Contains("templates"))
+               fp << "\t" << "import \"" << object->Get("templates") << "\"\n";
+
        BOOST_FOREACH(const Dictionary::Pair& kv, object) {
-               fp << "\t" << kv.first << " = ";
-               FormatValue(fp, kv.second);
+               if (kv.first == "templates") {
+                       continue;
+               } else {
+                       fp << "\t" << kv.first << " = ";
+                       FormatValue(fp, kv.second);
+               }
                fp << "\n";
        }
        fp << "}\n";