From 2f0c1d0e7e5aab1f8ee0fd9518f52f803e256ac9 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 15 Jun 2012 16:28:30 +0200 Subject: [PATCH] feature #1223: Included quotas for detach. Refactor some detach methods --- include/DispatchManager.h | 21 ++++--- include/Template.h | 7 --- include/TransferManager.h | 16 ++--- include/VirtualMachine.h | 9 ++- src/dm/DispatchManagerActions.cc | 76 +++++++++++----------- src/lcm/LifeCycleActions.cc | 18 +++--- src/lcm/LifeCycleStates.cc | 25 +++++--- src/rm/RequestManagerVirtualMachine.cc | 30 ++++----- src/template/Template.cc | 28 --------- src/tm/TransferManager.cc | 87 ++++++++++---------------- src/vm/VirtualMachine.cc | 48 +++----------- src/vmm/VirtualMachineManager.cc | 53 +++++++++------- src/vmm/VirtualMachineManagerDriver.cc | 10 +-- 13 files changed, 178 insertions(+), 250 deletions(-) diff --git a/include/DispatchManager.h b/include/DispatchManager.h index 43ec052fc7..9ac342c59d 100644 --- a/include/DispatchManager.h +++ b/include/DispatchManager.h @@ -248,22 +248,23 @@ public: * * @return 0 on success, -1 otherwise */ - int attach(int vid, VirtualMachineTemplate * tmpl, string & error_str); + int attach( + int vid, + VirtualMachineTemplate * tmpl, + string& error_str); /** * Starts the detach disk action. + * @param vid VirtualMachine identification + * @param disk_id Disk to detach + * @param error_str Error reason, if any * - * @param vm pointer to a VirtualMachine with its mutex locked. It will be - * unlocked - * @param disk_id Disk to detach - * @param error_str Error reason, if any - * - * @return 0 on success, -1 action error, -2 if the VM is in a wrong a state + * @return 0 on success, -1 otherwise */ int detach( - VirtualMachine* vm, - int disk_id, - string & error_str); + int id, + int disk_id, + string& error_str); private: /** diff --git a/include/Template.h b/include/Template.h index dc9b79946d..b85e974592 100644 --- a/include/Template.h +++ b/include/Template.h @@ -185,13 +185,6 @@ public: */ virtual int erase(const string& name); - /** - * Removes an attribute from the template, and frees the attributes. - * @param att Attribute to remove. It will be deleted - * @return the number of attributes removed - */ - virtual int erase(Attribute * att); - /** * Gets all the attributes with the given name. * @param name the attribute name. diff --git a/include/TransferManager.h b/include/TransferManager.h index 1de34727c1..1b33323690 100644 --- a/include/TransferManager.h +++ b/include/TransferManager.h @@ -103,7 +103,7 @@ public: * @param system_tm_mad The Transfer Manager for the system datastore * @param opennebula_hostname The front-end hostname * @param xfr Stream where the transfer command will be written - * @param error_str Error reason, if any + * @param error Error reason, if any * * @return 0 on success */ @@ -113,7 +113,7 @@ public: string& system_tm_mad, string& opennebula_hostname, ostream& xfr, - string& error_str); + ostringstream& error); /** * Inserts a transfer command in the xfs stream @@ -122,19 +122,13 @@ public: * @param disk Disk to transfer * @param disk_index Disk index * @param xfr Stream where the transfer command will be written - * @param error_str Error reason, if any - * - * @return 0 if the command was written to xfr, -1 if there is an - * error (and error reason in error_str), -2 if the disk didn't need - * a transfer command */ - int epilog_transfer_command( + void epilog_transfer_command( VirtualMachine * vm, const VectorAttribute * disk, - ostream& xfr, - string& error_str); + ostream& xfr); -private: +private: /** * Thread id for the Transfer Manager */ diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index e5e0ea897e..7a16a92e3a 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -794,13 +794,20 @@ public: * generated by the build_attach_disk * @param new_disk must be allocated in the heap */ - void attach_disk(VectorAttribute * new_disk) + void set_attach_disk(VectorAttribute * new_disk) { new_disk->replace("ATTACH", "YES"); obj_template->set(new_disk); } + /** + * Sets the attach attribute to the given disk + * @param disk_id of the DISK + * @return 0 if the disk_id was found -1 otherwise + */ + int set_attach_disk(int disk_id); + /** * Cleans the ATTACH = YES attribute from the disks * diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index 627bf300d6..26984d4849 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -839,7 +839,7 @@ int DispatchManager::attach(int vid, return -1; } - if ( vm->get_state() != VirtualMachine::ACTIVE || + if ( vm->get_state() != VirtualMachine::ACTIVE || vm->get_lcm_state() != VirtualMachine::RUNNING ) { oss << "Could not attach a new disk to VM " << vid << ", wrong state."; @@ -853,9 +853,6 @@ int DispatchManager::attach(int vid, vm->get_disk_info(num_disks, used_targets); - // TODO: Cancel resched? - // vm->set_resched(false); - vm->set_state(VirtualMachine::HOTPLUG); vm->set_resched(false); @@ -899,7 +896,7 @@ int DispatchManager::attach(int vid, } else { - vm->attach_disk(disk); + vm->set_attach_disk(disk); } vmpool->update(vm); @@ -915,37 +912,50 @@ int DispatchManager::attach(int vid, /* -------------------------------------------------------------------------- */ int DispatchManager::detach( - VirtualMachine* vm, - int disk_id, - string & error_str) + int vid, + int disk_id, + string& error_str) { - /* ostringstream oss; - int rc; - int vid = vm->get_oid(); - Nebula& nd = Nebula::instance(); - VirtualMachineManager * vmm = nd.get_vmm(); + ostringstream oss; - oss << "Detaching disk " << disk_id << " from VM " << vid; - NebulaLog::log("DiM",Log::DEBUG,oss); + Nebula& nd = Nebula::instance(); + VirtualMachineManager* vmm = nd.get_vmm(); - if ( vm->get_state() != VirtualMachine::ACTIVE || + VirtualMachine * vm = vmpool->get(vid, true); + + if ( vm == 0 ) + { + oss << "VirtualMachine " << vid << " no longer exists"; + return -1; + } + + if ( vm->get_state() != VirtualMachine::ACTIVE || vm->get_lcm_state() != VirtualMachine::RUNNING ) { - goto error_state; + oss << "Could not detach disk from VM " << vid << ", wrong state."; + error_str = oss.str(); + + NebulaLog::log("DiM", Log::ERROR, error_str); + + vm->unlock(); + return -1; } - - rc = vm->detach_disk(disk_id, error_str); - - if ( rc != 0 ) + + if ( vm->set_attach_disk(disk_id) == -1 ) { - goto error; - } + oss << "Could not detach disk with DISK_ID " << disk_id + << ", it does not exists."; + error_str = oss.str(); - TODO: Cancel resched? - vm->set_resched(false); + vm->unlock(); + return -1; + } vm->set_state(VirtualMachine::HOTPLUG); + + vm->set_resched(false); + vmpool->update(vm); vm->unlock(); @@ -953,20 +963,4 @@ int DispatchManager::detach( vmm->trigger(VirtualMachineManager::DETACH,vid); return 0; - -error: - vm->unlock(); - - return -1; - -error_state: - oss.str(""); - oss << "Could not attach a new disk to VM " << vid << ", wrong state."; - error_str = oss.str(); - - NebulaLog::log("DiM", Log::ERROR, error_str); - - vm->unlock(); - - return -2;*/ } diff --git a/src/lcm/LifeCycleActions.cc b/src/lcm/LifeCycleActions.cc index 22518cd56e..d24561cfe3 100644 --- a/src/lcm/LifeCycleActions.cc +++ b/src/lcm/LifeCycleActions.cc @@ -99,7 +99,7 @@ void LifeCycleManager::suspend_action(int vid) return; } - if (vm->get_state() == VirtualMachine::ACTIVE && + if (vm->get_state() == VirtualMachine::ACTIVE && vm->get_lcm_state() == VirtualMachine::RUNNING) { Nebula& nd = Nebula::instance(); @@ -145,7 +145,7 @@ void LifeCycleManager::stop_action(int vid) return; } - if (vm->get_state() == VirtualMachine::ACTIVE && + if (vm->get_state() == VirtualMachine::ACTIVE && vm->get_lcm_state() == VirtualMachine::RUNNING) { Nebula& nd = Nebula::instance(); @@ -191,7 +191,7 @@ void LifeCycleManager::migrate_action(int vid) return; } - if (vm->get_state() == VirtualMachine::ACTIVE && + if (vm->get_state() == VirtualMachine::ACTIVE && vm->get_lcm_state() == VirtualMachine::RUNNING) { Nebula& nd = Nebula::instance(); @@ -247,7 +247,7 @@ void LifeCycleManager::live_migrate_action(int vid) return; } - if (vm->get_state() == VirtualMachine::ACTIVE && + if (vm->get_state() == VirtualMachine::ACTIVE && vm->get_lcm_state() == VirtualMachine::RUNNING) { Nebula& nd = Nebula::instance(); @@ -302,7 +302,7 @@ void LifeCycleManager::shutdown_action(int vid) return; } - if (vm->get_state() == VirtualMachine::ACTIVE && + if (vm->get_state() == VirtualMachine::ACTIVE && vm->get_lcm_state() == VirtualMachine::RUNNING) { Nebula& nd = Nebula::instance(); @@ -408,7 +408,7 @@ void LifeCycleManager::cancel_action(int vid) return; } - if (vm->get_state() == VirtualMachine::ACTIVE && + if (vm->get_state() == VirtualMachine::ACTIVE && vm->get_lcm_state() == VirtualMachine::RUNNING) { Nebula& nd = Nebula::instance(); @@ -454,7 +454,7 @@ void LifeCycleManager::restart_action(int vid) return; } - if (vm->get_state() == VirtualMachine::ACTIVE && + if (vm->get_state() == VirtualMachine::ACTIVE && (vm->get_lcm_state() == VirtualMachine::UNKNOWN || vm->get_lcm_state() == VirtualMachine::BOOT)) { @@ -529,6 +529,7 @@ void LifeCycleManager::delete_action(int vid) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ + void LifeCycleManager::clean_action(int vid) { VirtualMachine * vm; @@ -602,6 +603,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm) case VirtualMachine::UNKNOWN: case VirtualMachine::SHUTDOWN: case VirtualMachine::CANCEL: + case VirtualMachine::HOTPLUG: vm->set_running_etime(the_time); vmpool->update_history(vm); @@ -686,6 +688,4 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm) default: //LCM_INIT,CLEANUP break; } - - } diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index 29e927a684..910e063edb 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -898,7 +898,11 @@ void LifeCycleManager::attach_failure_action(int vid) void LifeCycleManager::detach_success_action(int vid) { - VirtualMachine * vm; + VirtualMachine * vm; + VectorAttribute * disk; + + int uid; + int gid; vm = vmpool->get(vid,true); @@ -907,7 +911,9 @@ void LifeCycleManager::detach_success_action(int vid) return; } - vm->detach_success(); + disk = vm->delete_attach_disk(); + uid = vm->get_uid(); + gid = vm->get_gid(); vm->set_state(VirtualMachine::RUNNING); @@ -915,7 +921,14 @@ void LifeCycleManager::detach_success_action(int vid) vm->unlock(); - // TODO: update quotas + if ( disk != 0 ) + { + Template tmpl; + + tmpl.set(disk); + + Quotas::vm_del(uid, gid, &tmpl); + } } /* -------------------------------------------------------------------------- */ @@ -932,17 +945,15 @@ void LifeCycleManager::detach_failure_action(int vid) return; } - vm->detach_failure(); + vm->clear_attach_disk(); vm->set_state(VirtualMachine::RUNNING); vmpool->update(vm); - vm->unlock(); + vm->unlock(); } /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ - - diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 092c09121c..069222005a 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -633,7 +633,6 @@ void VirtualMachineAttach::request_execute(xmlrpc_c::paramList const& paramList, Nebula& nd = Nebula::instance(); DispatchManager * dm = nd.get_dm(); - VirtualMachine * vm; VirtualMachineTemplate * tmpl = new VirtualMachineTemplate(); PoolObjectAuth host_perms; @@ -670,7 +669,7 @@ void VirtualMachineAttach::request_execute(xmlrpc_c::paramList const& paramList, if ( quota_authorization(tmpl, att) == false ) { delete tmpl; - return; + return; } rc = dm->attach(id, tmpl, error_str); @@ -701,40 +700,35 @@ void VirtualMachineDetach::request_execute(xmlrpc_c::paramList const& paramList, Nebula& nd = Nebula::instance(); DispatchManager * dm = nd.get_dm(); - VirtualMachine * vm; - PoolObjectAuth host_perms; - int rc; string error_str; int id = xmlrpc_c::value_int(paramList.getInt(1)); int disk_id = xmlrpc_c::value_int(paramList.getInt(2)); - // TODO: auth & quotas - - vm = get_vm(id, att); - - if ( vm == 0 ) + // ------------------------------------------------------------------------- + // Authorize the operation + // ------------------------------------------------------------------------- + + if ( vm_authorization(id, 0, 0, att, 0, 0, auth_op) == false ) { - failure_response(NO_EXISTS, - get_error(object_name(auth_object),id), - att); - return; } - rc = dm->detach(vm, disk_id, error_str); + rc = dm->detach(id, disk_id, error_str); if ( rc != 0 ) { failure_response(ACTION, request_error(error_str, ""), att); - - return; + } + else + { + success_response(id, att); } - success_response(id, att); + return; } /* -------------------------------------------------------------------------- */ diff --git a/src/template/Template.cc b/src/template/Template.cc index 52e72343a3..0231894204 100644 --- a/src/template/Template.cc +++ b/src/template/Template.cc @@ -281,34 +281,6 @@ int Template::erase(const string& name) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int Template::erase(Attribute * att) -{ - multimap::iterator i; - - pair< - multimap::iterator, - multimap::iterator - > index; - - index = attributes.equal_range( att->name() ); - - for ( i = index.first; i != index.second; i++ ) - { - if ( i->second == att ) - { - delete att; - attributes.erase(i); - - return 1; - } - } - - return 0; -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - Attribute * Template::remove(Attribute * att) { multimap::iterator i; diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index 10b62a337e..2a40fb38ba 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -207,7 +207,7 @@ int TransferManager::prolog_transfer_command( string& system_tm_mad, string& opennebula_hostname, ostream& xfr, - string& error_str) + ostringstream& os) { string source; string type; @@ -218,8 +218,6 @@ int TransferManager::prolog_transfer_command( string ds_id; int disk_index; - ostringstream os; - disk->vector_value("DISK_ID", disk_index); type = disk->vector_value("TYPE"); @@ -235,8 +233,9 @@ int TransferManager::prolog_transfer_command( if ( size.empty() ) { - vm->log("TM",Log::WARNING,"No size in swap image, skipping"); - goto skip; + os << "No size in swap image"; + vm->log("TM", Log::WARNING, "No size in swap image, skipping"); + return 0; } //MKSWAP tm_mad size host:remote_system_dir/disk.i vmid dsid(=0) @@ -246,7 +245,8 @@ int TransferManager::prolog_transfer_command( << vm->get_hostname() << ":" << vm->get_remote_system_dir() << "/disk." << disk_index << " " << vm->get_oid() << " " - << "0"; + << "0" + << endl; } else if ( type == "FS" ) { @@ -258,8 +258,9 @@ int TransferManager::prolog_transfer_command( if ( size.empty() || format.empty() ) { - vm->log("TM",Log::WARNING, "No size or format in FS, skipping"); - goto skip; + os << "No size or format in FS"; + vm->log("TM", Log::WARNING, "No size or format in FS, skipping"); + return 0; } //MKIMAGE tm_mad size format host:remote_system_dir/disk.i vmid dsid(=0) @@ -270,7 +271,8 @@ int TransferManager::prolog_transfer_command( << vm->get_hostname() << ":" << vm->get_remote_system_dir() << "/disk." << disk_index << " " << vm->get_oid() << " " - << "0"; + << "0" + << endl; } else { @@ -320,21 +322,18 @@ int TransferManager::prolog_transfer_command( xfr << vm->get_hostname() << ":" << vm->get_remote_system_dir() << "/disk." << disk_index << " " << vm->get_oid() << " " - << ds_id; + << ds_id + << endl; } return 0; error_attributes: - os << "prolog, missing DISK mandatory attributes " + os << "missing DISK mandatory attributes " << "(SOURCE, TM_MAD, CLONE, DATASTORE_ID) for VM " << vm->get_oid() << ", DISK " << disk->vector_value("DISK_ID"); - error_str = os.str(); return -1; - -skip: - return 0; } /* -------------------------------------------------------------------------- */ @@ -343,7 +342,7 @@ skip: void TransferManager::prolog_action(int vid) { ofstream xfr; - ostringstream os; + ostringstream os("prolog, "); string xfr_name; const VectorAttribute * disk; @@ -414,15 +413,16 @@ void TransferManager::prolog_action(int vid) continue; } - rc = prolog_transfer_command(vm, disk, system_tm_mad, - opennebula_hostname, xfr, error_str); - + rc = prolog_transfer_command(vm, + disk, + system_tm_mad, + opennebula_hostname, + xfr, + os); if ( rc != 0 ) { goto error_attributes; } - - xfr << endl; } // ------------------------------------------------------------------------- @@ -461,24 +461,19 @@ void TransferManager::prolog_action(int vid) return; error_history: - os.str(""); - os << "prolog, VM " << vid << " has no history"; + os << "VM " << vid << " has no history"; goto error_common; error_file: - os.str(""); - os << "prolog, could not open file: " << xfr_name; + os << "could not open file: " << xfr_name; goto error_common; error_attributes: - os.str(error_str); - xfr.close(); goto error_common; error_context: - os.str(""); - os << "prolog, could not write context file for VM " << vid; + os << "could not write context file for VM " << vid; xfr.close(); goto error_common; @@ -745,11 +740,10 @@ error_common: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int TransferManager::epilog_transfer_command( +void TransferManager::epilog_transfer_command( VirtualMachine * vm, const VectorAttribute * disk, - ostream& xfr, - string& error_str) + ostream& xfr) { string save; string tm_mad; @@ -762,7 +756,7 @@ int TransferManager::epilog_transfer_command( if ( save.empty() || ds_id.empty() || tm_mad.empty() ) { - return -2; + return; } disk->vector_value("DISK_ID", disk_index); @@ -779,8 +773,8 @@ int TransferManager::epilog_transfer_command( if (source.empty() && save_source.empty()) { - error_str = "No SOURCE to save disk image"; - return -1; + vm->log("TM", Log::ERROR, "No SOURCE to save disk image"); + return; } if (!save_source.empty())//Use the save_as_source instead @@ -795,7 +789,8 @@ int TransferManager::epilog_transfer_command( << vm->get_remote_system_dir() << "/disk." << disk_index << " " << source << " " << vm->get_oid() << " " - << ds_id; + << ds_id + << endl; } else //No saving disk { @@ -805,10 +800,9 @@ int TransferManager::epilog_transfer_command( << vm->get_hostname() << ":" << vm->get_remote_system_dir() << "/disk." << disk_index << " " << vm->get_oid() << " " - << ds_id; + << ds_id + << endl; } - - return 0; } /* -------------------------------------------------------------------------- */ @@ -821,7 +815,6 @@ void TransferManager::epilog_action(int vid) string xfr_name; string system_tm_mad; string error_str; - int rc; const VectorAttribute * disk; @@ -881,19 +874,7 @@ void TransferManager::epilog_action(int vid) continue; } - rc = epilog_transfer_command(vm, disk, xfr, error_str); - - if ( rc == -2 ) - { - continue; - } - - if ( rc == -1 ) - { - vm->log("TM", Log::ERROR, error_str); - } - - xfr << endl; + epilog_transfer_command(vm, disk, xfr); } //DELETE system_tm_mad hostname:remote_system_dir vmid ds_id diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 69bad3686b..cda76800dd 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -1236,50 +1236,38 @@ VectorAttribute * VirtualMachine::set_up_attach_disk( /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -// TODO: this method requires the VM to be locked, and then it locks the Image -// to acquire. Check if this can be troublesome - /* -int VirtualMachine::detach_disk(int disk_id, string& error_str) +int VirtualMachine::set_attach_disk(int disk_id) { - int num_disks; + int num_disks; + int d_id; + vector disks; VectorAttribute * disk; - bool found = false; num_disks = obj_template->get("DISK", disks); - int i = 0; - int d_id; - - while( !found && i(disks[i]); - i++; - if ( disk == 0 ) { continue; } disk->vector_value("DISK_ID", d_id); + if ( d_id == disk_id ) { disk->replace("ATTACH", "YES"); - found = true; + return 0; } } - if ( !found ) - { - return -1; - } - - return 0; - + return -1; } - */ + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -1368,24 +1356,6 @@ VectorAttribute * VirtualMachine::delete_attach_disk() /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int VirtualMachine::detach_success() -{ - return 0; - /*return attach_failure();*/ -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -int VirtualMachine::detach_failure() -{ - return 0; - /*return attach_success();*/ -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - void VirtualMachine::release_disk_images() { int iid; diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index 3377e48748..75b707be71 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -338,9 +338,9 @@ string * VirtualMachineManager::format_message( if ( !tm_command.empty() ) { - oss << "" - << "" << disk_id << "" - << "" << disk_target_path << ""; + oss << "" + << "" << disk_id << "" + << ""<< disk_target_path << ""; } else { @@ -1322,20 +1322,21 @@ void VirtualMachineManager::attach_action( VirtualMachine * vm; const VirtualMachineManagerDriver * vmd; - ostringstream os; - string vm_tmpl; - string * drv_msg; - string tm_command; - string system_tm_mad; - string opennebula_hostname; - string prolog_cmd; - string disk_path; - string error_str; + ostringstream os, error_os; + string vm_tmpl; + string* drv_msg; + string tm_command; + string system_tm_mad; + string opennebula_hostname; + string prolog_cmd; + string disk_path; + const VectorAttribute * disk; int disk_id; + int rc; - Nebula& nd = Nebula::instance(); + Nebula& nd = Nebula::instance(); // Get the VM from the pool vm = vmpool->get(vid,true); @@ -1365,22 +1366,28 @@ void VirtualMachineManager::attach_action( goto error_disk; } - system_tm_mad = nd.get_system_ds_tm_mad(); + system_tm_mad = nd.get_system_ds_tm_mad(); opennebula_hostname = nd.get_nebula_hostname(); - disk->vector_value("DISK_ID", disk_id); - - Nebula::instance().get_tm()->prolog_transfer_command( + rc = Nebula::instance().get_tm()->prolog_transfer_command( vm, disk, system_tm_mad, opennebula_hostname, os, - error_str); + error_os); prolog_cmd = os.str(); + if ( prolog_cmd.empty() || rc != 0 ) + { + goto error_no_tm_command; + } + os.str(""); + + disk->vector_value("DISK_ID", disk_id); + os << vm->get_remote_system_dir() << "/disk." << disk_id; disk_path = os.str(); @@ -1424,6 +1431,11 @@ error_driver: os << "attach_action, error getting driver " << vm->get_vmm_mad(); goto error_common; +error_no_tm_command: + os.str(""); + os << "Cannot set disk to attach it to VM: " << error_os; + goto error_common; + error_common: Nebula &ne = Nebula::instance(); LifeCycleManager * lcm = ne.get_lcm(); @@ -1487,12 +1499,12 @@ void VirtualMachineManager::detach_action( goto error_disk; } - system_tm_mad = nd.get_system_ds_tm_mad(); + system_tm_mad = nd.get_system_ds_tm_mad(); opennebula_hostname = nd.get_nebula_hostname(); disk->vector_value("DISK_ID", disk_id); - Nebula::instance().get_tm()->epilog_transfer_command(vm,disk,os,error_str); + Nebula::instance().get_tm()->epilog_transfer_command(vm, disk, os); epilog_cmd = os.str(); @@ -1516,7 +1528,6 @@ void VirtualMachineManager::detach_action( disk_path, vm->to_xml(vm_tmpl)); - vmd->detach(vid, *drv_msg); delete drv_msg; diff --git a/src/vmm/VirtualMachineManagerDriver.cc b/src/vmm/VirtualMachineManagerDriver.cc index 440326660e..406420e1a1 100644 --- a/src/vmm/VirtualMachineManagerDriver.cc +++ b/src/vmm/VirtualMachineManagerDriver.cc @@ -305,7 +305,7 @@ void VirtualMachineManagerDriver::protocol( } else { - log_error(vm,os,is,"Error live migrating VM"); + log_error(vm, os, is, "Error live migrating VM"); vmpool->update(vm); lcm->trigger(LifeCycleManager::DEPLOY_FAILURE, id); @@ -337,18 +337,18 @@ void VirtualMachineManagerDriver::protocol( } else if ( action == "ATTACH" ) { - Nebula &ne = Nebula::instance(); - LifeCycleManager *lcm = ne.get_lcm(); + Nebula &ne = Nebula::instance(); + LifeCycleManager *lcm = ne.get_lcm(); if ( result == "SUCCESS" ) { - vm->log("VMM",Log::ERROR,"VM Disk Successfully attached."); + vm->log("VMM", Log::ERROR, "VM Disk Successfully attached."); lcm->trigger(LifeCycleManager::ATTACH_SUCCESS, id); } else { - log_error(vm,os,is,"Error attaching new VM Disk"); + log_error(vm, os, is, "Error attaching new VM Disk"); vmpool->update(vm); lcm->trigger(LifeCycleManager::ATTACH_FAILURE, id);