string LdapTools::readStoragePoolUri(const string& storagePoolName) { string retval = ""; string base("sstStoragePool="); base.append(storagePoolName).append(",ou=storage pools,ou=virtualization,ou=services,").append( Config::getInstance()->getLdapBaseDn()); SYSLOGLOGGER(logDEBUG) << "readStoragePool " << base; LDAPSearchResults* entries = lc->search(base, LDAPConnection::SEARCH_SUB); if (entries != 0) { LDAPEntry* entry = entries->getNext(); if (entry != 0) { // SYSLOGLOGGER(logINFO) << "dn: " << entry->getDN() << endl; const LDAPAttributeList* attrs = entry->getAttributes(); LDAPAttributeList::const_iterator it = attrs->begin(); for (; it != attrs->end(); it++) { LDAPAttribute attr = *it; // SYSLOGLOGGER(logINFO) << attr.getName() << "("; // SYSLOGLOGGER(logINFO) << attr.getNumValues() << "): "; if (0 == attr.getName().compare("sstStoragePoolURI")) { StringList values = attr.getValues(); StringList::const_iterator it2 = values.begin(); if (it2 != values.end()) { retval = *it2; break; } } } delete entry; } } return retval; }
void LDAPAttributeList::addAttribute(const LDAPAttribute& attr){ DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::addAttribute()" << endl); DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER, " attr:" << attr << endl); const std::string attrType = attr.getName(); const std::string::size_type attrLen = attrType.size(); std::string::size_type tmpAttrLen = 0; bool done=false; AttrList::iterator i; for( i=m_attrs.begin(); i != m_attrs.end(); i++ ){ const std::string tmpAttrType = i->getName(); tmpAttrLen = tmpAttrType.size(); if(tmpAttrLen == attrLen){ if(equal(tmpAttrType.begin(), tmpAttrType.end(), attrType.begin(), nocase_compare)){ const StringList& values = attr.getValues(); StringList::const_iterator j; for(j = values.begin(); j != values.end(); j++){ i->addValue(*j); } DEBUG(LDAP_DEBUG_TRACE,"Attribute" << i->getName() << "already present" << endl); done=true; break; // The AttributeType was already present, // we are done here } } } if(! done){ m_attrs.push_back(attr); } }
void LdapTools::readGlobalBackupConfiguration() { VmBackupConfiguration* config = Config::getInstance()->getGlobalBackupConfiguration(); string base("ou=backup,ou=configuration,ou=virtualization,ou=services,"); base.append(Config::getInstance()->getLdapBaseDn()); SYSLOGLOGGER(logDEBUG) << "readGlobalBackupConfiguration " << base; LDAPSearchResults* entries = lc->search(base, LDAPConnection::SEARCH_SUB); if (entries != 0) { LDAPEntry* entry = entries->getNext(); while (entry != 0) { // SYSLOGLOGGER(logINFO) << "dn: " << entry->getDN(); const LDAPAttributeList* attrs = entry->getAttributes(); LDAPAttributeList::const_iterator it = attrs->begin(); for (; it != attrs->end(); it++) { LDAPAttribute attr = *it; // SYSLOGLOGGER(logINFO) << attr.getName() << "("; // SYSLOGLOGGER(logINFO) << attr.getNumValues() << "): "; StringList values = attr.getValues(); StringList::const_iterator it2 = values.begin(); string value = *it2; // for (; it2 != values.end(); it2++) { // // SYSLOGLOGGER(logINFO) << *it2 << "; "; // } // SYSLOGLOGGER(logINFO) << std::endl; //retval->addAttribute(entry->getDN(), attr.getName(), value); if (0 == attr.getName().compare("sstBackupNumberOfIterations")) { config->setIterations(atoi(value.c_str())); } else if (0 == attr.getName().compare("sstBackupExcludeFromBackup")) { config->setExclude(0 == value.compare("TRUE")); } else if (0 == attr.getName().compare("sstCronActive")) { config->setCronActive(0 == value.compare("TRUE")); } else if (0 == attr.getName().compare("sstCronDay")) { config->setCronDay(value); } else if (0 == attr.getName().compare("sstCronDayOfWeek")) { config->setCronDayOfWeek(value); } else if (0 == attr.getName().compare("sstCronHour")) { config->setCronHour(value); } else if (0 == attr.getName().compare("sstCronMinute")) { config->setCronMinute(value); } else if (0 == attr.getName().compare("sstCronMonth")) { config->setCronMonth(value); } } delete entry; entry = entries->getNext(); } } }
void LdapTools::readConfigurationSettings() { string base("ou=settings,ou=configuration,ou=virtualization,ou=services,"); base.append(Config::getInstance()->getLdapBaseDn()); SYSLOGLOGGER(logDEBUG) << "readConfigurationSettings " << base; LDAPSearchResults* entries = lc->search(base, LDAPConnection::SEARCH_SUB); if (entries != 0) { LDAPEntry* entry = entries->getNext(); while (entry != 0) { // SYSLOGLOGGER(logINFO) << "dn: " << entry->getDN(); const LDAPAttributeList* attrs = entry->getAttributes(); LDAPAttributeList::const_iterator it = attrs->begin(); for (; it != attrs->end(); it++) { LDAPAttribute attr = *it; // SYSLOGLOGGER(logINFO) << attr.getName() << "("; // SYSLOGLOGGER(logINFO) << attr.getNumValues() << "): "; StringList values = attr.getValues(); StringList::const_iterator it2 = values.begin(); string value = *it2; // for (; it2 != values.end(); it2++) { // // SYSLOGLOGGER(logINFO) << *it2 << "; "; // } // SYSLOGLOGGER(logINFO) << std::endl; //retval->addAttribute(entry->getDN(), attr.getName(), value); if (string::npos != entry->getDN().find("ou=sound")) { if (0 == attr.getName().compare("sstAllowSound")) { Config::getInstance()->setAllowSound(0 == value.compare("TRUE")); } } else if (string::npos != entry->getDN().find("ou=spice")) { if (0 == attr.getName().compare("sstAllowSpice")) { Config::getInstance()->setAllowSpice(0 == value.compare("TRUE")); } else if (0 == attr.getName().compare("sstSpicePortMin")) { Config::getInstance()->setSpicePortMin(atoi(value.c_str())); } else if (0 == attr.getName().compare("sstSpicePortMax")) { Config::getInstance()->setSpicePortMax(atoi(value.c_str())); } } else if (string::npos != entry->getDN().find("ou=usb")) { if (0 == attr.getName().compare("sstAllowUSB")) { Config::getInstance()->setAllowUsb(0 == value.compare("TRUE")); } } } delete entry; entry = entries->getNext(); } } }
VmPool* LdapTools::readVmPool(const string poolName, bool complete) { VmPool* retval = NULL; string base; if (!complete) { base = string("sstVirtualMachinePool="); base.append(poolName).append(",ou=virtual machine pools,ou=virtualization,ou=services,").append( Config::getInstance()->getLdapBaseDn()); } else { base = string(poolName); } SYSLOGLOGGER(logINFO) << "readVmPool "; LDAPSearchResults* entries = lc->search(base, LDAPConnection::SEARCH_SUB); if (entries != 0) { LDAPEntry* entry = entries->getNext(); if (entry != 0) { retval = new VmPool(entry->getDN(), this); } while (entry != 0) { // SYSLOGLOGGER(logINFO) << "dn: " << entry->getDN(); const LDAPAttributeList* attrs = entry->getAttributes(); LDAPAttributeList::const_iterator it = attrs->begin(); for (; it != attrs->end(); it++) { LDAPAttribute attr = *it; // SYSLOGLOGGER(logINFO) << attr.getName() << "("; // SYSLOGLOGGER(logINFO) << attr.getNumValues() << "): "; StringList values = attr.getValues(); StringList::const_iterator it2 = values.begin(); string value = *it2; // for (; it2 != values.end(); it2++) { // // SYSLOGLOGGER(logINFO) << *it2 << "; "; // } // SYSLOGLOGGER(logINFO) << std::endl; retval->addAttribute(entry->getDN(), attr.getName(), value); } delete entry; entry = entries->getNext(); } } if (!retval->hasOwnBackupConfiguration()) { retval->setBackupConfiguration(Config::getInstance()->getGlobalBackupConfiguration()); SYSLOGLOGGER(logINFO) << " use global backupconf for vmPool " << retval->getName() << "!"; SYSLOGLOGGER(logINFO) << " " << *(Config::getInstance()->getGlobalBackupConfiguration()); } return retval; }
Vm* LdapTools::readVm(const string vmName, bool complete) { Vm* retval = NULL; string base; if (!complete) { base = string("sstVirtualMachine="); base.append(vmName).append(",ou=virtual machines,ou=virtualization,ou=services,").append( Config::getInstance()->getLdapBaseDn()); } else { base = string(vmName); } SYSLOGLOGGER(logINFO) << "readVm " << base; LDAPSearchResults* entries = lc->search(base, LDAPConnection::SEARCH_SUB); if (entries != 0) { LDAPEntry* entry = entries->getNext(); if (entry != 0) { retval = new Vm(entry->getDN(), this); } while (entry != 0) { // SYSLOGLOGGER(logINFO) << "dn: " << entry->getDN(); const LDAPAttributeList* attrs = entry->getAttributes(); LDAPAttributeList::const_iterator it = attrs->begin(); for (; it != attrs->end(); it++) { LDAPAttribute attr = *it; // SYSLOGLOGGER(logINFO) << attr.getName() << "(" << attr.getNumValues() << "): "; StringList values = attr.getValues(); StringList::const_iterator it2 = values.begin(); string value = *it2; // for (; it2 != values.end(); it2++) { // SYSLOGLOGGER(logINFO) << *it2 << "; "; // } if (0 == attr.getName().compare("sstFeature")) { retval->setFeatures(values); } else { retval->addAttribute(entry->getDN(), attr.getName(), value); } } delete entry; entry = entries->getNext(); } } //SYSLOGLOGGER(logINFO) << "readVm finished!"; return retval; }
Node* LdapTools::readNode(const string nodeName) { Node* retval = NULL; string base("sstNode="); base.append(nodeName).append(",ou=nodes,ou=virtualization,ou=services,").append( Config::getInstance()->getLdapBaseDn()); SYSLOGLOGGER(logDEBUG) << "readNode " << base; LDAPSearchResults* entries = lc->search(base, LDAPConnection::SEARCH_SUB); if (entries != 0) { LDAPEntry* entry = entries->getNext(); if (entry != 0) { retval = new Node(entry->getDN(), this); } while (entry != 0) { // SYSLOGLOGGER(logINFO) << "dn: " << entry->getDN(); const LDAPAttributeList* attrs = entry->getAttributes(); LDAPAttributeList::const_iterator it = attrs->begin(); for (; it != attrs->end(); it++) { LDAPAttribute attr = *it; // SYSLOGLOGGER(logINFO) << attr.getName() << "("; // SYSLOGLOGGER(logINFO) << attr.getNumValues() << "): "; StringList values = attr.getValues(); StringList::const_iterator it2 = values.begin(); string value = *it2; // for (; it2 != values.end(); it2++) { // // SYSLOGLOGGER(logINFO) << *it2 << "; "; // } // SYSLOGLOGGER(logINFO) << std::endl; retval->addAttribute(entry->getDN(), attr.getName(), value); } delete entry; entry = entries->getNext(); } if (NULL != retval) { NodeType* type = retval->getType(string("VM-Node")); string nodestate = type->getState(); retval->setMaintenance(0 == nodestate.compare("maintenance")); } } return retval; }