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,103 +737,72 @@ 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)) { /* dump the hostgroup and its attributes/members to ido */
HostGroup::Ptr hg = HostGroup::GetByName(name); stringstream message;
message << "\n"
<< 401 << ":" << "\n" /* hostgroupdefinition */
<< 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */
<< 172 << "=" << hg->GetName() << "\n" /* hostgroupname */
<< 170 << "=" << hg->GetAlias() << "\n"; /* hostgroupalias */
/* dump the hostgroup and its attributes/members to ido */ vector<String> hglist;
stringstream message;
message << "\n"
<< 401 << ":" << "\n" /* hostgroupdefinition */
<< 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */
<< 172 << "=" << name << "\n" /* hostgroupname */
<< 170 << "=" << hg->GetAlias() << "\n"; /* hostgroupalias */
SendMessageList(message, hosts, 171); /* hostgroupmember */ BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
hglist.push_back(host->GetName());
message << 999 << "\n\n"; /* enddata */
m_IdoConnection->SendMessage(message.str());
} }
SendMessageList(message, hglist, 171); /* hostgroupmember */
message << 999 << "\n\n"; /* enddata */
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)) { /* dump the servicegroup and its attributes/members to ido */
ServiceGroup::Ptr sg = ServiceGroup::GetByName(name); stringstream message;
message << "\n"
<< 403 << ":" << "\n" /* servicegroupdefinition */
<< 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */
<< 220 << "=" << sg->GetName() << "\n" /* servicegroupname */
<< 218 << "=" << sg->GetAlias() << "\n"; /* servicegroupalias */
/* dump the servicegroup and its attributes/members to ido */ vector<String> sglist;
stringstream message; vector<Service::Ptr>::iterator vt;
message << "\n"
<< 403 << ":" << "\n" /* servicegroupdefinition */
<< 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */
<< 220 << "=" << name << "\n" /* servicegroupname */
<< 218 << "=" << sg->GetAlias() << "\n"; /* servicegroupalias */
vector<String> sglist; BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
vector<Service::Ptr>::iterator vt; sglist.push_back(service->GetHost()->GetName());
sglist.push_back(service->GetAlias());
BOOST_FOREACH(const Service::Ptr& service, services) {
sglist.push_back(service->GetHost()->GetName());
sglist.push_back(service->GetAlias());
}
SendMessageList(message, services, 219); /* servicegroupmember */
message << 999 << "\n\n"; /* enddata */
m_IdoConnection->SendMessage(message.str());
} }
SendMessageList(message, sglist, 219); /* servicegroupmember */
message << 999 << "\n\n"; /* enddata */
m_IdoConnection->SendMessage(message.str());
} }
/* tell ido2db that we ended dumping the config */ /* tell ido2db that we ended dumping the config */