Skip to content

Commit

Permalink
Cli: Add endpoint & zone repository object for 'agent update-config'
Browse files Browse the repository at this point in the history
refs #7248
  • Loading branch information
Michael Friedrich committed Oct 28, 2014
1 parent 3c5645c commit 00652f6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
30 changes: 30 additions & 0 deletions lib/cli/agentupdateconfigcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.");
Expand Down
6 changes: 3 additions & 3 deletions lib/cli/repositoryutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>();

Expand All @@ -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>();

Expand Down

0 comments on commit 00652f6

Please sign in to comment.