mirror of https://github.com/Icinga/icinga2.git
Cli: Add repository add --{zone,template} support for repo objects
refs #7255
This commit is contained in:
parent
7f0ced592c
commit
27b15a5714
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in New Issue