Vm* VmFactory::createInstance(const Vm* goldenImage, const Node* node) const { Vm* retval = NULL; SYSLOGLOGGER(logDEBUG) << "createInstance on " << node->getName(); retval = lt->cloneVm(goldenImage, node, vt, vt->generateUUID()); try { vt->startVm(retval); LDAPModList* modlist = new LDAPModList(); LDAPAttribute attr = LDAPAttribute("sstStatus", "running"); LDAPModification modification = LDAPModification(attr, LDAPModification::OP_REPLACE); modlist->addModification(modification); SYSLOGLOGGER(logDEBUG) << (retval->getName()) << ": set sstStatus to running"; lt->modifyEntry(retval->getDn(), modlist); delete modlist; } catch(VirtException &e) { SYSLOGLOGGER(logINFO) << "createInstance -------------- caught VirtException ---------"; SYSLOGLOGGER(logINFO) << e; retval->remove(); delete retval; retval = NULL; throw e; } catch(LDAPException &e) { SYSLOGLOGGER(logINFO) << "createInstance -------------- caught LDAPException ---------"; SYSLOGLOGGER(logINFO) << e; } return retval; }
void TLdap::runTest2() { cout << "TLdap::runTest2()" << endl; init(); LdapTools* lt = new LdapTools(); lt->bind(); try { string dn = "sstVirtualMachine=4fe820ca-2467-405d-8418-a39b14254582,ou=virtual machines,ou=virtualization,ou=services,dc=foss-cloud,dc=org"; string attr = "sstNode"; string value = "foss-cloud-node-02_CWI"; cout << dn << "; " << attr << "=" << value << endl; LDAPModList* modlist = new LDAPModList(); cout << "modlist"; LDAPAttribute attribute = LDAPAttribute(attr, value); cout << "; attribute"; LDAPModification modification = LDAPModification(attribute, LDAPModification::OP_REPLACE); cout << "; modification"; modlist->addModification(modification); cout << "; addModification"; lt->modifyEntry(dn, modlist); cout << "; modify" << endl; } catch (LDAPException &e) { std::cout << "-------------- caught LDAPException ---------" << std::endl; std::cout << e << std::endl; } }
void TLdap::runTest() { cout << "TLdap::runTest()" << endl; init(); LdapTools* lt = new LdapTools(); lt->bind(); try { string dn = "uid=4000007,ou=people,dc=foss-cloud,dc=org"; cout << dn << "; " << "sstGender=f" << endl; LDAPModList* modlist = new LDAPModList(); cout << "modlist"; LDAPAttribute attribute = LDAPAttribute("sstGender", "f"); cout << "; attribute"; LDAPModification modification = LDAPModification(attribute, LDAPModification::OP_REPLACE); cout << "; modification"; modlist->addModification(modification); cout << "; addModification"; lt->modifyEntry(dn, modlist); cout << "; modify" << endl; } catch (LDAPException &e) { std::cout << "-------------- caught LDAPException ---------" << std::endl; std::cout << e << std::endl; } }
void Vm::migrate(const Node* targetNode, VirtTools* vt) { try { const Vm* vm = this; LDAPModList* modlist = new LDAPModList(); const string targetNodeName = targetNode->getName(); const string targetSpicePort = lt->nextSpicePort(targetNode); LDAPAttribute attr = LDAPAttribute("sstMigrationNode", targetNodeName); LDAPModification modification = LDAPModification(attr, LDAPModification::OP_ADD); modlist->addModification(modification); attr = LDAPAttribute("sstMigrationSpicePort", targetSpicePort); modification = LDAPModification(attr, LDAPModification::OP_ADD); modlist->addModification(modification); SYSLOGLOGGER(logDEBUG) << (getName()) << ": set sstMigrationNode to " << targetNodeName; SYSLOGLOGGER(logDEBUG) << (getName()) << ": set sstMigrationSpicePort to " << targetSpicePort; try { lt->modifyEntry(getDn(), modlist); delete modlist; } catch(LDAPException &e) { delete modlist; modlist = new LDAPModList(); attr = LDAPAttribute("sstMigrationNode", targetNodeName); modification = LDAPModification(attr, LDAPModification::OP_REPLACE); modlist->addModification(modification); attr = LDAPAttribute("sstMigrationSpicePort", targetSpicePort); modification = LDAPModification(attr, LDAPModification::OP_REPLACE); modlist->addModification(modification); SYSLOGLOGGER(logDEBUG) << (getName()) << ": change sstMigrationNode to " << targetNodeName; SYSLOGLOGGER(logDEBUG) << (getName()) << ": change sstMigrationSpicePort to " << targetSpicePort; lt->modifyEntry(getDn(), modlist); delete modlist; } vt->migrateVm(vm, targetNode, targetSpicePort); modlist = new LDAPModList(); attr = LDAPAttribute("sstNode", targetNodeName); modification = LDAPModification(attr, LDAPModification::OP_REPLACE); modlist->addModification(modification); attr = LDAPAttribute("sstSpicePort", targetSpicePort); modification = LDAPModification(attr, LDAPModification::OP_REPLACE); modlist->addModification(modification); SYSLOGLOGGER(logDEBUG) << (getName()) << ": change sstNode to " << targetNodeName; SYSLOGLOGGER(logDEBUG) << (getName()) << ": change sstSpicePort to " << targetSpicePort; attr = LDAPAttribute("sstMigrationNode"); modification = LDAPModification(attr, LDAPModification::OP_DELETE); modlist->addModification(modification); attr = LDAPAttribute("sstMigrationSpicePort"); modification = LDAPModification(attr, LDAPModification::OP_DELETE); modlist->addModification(modification); SYSLOGLOGGER(logDEBUG) << (getName()) << ": remove sstMigrationNode"; SYSLOGLOGGER(logDEBUG) << (getName()) << ": remove sstMigrationSpicePort"; lt->modifyEntry(getDn(), modlist); delete modlist; /* the following lines will be done in caller method migrateFirstOne of class VmPoolNodeWrapper */ /* const_cast<Node*>(targetNode)->addVm(this); Node* node = const_cast<Node*>(getNode()); set<Vm*>* nodeVms = node->getVms(); nodeVms->erase(this); */ } catch (VirtException &e) { SYSLOGLOGGER(logDEBUG) << "-------------- caught VirtException ---------"; SYSLOGLOGGER(logDEBUG) << e; } catch (LDAPException &e) { SYSLOGLOGGER(logDEBUG) << "-------------- caught LDAPException ---------"; SYSLOGLOGGER(logDEBUG) << e; } }
void Vm::handleBackupWorkflow(VirtTools* vt) { string newMode = ""; string newState = "0"; if (0 == activeBackupMode.compare("initialize")) { //20121002T010000Z string backupDn = "ou=backup,"; backupDn.append(getDn()); if (!lt->hasDn(backupDn)) { LDAPEntry* backupEntry = new LDAPEntry(backupDn); StringList values; values.add("top"); values.add("organizationalUnit"); backupEntry->addAttribute(LDAPAttribute("objectClass", values)); backupEntry->addAttribute(LDAPAttribute("ou", "backup")); lt->addEntry(backupEntry); delete backupEntry; } char buffer[18]; struct tm * timeinfo; time_t rawtime = backupConfiguration.getNextTime(); timeinfo = localtime(&rawtime); strftime(buffer, 18, "%Y%m%dT%H%M00Z", timeinfo); activeBackupDn = "ou="; activeBackupDn.append(buffer).append(",").append(backupDn); if (!lt->hasDn(activeBackupDn)) { LDAPEntry* singelBackupEntry = new LDAPEntry(activeBackupDn); StringList values; values.add("top"); values.add("organizationalUnit"); values.add("sstProvisioning"); time(&rawtime); timeinfo = localtime(&rawtime); strftime(buffer, 18, "%Y%m%dT%H%M00Z", timeinfo); singelBackupEntry->addAttribute(LDAPAttribute("objectClass", values)); singelBackupEntry->addAttribute(LDAPAttribute("ou", buffer)); singelBackupEntry->addAttribute(LDAPAttribute("sstProvisioningExecutionDate", "0")); singelBackupEntry->addAttribute(LDAPAttribute("sstProvisioningMode", "initialized")); singelBackupEntry->addAttribute(LDAPAttribute("sstProvisioningState", "0")); lt->addEntry(singelBackupEntry); delete singelBackupEntry; } SYSLOGLOGGER(logDEBUG) << (getDn()) << ": change sstProvisioningMode from initialize to initialized"; newMode = "snapshot"; newState = "0"; } else if (0 == activeBackupMode.compare("initialized")) { // This attribute is written by the fc-brokerd and used internally by the fc-brokerd. newMode = "snapshot"; newState = "0"; } else if (0 == activeBackupMode.compare("snapshotted") && 0 == activeBackupReturnValue) { // The attribute is changed by the Backup-Daemon from snapshotting to snapshotted when the snapshot process has finished. newMode = "merge"; newState = "0"; } else if (0 == activeBackupMode.compare("merged") && 0 == activeBackupReturnValue) { // The attribute is changed by the Backup-Daemon from merging to merged when the merge process has finished. newMode = "retain"; newState = "0"; } else if (0 == activeBackupMode.compare("retained") && 0 == activeBackupReturnValue) { // The attribute is changed by the Backup-Daemon from retaining to retained when the retain process has finished. newMode = "finished"; time_t rawtime; struct tm * timeinfo; char buffer[18]; time(&rawtime); timeinfo = localtime(&rawtime); strftime(buffer, 18, "%Y%m%dT%H%M00Z", timeinfo); newState = buffer; } else if (0 == activeBackupMode.compare("deleted") && 0 == activeBackupReturnValue) { lt->removeEntry(activeBackupDn, true); } else if (0 == activeBackupMode.compare("unretainedLargeFiles") && 0 == activeBackupReturnValue) { // The attribute is changed by the Backup-Daemon from unretaining to unretained when the unretain process has finished. newMode = "restore"; newState = "0"; vt->stopVmForRestore(this); // Merge ldif } else if (0 == activeBackupMode.compare("restored") && 0 == activeBackupReturnValue) { // The attribute is changed by the Backup-Daemon from restoring to restored when the restore process has finished. newMode = "finished"; time_t rawtime; struct tm * timeinfo; char buffer[18]; time(&rawtime); timeinfo = localtime(&rawtime); strftime(buffer, 18, "%Y%m%dT%H%M00Z", timeinfo); newState = buffer; } if (0 != newMode.length()) { LDAPModList* modlist = new LDAPModList(); const string value = newMode; LDAPAttribute attr = LDAPAttribute("sstProvisioningMode", value); LDAPModification modification = LDAPModification(attr, LDAPModification::OP_REPLACE); modlist->addModification(modification); const string value2 = newState; attr = LDAPAttribute("sstProvisioningState", value2); modification = LDAPModification(attr, LDAPModification::OP_REPLACE); modlist->addModification(modification); SYSLOGLOGGER(logDEBUG) << (getDn()) << ": change sstProvisioningMode from " << activeBackupMode << " to " << value; lt->modifyEntry(activeBackupDn, modlist); delete modlist; } if (0 == newMode.compare("finished") && 0 == activeBackupMode.compare("retained") && singleBackupCount > backupConfiguration.getIterations()) { // check for deletion of an older backup if (0 < finishedBackups.size()) { string oldBackupDn = *(finishedBackups.begin()); LDAPModList* modlist = new LDAPModList(); LDAPAttribute attr = LDAPAttribute("sstProvisioningMode", "delete"); LDAPModification modification = LDAPModification(attr, LDAPModification::OP_REPLACE); modlist->addModification(modification); attr = LDAPAttribute("sstProvisioningState", "0"); modification = LDAPModification(attr, LDAPModification::OP_REPLACE); modlist->addModification(modification); SYSLOGLOGGER(logDEBUG) << (getDn()) << ": change sstProvisioningMode from finished to delete"; lt->modifyEntry(oldBackupDn, modlist); delete modlist; } } }