diff --git a/include/Nebula.h b/include/Nebula.h index 1bab2d21b6..a3aa35b781 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -243,30 +243,6 @@ public: return ds_location; }; - /** - * Returns the Transfer Manager for the system datastore - * @return the tm name. - */ - string get_system_ds_tm_mad() - { - Datastore * ds; - string tm_mad = ""; - - ds = dspool->get(DatastorePool::SYSTEM_DS_ID, true); - - if ( ds == 0 ) - { - NebulaLog::log("DaS", Log::ERROR, "Can not get system datastore"); - return tm_mad; - } - - tm_mad = ds->get_tm_mad(); - - ds->unlock(); - - return tm_mad; - }; - /** * Returns the path of the log file for a VM, depending where OpenNebula is * installed, diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 67e14dc50b..90ec095ced 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -106,7 +106,12 @@ int RequestManagerVirtualMachine::get_host_information(int hid, Nebula& nd = Nebula::instance(); HostPool * hpool = nd.get_hpool(); - Host * host; + Host * host; + Cluster * cluster; + Datastore * ds; + + int cluster_id; + int ds_id; host = hpool->get(hid,true); @@ -122,12 +127,44 @@ int RequestManagerVirtualMachine::get_host_information(int hid, name = host->get_name(); vmm = host->get_vmm_mad(); vnm = host->get_vnm_mad(); - tm = ""; // TODO host->get_cluster_id, get DS from Cluster, get TM from DS host->get_permissions(host_perms); + cluster_id = host->get_cluster_id(); + host->unlock(); + cluster = nd.get_clpool()->get(cluster_id, true); + + if ( cluster == 0 ) + { + failure_response(NO_EXISTS, + get_error(object_name(PoolObjectSQL::CLUSTER),cluster_id), + att); + + return -1; + } + + // TODO: ds_id = cluster->get_datastore() + ds_id = DatastorePool::SYSTEM_DS_ID; + + cluster->unlock(); + + ds = nd.get_dspool()->get(ds_id, true); + + if ( ds == 0 ) + { + failure_response(NO_EXISTS, + get_error(object_name(PoolObjectSQL::DATASTORE),ds_id), + att); + + return -1; + } + + tm = ds->get_tm_mad(); + + ds->unlock(); + return 0; } diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index 1862dbaf3b..680a5f894f 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -212,7 +212,7 @@ void TransferManager::do_action(const string &action, void * arg) int TransferManager::prolog_transfer_command( VirtualMachine * vm, const VectorAttribute * disk, - string& system_tm_mad, + string& vm_tm_mad, string& opennebula_hostname, ostream& xfr, ostringstream& os) @@ -248,7 +248,7 @@ int TransferManager::prolog_transfer_command( //MKSWAP tm_mad size host:remote_system_dir/disk.i vmid dsid(=0) xfr << "MKSWAP " - << system_tm_mad << " " + << vm_tm_mad << " " << size << " " << vm->get_hostname() << ":" << vm->get_remote_system_dir() << "/disk." << disk_index << " " @@ -273,7 +273,7 @@ int TransferManager::prolog_transfer_command( //MKIMAGE tm_mad size format host:remote_system_dir/disk.i vmid dsid(=0) xfr << "MKIMAGE " - << system_tm_mad << " " + << vm_tm_mad << " " << size << " " << format << " " << vm->get_hostname() << ":" @@ -356,7 +356,7 @@ void TransferManager::prolog_action(int vid) const VectorAttribute * disk; string files; - string system_tm_mad; + string vm_tm_mad; string opennebula_hostname; int rc; string error_str; @@ -374,17 +374,6 @@ void TransferManager::prolog_action(int vid) // ------------------------------------------------------------------------- // Setup & Transfer script // ------------------------------------------------------------------------- - system_tm_mad = nd.get_system_ds_tm_mad(); - tm_md = get(); - - if ( tm_md == 0 || system_tm_mad.empty() ) - { - NebulaLog::log("TM", Log::ERROR, "prolog, error getting drivers."); - (nd.get_lcm())->trigger(LifeCycleManager::PROLOG_FAILURE,vid); - - return; - } - vm = vmpool->get(vid,true); if (vm == 0) @@ -397,6 +386,14 @@ void TransferManager::prolog_action(int vid) goto error_history; } + vm_tm_mad = vm->get_tm_mad(); + tm_md = get(); + + if ( tm_md == 0 || vm_tm_mad.empty() ) + { + goto error_drivers; + } + xfr_name = vm->get_transfer_file() + ".prolog"; xfr.open(xfr_name.c_str(), ios::out | ios::trunc); @@ -423,7 +420,7 @@ void TransferManager::prolog_action(int vid) rc = prolog_transfer_command(vm, disk, - system_tm_mad, + vm_tm_mad, opennebula_hostname, xfr, os); @@ -447,7 +444,7 @@ void TransferManager::prolog_action(int vid) { //CONTEXT tm_mad files hostname:remote_system_dir/disk.i vmid dsid(=0) xfr << "CONTEXT " - << system_tm_mad << " " + << vm_tm_mad << " " << vm->get_context_file() << " "; if (!files.empty()) @@ -472,6 +469,11 @@ error_history: os << "VM " << vid << " has no history"; goto error_common; +error_drivers: + os.str(""); + os << "prolog, error getting drivers."; + goto error_common; + error_file: os << "could not open file: " << xfr_name; goto error_common; @@ -505,7 +507,7 @@ void TransferManager::prolog_migr_action(int vid) const VectorAttribute * disk; string tm_mad; - string system_tm_mad; + string vm_tm_mad; string ds_id; int disk_id; @@ -520,17 +522,6 @@ void TransferManager::prolog_migr_action(int vid) // ------------------------------------------------------------------------- // Setup & Transfer script // ------------------------------------------------------------------------- - system_tm_mad = nd.get_system_ds_tm_mad(); - tm_md = get(); - - if ( tm_md == 0 || system_tm_mad.empty() ) - { - NebulaLog::log("TM", Log::ERROR, "prolog_migr, error getting drivers."); - (nd.get_lcm())->trigger(LifeCycleManager::PROLOG_FAILURE,vid); - - return; - } - vm = vmpool->get(vid,true); if (vm == 0) @@ -538,11 +529,19 @@ void TransferManager::prolog_migr_action(int vid) return; } - if (!vm->hasHistory()) + if (!vm->hasHistory() || !vm->hasPreviousHistory()) { goto error_history; } + vm_tm_mad = vm->get_tm_mad(); + tm_md = get(); + + if ( tm_md == 0 || vm_tm_mad.empty() ) + { + goto error_drivers; + } + xfr_name = vm->get_transfer_file() + ".migrate"; xfr.open(xfr_name.c_str(), ios::out | ios::trunc); @@ -588,7 +587,7 @@ void TransferManager::prolog_migr_action(int vid) //MV tm_mad prev_host:remote_system_dir host:remote_system_dir VMID 0 xfr << "MV " - << system_tm_mad << " " + << vm_tm_mad << " " << vm->get_previous_hostname() << ":" << vm->get_remote_system_dir() << " " << vm->get_hostname() << ":" @@ -608,6 +607,11 @@ error_history: os << "prolog_migr, VM " << vid << " has no history"; goto error_common; +error_drivers: + os.str(""); + os << "prolog_migr, error getting drivers."; + goto error_common; + error_file: os.str(""); os << "prolog_migr, could not open file: " << xfr_name; @@ -632,7 +636,7 @@ void TransferManager::prolog_resume_action(int vid) const VectorAttribute * disk; string tm_mad; - string system_tm_mad; + string vm_tm_mad; string ds_id; int disk_id; @@ -647,17 +651,6 @@ void TransferManager::prolog_resume_action(int vid) // ------------------------------------------------------------------------- // Setup & Transfer script // ------------------------------------------------------------------------- - system_tm_mad = nd.get_system_ds_tm_mad(); - tm_md = get(); - - if ( tm_md == 0 || system_tm_mad.empty() ) - { - NebulaLog::log("TM", Log::ERROR, "prolog_resume, error getting drivers."); - (nd.get_lcm())->trigger(LifeCycleManager::PROLOG_FAILURE,vid); - - return; - } - vm = vmpool->get(vid,true); if (vm == 0) @@ -670,6 +663,14 @@ void TransferManager::prolog_resume_action(int vid) goto error_history; } + vm_tm_mad = vm->get_tm_mad(); + tm_md = get(); + + if ( tm_md == 0 || vm_tm_mad.empty() ) + { + goto error_drivers; + } + xfr_name = vm->get_transfer_file() + ".resume"; xfr.open(xfr_name.c_str(), ios::out | ios::trunc); @@ -714,7 +715,7 @@ void TransferManager::prolog_resume_action(int vid) //MV tm_mad fe:system_dir host:remote_system_dir vmid 0 xfr << "MV " - << system_tm_mad << " " + << vm_tm_mad << " " << nd.get_nebula_hostname() << ":"<< vm->get_system_dir() << " " << vm->get_hostname() << ":" << vm->get_remote_system_dir()<< " " << vm->get_oid() << " " @@ -732,6 +733,11 @@ error_history: os << "prolog_resume, VM " << vid << " has no history"; goto error_common; +error_drivers: + os.str(""); + os << "prolog_resume, error getting drivers."; + goto error_common; + error_file: os.str(""); os << "prolog_resume, could not open file: " << xfr_name; @@ -821,7 +827,7 @@ void TransferManager::epilog_action(int vid) ofstream xfr; ostringstream os; string xfr_name; - string system_tm_mad; + string vm_tm_mad; string error_str; const VectorAttribute * disk; @@ -837,17 +843,6 @@ void TransferManager::epilog_action(int vid) // ------------------------------------------------------------------------ // Setup & Transfer script // ------------------------------------------------------------------------ - system_tm_mad = nd.get_system_ds_tm_mad(); - tm_md = get(); - - if ( tm_md == 0 || system_tm_mad.empty() ) - { - NebulaLog::log("TM", Log::ERROR, "epilog, error getting drivers."); - (nd.get_lcm())->trigger(LifeCycleManager::EPILOG_FAILURE,vid); - - return; - } - vm = vmpool->get(vid,true); if (vm == 0) @@ -860,6 +855,14 @@ void TransferManager::epilog_action(int vid) goto error_history; } + vm_tm_mad = vm->get_tm_mad(); + tm_md = get(); + + if ( tm_md == 0 || vm_tm_mad.empty() ) + { + goto error_drivers; + } + xfr_name = vm->get_transfer_file() + ".epilog"; xfr.open(xfr_name.c_str(), ios::out | ios::trunc); @@ -885,9 +888,9 @@ void TransferManager::epilog_action(int vid) epilog_transfer_command(vm, disk, xfr); } - //DELETE system_tm_mad hostname:remote_system_dir vmid ds_id + //DELETE vm_tm_mad hostname:remote_system_dir vmid ds_id xfr << "DELETE " - << system_tm_mad << " " + << vm_tm_mad << " " << vm->get_hostname() << ":" << vm->get_remote_system_dir() << " " << vm->get_oid() << " " << "0" << endl; @@ -904,6 +907,11 @@ error_history: os << "epilog, VM " << vid << " has no history"; goto error_common; +error_drivers: + os.str(""); + os << "epilog, error getting drivers."; + goto error_common; + error_file: os.str(""); os << "epilog, could not open file: " << xfr_name; @@ -926,7 +934,7 @@ void TransferManager::epilog_stop_action(int vid) ostringstream os; string xfr_name; string tm_mad; - string system_tm_mad; + string vm_tm_mad; string ds_id; int disk_id; @@ -942,17 +950,6 @@ void TransferManager::epilog_stop_action(int vid) // ------------------------------------------------------------------------ // Setup & Transfer script // ------------------------------------------------------------------------ - system_tm_mad = nd.get_system_ds_tm_mad(); - tm_md = get(); - - if ( tm_md == 0 || system_tm_mad.empty() ) - { - NebulaLog::log("TM", Log::ERROR, "epilog_stop, error getting drivers."); - (nd.get_lcm())->trigger(LifeCycleManager::EPILOG_FAILURE,vid); - - return; - } - vm = vmpool->get(vid,true); if (vm == 0) @@ -965,6 +962,14 @@ void TransferManager::epilog_stop_action(int vid) goto error_history; } + vm_tm_mad = vm->get_tm_mad(); + tm_md = get(); + + if ( tm_md == 0 || vm_tm_mad.empty() ) + { + goto error_drivers; + } + xfr_name = vm->get_transfer_file() + ".stop"; xfr.open(xfr_name.c_str(), ios::out | ios::trunc); @@ -1007,9 +1012,9 @@ void TransferManager::epilog_stop_action(int vid) << ds_id << endl; } - //MV system_tm_mad hostname:remote_system_dir fe:system_dir + //MV vm_tm_mad hostname:remote_system_dir fe:system_dir xfr << "MV " - << system_tm_mad << " " + << vm_tm_mad << " " << vm->get_hostname() << ":" << vm->get_remote_system_dir() << " " << nd.get_nebula_hostname() << ":" << vm->get_system_dir() << " " << vm->get_oid() << " " @@ -1028,6 +1033,11 @@ error_history: os << "epilog_stop, VM " << vid << " has no history"; goto error_common; +error_drivers: + os.str(""); + os << "epilog_stop, error getting drivers."; + goto error_common; + error_file: os.str(""); os << "epilog_stop, could not open file: " << xfr_name; @@ -1049,7 +1059,7 @@ void TransferManager::epilog_delete_action(bool local, int vid) ofstream xfr; ostringstream os; string xfr_name; - string system_tm_mad; + string vm_tm_mad; string tm_mad; string ds_id; int disk_id; @@ -1066,17 +1076,6 @@ void TransferManager::epilog_delete_action(bool local, int vid) // ------------------------------------------------------------------------ // Setup & Transfer script // ------------------------------------------------------------------------ - system_tm_mad = nd.get_system_ds_tm_mad(); - tm_md = get(); - - if ( tm_md == 0 || system_tm_mad.empty() ) - { - NebulaLog::log("TM", Log::ERROR, "epilog_delete, error getting drivers."); - (nd.get_lcm())->trigger(LifeCycleManager::EPILOG_FAILURE,vid); - - return; - } - vm = vmpool->get(vid,true); if (vm == 0) @@ -1088,7 +1087,15 @@ void TransferManager::epilog_delete_action(bool local, int vid) { goto error_history; } - + + vm_tm_mad = vm->get_tm_mad(); + tm_md = get(); + + if ( tm_md == 0 || vm_tm_mad.empty() ) + { + goto error_drivers; + } + xfr_name = vm->get_transfer_file() + ".delete"; xfr.open(xfr_name.c_str(), ios::out | ios::trunc); @@ -1144,18 +1151,18 @@ void TransferManager::epilog_delete_action(bool local, int vid) if ( local ) { - //DELETE system_tm_mad fe:system_dir vmid dsid(=0) + //DELETE vm_tm_mad fe:system_dir vmid dsid(=0) xfr << "DELETE " - << system_tm_mad << " " + << vm_tm_mad << " " << nd.get_nebula_hostname() <<":"<< vm->get_system_dir() << " " << vm->get_oid() << " " << "0"; } else { - //DELETE system_tm_mad hostname:remote_system_dir vmid dsid(=0) + //DELETE vm_tm_mad hostname:remote_system_dir vmid dsid(=0) xfr << "DELETE " - << system_tm_mad << " " + << vm_tm_mad << " " << vm->get_hostname() <<":"<< vm->get_remote_system_dir() << " " << vm->get_oid() << " " << "0"; @@ -1173,6 +1180,11 @@ error_history: os << "epilog_delete, VM " << vid << " has no history"; goto error_common; +error_drivers: + os.str(""); + os << "epilog_delete, error getting drivers."; + goto error_common; + error_file: os.str(""); os << "epilog_delete, could not open file: " << xfr_name; @@ -1196,7 +1208,7 @@ void TransferManager::epilog_delete_previous_action(int vid) ofstream xfr; ostringstream os; string xfr_name; - string system_tm_mad; + string vm_tm_mad; string tm_mad; string ds_id; int disk_id; @@ -1213,17 +1225,6 @@ void TransferManager::epilog_delete_previous_action(int vid) // ------------------------------------------------------------------------ // Setup & Transfer script // ------------------------------------------------------------------------ - system_tm_mad = nd.get_system_ds_tm_mad(); - tm_md = get(); - - if ( tm_md == 0 || system_tm_mad.empty() ) - { - NebulaLog::log("TM", Log::ERROR, "epilog_delete, error getting drivers."); - (nd.get_lcm())->trigger(LifeCycleManager::EPILOG_FAILURE,vid); - - return; - } - vm = vmpool->get(vid,true); if (vm == 0) @@ -1236,6 +1237,14 @@ void TransferManager::epilog_delete_previous_action(int vid) goto error_history; } + vm_tm_mad = vm->get_previous_tm_mad(); + tm_md = get(); + + if ( tm_md == 0 || vm_tm_mad.empty() ) + { + goto error_drivers; + } + xfr_name = vm->get_transfer_file() + ".delete_prev"; xfr.open(xfr_name.c_str(),ios::out | ios::trunc); @@ -1276,9 +1285,9 @@ void TransferManager::epilog_delete_previous_action(int vid) << ds_id << endl; } - //DELTE system_tm_mad prev_host:remote_system_dir vmid ds_id(=0) + //DELTE vm_tm_mad prev_host:remote_system_dir vmid ds_id(=0) xfr << "DELETE " - << system_tm_mad << " " + << vm_tm_mad << " " << vm->get_previous_hostname() <<":"<< vm->get_remote_system_dir() << " " << vm->get_oid() << " " << "0" << endl; @@ -1295,9 +1304,14 @@ error_history: os << "epilog_delete_previous, VM " << vid << " has no history"; goto error_common; +error_drivers: + os.str(""); + os << "epilog_delete_previous, error getting drivers."; + goto error_common; + error_file: os.str(""); - os << "epilog_delete, could not open file: " << xfr_name; + os << "epilog_delete_previous, could not open file: " << xfr_name; os << ". You may need to manually clean " << vm->get_previous_hostname() << ":" << vm->get_remote_system_dir(); goto error_common; diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index ecd651acc1..1565dabfd0 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -1313,7 +1313,7 @@ void VirtualMachineManager::attach_action( string vm_tmpl; string* drv_msg; string tm_command; - string system_tm_mad; + string vm_tm_mad; string opennebula_hostname; string prolog_cmd; string disk_path; @@ -1352,13 +1352,13 @@ void VirtualMachineManager::attach_action( goto error_disk; } - system_tm_mad = nd.get_system_ds_tm_mad(); + vm_tm_mad = vm->get_tm_mad(); opennebula_hostname = nd.get_nebula_hostname(); rc = Nebula::instance().get_tm()->prolog_transfer_command( vm, disk, - system_tm_mad, + vm_tm_mad, opennebula_hostname, os, error_os); @@ -1445,7 +1445,7 @@ void VirtualMachineManager::detach_action( string vm_tmpl; string * drv_msg; string tm_command; - string system_tm_mad; + string vm_tm_mad; string opennebula_hostname; string epilog_cmd; string disk_path; @@ -1484,7 +1484,7 @@ void VirtualMachineManager::detach_action( goto error_disk; } - system_tm_mad = nd.get_system_ds_tm_mad(); + vm_tm_mad = vm->get_tm_mad(); opennebula_hostname = nd.get_nebula_hostname(); disk->vector_value("DISK_ID", disk_id);