compatido: Update to use new *Group::GetMembers() functions

Fixes #3564
This commit is contained in:
Gunnar Beutner 2013-01-24 20:46:26 +01:00
parent bbbdb41581
commit cd30cb48c8
1 changed files with 38 additions and 69 deletions

View File

@ -737,104 +737,73 @@ void CompatIdoComponent::DumpConfigObjects(void)
m_IdoConnection->SendMessage(msgStartConfigDump.str()); m_IdoConnection->SendMessage(msgStartConfigDump.str());
/* hosts and hostgroups */ /* hosts and hostgroups */
map<String, vector<String> > hostgroups;
DynamicObject::Ptr object; DynamicObject::Ptr object;
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Host")->GetObjects()) { BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Host")->GetObjects()) {
const Host::Ptr& host = static_pointer_cast<Host>(object); const Host::Ptr& host = static_pointer_cast<Host>(object);
Dictionary::Ptr dict;
dict = host->GetGroups();
if (dict) {
Value hostgroup;
BOOST_FOREACH(tie(tuples::ignore, hostgroup), dict) {
hostgroups[hostgroup].push_back(host->GetName());
}
}
DumpHostObject(host); DumpHostObject(host);
//FIXME remove me, debug only XXX //FIXME remove me, debug only XXX
//DisableHostObject(host); //DisableHostObject(host);
} }
pair<String, vector<String > > hgt; BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("HostGroup")->GetObjects()) {
BOOST_FOREACH(hgt, hostgroups) { const HostGroup::Ptr& hg = static_pointer_cast<HostGroup>(object);
const String& name = hgt.first;
const vector<String>& hosts = hgt.second;
if (HostGroup::Exists(name)) {
HostGroup::Ptr hg = HostGroup::GetByName(name);
/* dump the hostgroup and its attributes/members to ido */ /* dump the hostgroup and its attributes/members to ido */
stringstream message; stringstream message;
message << "\n" message << "\n"
<< 401 << ":" << "\n" /* hostgroupdefinition */ << 401 << ":" << "\n" /* hostgroupdefinition */
<< 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */ << 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */
<< 172 << "=" << name << "\n" /* hostgroupname */ << 172 << "=" << hg->GetName() << "\n" /* hostgroupname */
<< 170 << "=" << hg->GetAlias() << "\n"; /* hostgroupalias */ << 170 << "=" << hg->GetAlias() << "\n"; /* hostgroupalias */
SendMessageList(message, hosts, 171); /* hostgroupmember */ vector<String> hglist;
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
hglist.push_back(host->GetName());
}
SendMessageList(message, hglist, 171); /* hostgroupmember */
message << 999 << "\n\n"; /* enddata */ message << 999 << "\n\n"; /* enddata */
m_IdoConnection->SendMessage(message.str()); m_IdoConnection->SendMessage(message.str());
} }
}
/* services and servicegroups */ /* services and servicegroups */
map<String, vector<Service::Ptr> > servicegroups;
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) { BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) {
Service::Ptr service = static_pointer_cast<Service>(object); Service::Ptr service = static_pointer_cast<Service>(object);
Dictionary::Ptr dict;
dict = service->GetGroups();
if (dict) {
Value servicegroup;
BOOST_FOREACH(tie(tuples::ignore, servicegroup), dict) {
servicegroups[servicegroup].push_back(service);
}
}
DumpServiceObject(service); DumpServiceObject(service);
//FIXME remove me, debug only XXX //FIXME remove me, debug only XXX
//DisableServiceObject(service); //DisableServiceObject(service);
} }
pair<String, vector<Service::Ptr> > sgt; BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("ServiceGroup")->GetObjects()) {
BOOST_FOREACH(sgt, servicegroups) { const ServiceGroup::Ptr& sg = static_pointer_cast<ServiceGroup>(object);
const String& name = sgt.first;
const vector<Service::Ptr>& services = sgt.second;
if (ServiceGroup::Exists(name)) {
ServiceGroup::Ptr sg = ServiceGroup::GetByName(name);
/* dump the servicegroup and its attributes/members to ido */ /* dump the servicegroup and its attributes/members to ido */
stringstream message; stringstream message;
message << "\n" message << "\n"
<< 403 << ":" << "\n" /* servicegroupdefinition */ << 403 << ":" << "\n" /* servicegroupdefinition */
<< 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */ << 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */
<< 220 << "=" << name << "\n" /* servicegroupname */ << 220 << "=" << sg->GetName() << "\n" /* servicegroupname */
<< 218 << "=" << sg->GetAlias() << "\n"; /* servicegroupalias */ << 218 << "=" << sg->GetAlias() << "\n"; /* servicegroupalias */
vector<String> sglist; vector<String> sglist;
vector<Service::Ptr>::iterator vt; vector<Service::Ptr>::iterator vt;
BOOST_FOREACH(const Service::Ptr& service, services) { BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
sglist.push_back(service->GetHost()->GetName()); sglist.push_back(service->GetHost()->GetName());
sglist.push_back(service->GetAlias()); sglist.push_back(service->GetAlias());
} }
SendMessageList(message, services, 219); /* servicegroupmember */ SendMessageList(message, sglist, 219); /* servicegroupmember */
message << 999 << "\n\n"; /* enddata */ message << 999 << "\n\n"; /* enddata */
m_IdoConnection->SendMessage(message.str()); m_IdoConnection->SendMessage(message.str());
} }
}
/* tell ido2db that we ended dumping the config */ /* tell ido2db that we ended dumping the config */
stringstream msgEndConfigDump; stringstream msgEndConfigDump;