Cli: Add endpoint & zone repository object for 'agent update-config'

refs #7248
This commit is contained in:
Michael Friedrich 2014-10-28 10:54:29 +01:00
parent 3c5645c730
commit 00652f603c
2 changed files with 33 additions and 3 deletions

View File

@ -74,6 +74,7 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
BOOST_FOREACH(const Dictionary::Ptr& agent, AgentUtility::GetAgents()) {
Dictionary::Ptr repository = agent->Get("repository");
String zone = agent->Get("zone");
String endpoint = agent->Get("endpoint");
ObjectLock olock(repository);
BOOST_FOREACH(const Dictionary::Pair& kv, repository) {
@ -107,6 +108,35 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
}
}
}
/* write a new zone and endpoint for the agent */
Dictionary::Ptr endpoint_attrs = make_shared<Dictionary>();
Dictionary::Ptr settings = agent->Get("settings");
if (settings) {
if (settings->Contains("host"))
endpoint_attrs->Set("host", settings->Get("host"));
if (settings->Contains("port"))
endpoint_attrs->Set("port", settings->Get("port"));
}
if (!RepositoryUtility::AddObject(endpoint, "Endpoint", endpoint_attrs)) {
Log(LogCritical, "cli")
<< "Cannot add agent endpoint '" << endpoint << "' to the config repository!\n";
}
Dictionary::Ptr zone_attrs = make_shared<Dictionary>();
Array::Ptr zone_members = make_shared<Array>();
zone_members->Add(endpoint);
zone_attrs->Set("endpoints", zone_members);
zone_attrs->Set("parent", agent->Get("parent_zone"));
if (!RepositoryUtility::AddObject(zone, "Zone", zone_attrs)) {
Log(LogCritical, "cli")
<< "Cannot add agent zone '" << zone << "' to the config repository!\n";
}
}
Log(LogInformation, "cli", "Committing agent configuration.");

View File

@ -84,7 +84,7 @@ String RepositoryUtility::GetRepositoryObjectConfigPath(const String& type, cons
path += "hosts/" + object->Get("host_name");
else if (type == "Zone")
path += "zones";
else if (type == "Endpoints")
else if (type == "Endpoint")
path += "endpoints";
return path;
@ -181,7 +181,7 @@ void RepositoryUtility::PrintChangeLog(std::ostream& fp)
bool RepositoryUtility::AddObject(const String& name, const String& type, const Dictionary::Ptr& attrs)
{
/* add a new changelog entry by timestamp */
String path = GetRepositoryChangeLogPath() + "/" + Convert::ToString(static_cast<long>(Utility::GetTime())) + "-" + SHA256(name) + ".change";
String path = GetRepositoryChangeLogPath() + "/" + Convert::ToString(Utility::GetTime()) + "-" + type + "-" + SHA256(name) + ".change";
Dictionary::Ptr change = make_shared<Dictionary>();
@ -197,7 +197,7 @@ bool RepositoryUtility::AddObject(const String& name, const String& type, const
bool RepositoryUtility::RemoveObject(const String& name, const String& type, const Dictionary::Ptr& attrs)
{
/* add a new changelog entry by timestamp */
String path = GetRepositoryChangeLogPath() + "/" + Convert::ToString(static_cast<long>(Utility::GetTime())) + "-" + SHA256(name) + ".change";
String path = GetRepositoryChangeLogPath() + "/" + Convert::ToString(Utility::GetTime()) + "-" + type + "-" + SHA256(name) + ".change";
Dictionary::Ptr change = make_shared<Dictionary>();