diff --git a/include/DispatchManager.h b/include/DispatchManager.h index 9b6e98a9f5..c66ac52ce0 100644 --- a/include/DispatchManager.h +++ b/include/DispatchManager.h @@ -137,7 +137,8 @@ public: * in a wrong a state */ int shutdown ( - int vid); + int vid, + string& error_str); /** * Shuts down a VM, but it is saved in the system DS instead of destroyed. @@ -147,8 +148,9 @@ public: * in a wrong a state */ int undeploy ( - int vid, - bool hard); + int vid, + bool hard, + string& error_str); /** * Powers off a VM. @@ -158,8 +160,9 @@ public: * in a wrong a state */ int poweroff ( - int vid, - bool hard); + int vid, + bool hard, + string& error_str); /** * Holds a VM. @@ -168,7 +171,8 @@ public: * in a wrong a state */ int hold( - int vid); + int vid, + string& error_str); /** * Releases a VM. @@ -177,7 +181,8 @@ public: * in a wrong a state */ int release( - int vid); + int vid, + string& error_str); /** * Stops a VM. @@ -186,7 +191,8 @@ public: * in a wrong a state */ int stop( - int vid); + int vid, + string& error_str); /** * Cancels a VM. @@ -195,7 +201,8 @@ public: * in a wrong a state */ int cancel( - int vid); + int vid, + string& error_str); /** * Suspends a VM. @@ -204,7 +211,8 @@ public: * in a wrong a state */ int suspend( - int vid); + int vid, + string& error_str); /** * Resumes a VM. @@ -213,7 +221,8 @@ public: * in a wrong a state */ int resume( - int vid); + int vid, + string& error_str); /** * Restart a previusly deployed VM. @@ -222,7 +231,8 @@ public: * in a wrong a state */ int restart( - int vid); + int vid, + string& error_str); /** * Ends a VM life cycle inside ONE. @@ -231,7 +241,8 @@ public: * in a wrong a state */ int finalize( - int vid); + int vid, + string& error_str); /** * Moves a VM to PENDING state preserving any resource (i.e. leases) and id @@ -240,7 +251,8 @@ public: * in a wrong a state */ int resubmit( - int vid); + int vid, + string& error_str); /** * Reboots a VM preserving any resource and RUNNING state @@ -249,7 +261,8 @@ public: * in a wrong a state */ int reboot( - int vid); + int vid, + string& error_str); /** * Resets a VM preserving any resource and RUNNING state @@ -258,7 +271,8 @@ public: * in a wrong a state */ int reset( - int vid); + int vid, + string& error_str); /** * Set the re-scheduling flag for the VM (must be in RUNNING state) @@ -269,8 +283,9 @@ public: * in a wrong a state */ int resched( - int vid, - bool do_resched); + int vid, + bool do_resched, + string& error_str); /** * Starts the attach disk action. diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 53bc96bc9a..3386848ae6 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -263,6 +263,23 @@ public: return st; } + /** + * Returns the VM state to string, using the lcm state if the current state + * is ACTIVE. + * @return the state sting + */ + string state_str() + { + string st; + + if (state == ACTIVE) + { + return lcm_state_to_str(st, lcm_state); + } + + return vm_state_to_str(st, state); + } + // ------------------------------------------------------------------------- // Log & Print // ------------------------------------------------------------------------- diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index 1d00496a29..ab200676e1 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -219,7 +219,8 @@ error: /* ************************************************************************** */ int DispatchManager::shutdown ( - int vid) + int vid, + string& error_str) { ostringstream oss; VirtualMachine * vm; @@ -255,11 +256,14 @@ int DispatchManager::shutdown ( return 0; error: - oss.str(""); oss << "Could not shutdown VM " << vid << ", wrong state."; NebulaLog::log("DiM",Log::ERROR,oss); + oss.str(""); + oss << "This action is not available for state " << vm->state_str(); + error_str = oss.str(); + vm->unlock(); return -2; } @@ -268,8 +272,9 @@ error: /* -------------------------------------------------------------------------- */ int DispatchManager::undeploy( - int vid, - bool hard) + int vid, + bool hard, + string& error_str) { VirtualMachine * vm; ostringstream oss; @@ -315,6 +320,10 @@ error: oss << "Could not undeploy VM " << vid << ", wrong state."; NebulaLog::log("DiM",Log::ERROR,oss); + oss.str(""); + oss << "This action is not available for state " << vm->state_str(); + error_str = oss.str(); + vm->unlock(); return -2; } @@ -323,8 +332,9 @@ error: /* -------------------------------------------------------------------------- */ int DispatchManager::poweroff ( - int vid, - bool hard) + int vid, + bool hard, + string& error_str) { ostringstream oss; VirtualMachine * vm; @@ -370,6 +380,10 @@ error: oss << "Could not power off VM " << vid << ", wrong state."; NebulaLog::log("DiM",Log::ERROR,oss); + oss.str(""); + oss << "This action is not available for state " << vm->state_str(); + error_str = oss.str(); + vm->unlock(); return -2; } @@ -378,7 +392,8 @@ error: /* -------------------------------------------------------------------------- */ int DispatchManager::hold( - int vid) + int vid, + string& error_str) { VirtualMachine * vm; ostringstream oss; @@ -414,6 +429,10 @@ error: oss << "Could not hold VM " << vid << ", wrong state."; NebulaLog::log("DiM",Log::ERROR,oss); + oss.str(""); + oss << "This action is not available for state " << vm->state_str(); + error_str = oss.str(); + vm->unlock(); return -2; } @@ -422,7 +441,8 @@ error: /* -------------------------------------------------------------------------- */ int DispatchManager::release( - int vid) + int vid, + string& error_str) { VirtualMachine * vm; ostringstream oss; @@ -457,6 +477,10 @@ error: oss << "Could not release VM " << vid << ", wrong state."; NebulaLog::log("DiM",Log::ERROR,oss); + oss.str(""); + oss << "This action is not available for state " << vm->state_str(); + error_str = oss.str(); + vm->unlock(); return -2; } @@ -465,7 +489,8 @@ error: /* -------------------------------------------------------------------------- */ int DispatchManager::stop( - int vid) + int vid, + string& error_str) { VirtualMachine * vm; ostringstream oss; @@ -503,6 +528,10 @@ error: oss << "Could not stop VM " << vid << ", wrong state."; NebulaLog::log("DiM",Log::ERROR,oss); + oss.str(""); + oss << "This action is not available for state " << vm->state_str(); + error_str = oss.str(); + vm->unlock(); return -2; } @@ -511,7 +540,8 @@ error: /* -------------------------------------------------------------------------- */ int DispatchManager::cancel( - int vid) + int vid, + string& error_str) { VirtualMachine * vm; ostringstream oss; @@ -551,6 +581,10 @@ error: oss << "Could not cancel VM " << vid << ", wrong state."; NebulaLog::log("DiM",Log::ERROR,oss); + oss.str(""); + oss << "This action is not available for state " << vm->state_str(); + error_str = oss.str(); + vm->unlock(); return -2; } @@ -559,7 +593,8 @@ error: /* -------------------------------------------------------------------------- */ int DispatchManager::suspend( - int vid) + int vid, + string& error_str) { VirtualMachine * vm; ostringstream oss; @@ -596,6 +631,10 @@ error: oss << "Could not suspend VM " << vid << ", wrong state."; NebulaLog::log("DiM",Log::ERROR,oss); + oss.str(""); + oss << "This action is not available for state " << vm->state_str(); + error_str = oss.str(); + vm->unlock(); return -2; } @@ -604,7 +643,8 @@ error: /* -------------------------------------------------------------------------- */ int DispatchManager::resume( - int vid) + int vid, + string& error_str) { VirtualMachine * vm; ostringstream oss; @@ -654,6 +694,10 @@ error: oss << "Could not resume VM " << vid << ", wrong state."; NebulaLog::log("DiM",Log::ERROR,oss); + oss.str(""); + oss << "This action is not available for state " << vm->state_str(); + error_str = oss.str(); + vm->unlock(); return -2; } @@ -661,7 +705,9 @@ error: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int DispatchManager::restart(int vid) +int DispatchManager::restart( + int vid, + string& error_str) { VirtualMachine * vm; ostringstream oss; @@ -705,6 +751,10 @@ error: oss << "Could not restart VM " << vid << ", wrong state."; NebulaLog::log("DiM",Log::ERROR,oss); + oss.str(""); + oss << "This action is not available for state " << vm->state_str(); + error_str = oss.str(); + vm->unlock(); return -2; @@ -713,7 +763,9 @@ error: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int DispatchManager::reboot(int vid) +int DispatchManager::reboot( + int vid, + string& error_str) { VirtualMachine * vm; ostringstream oss; @@ -754,6 +806,10 @@ error: oss << "Could not reboot VM " << vid << ", wrong state."; NebulaLog::log("DiM",Log::ERROR,oss); + oss.str(""); + oss << "This action is not available for state " << vm->state_str(); + error_str = oss.str(); + vm->unlock(); return -2; @@ -762,7 +818,9 @@ error: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int DispatchManager::reset(int vid) +int DispatchManager::reset( + int vid, + string& error_str) { VirtualMachine * vm; ostringstream oss; @@ -803,6 +861,10 @@ error: oss << "Could not reset VM " << vid << ", wrong state."; NebulaLog::log("DiM",Log::ERROR,oss); + oss.str(""); + oss << "This action is not available for state " << vm->state_str(); + error_str = oss.str(); + vm->unlock(); return -2; @@ -811,7 +873,10 @@ error: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int DispatchManager::resched(int vid, bool do_resched) +int DispatchManager::resched( + int vid, + bool do_resched, + string& error_str) { VirtualMachine * vm; ostringstream oss; @@ -847,6 +912,10 @@ error: oss << "Could not set rescheduling flag for VM " << vid << ", wrong state."; NebulaLog::log("DiM",Log::ERROR,oss); + oss.str(""); + oss << "This action is not available for state " << vm->state_str(); + error_str = oss.str(); + vm->unlock(); return -2; @@ -886,7 +955,8 @@ void DispatchManager::finalize_cleanup(VirtualMachine * vm) /* -------------------------------------------------------------------------- */ int DispatchManager::finalize( - int vid) + int vid, + string& error_str) { VirtualMachine * vm; ostringstream oss; @@ -950,7 +1020,9 @@ int DispatchManager::finalize( /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int DispatchManager::resubmit(int vid) +int DispatchManager::resubmit( + int vid, + string& error_str) { VirtualMachine * vm; ostringstream oss; @@ -969,14 +1041,14 @@ int DispatchManager::resubmit(int vid) switch (vm->get_state()) { case VirtualMachine::POWEROFF: - NebulaLog::log("DiM",Log::ERROR, - "Cannot delete-recreate a powered off VM. Resume it first"); + error_str = "Cannot delete-recreate a powered off VM. Resume it first"; + NebulaLog::log("DiM",Log::ERROR,error_str); rc = -2; break; case VirtualMachine::SUSPENDED: - NebulaLog::log("DiM",Log::ERROR, - "Cannot delete-recreate a suspended VM. Resume it first"); + error_str = "Cannot delete-recreate a suspended VM. Resume it first"; + NebulaLog::log("DiM",Log::ERROR,error_str); rc = -2; break; @@ -998,8 +1070,8 @@ int DispatchManager::resubmit(int vid) break; case VirtualMachine::DONE: - NebulaLog::log("DiM",Log::ERROR, - "Cannot delete-recreate a VM already in DONE state"); + error_str = "Cannot delete-recreate a VM already in DONE state"; + NebulaLog::log("DiM",Log::ERROR,error_str); rc = -2; break; } @@ -1055,7 +1127,8 @@ int DispatchManager::attach(int vid, } else { - oss << "Could not attach a new disk to VM " << vid << ", wrong state."; + oss << "Could not attach a new disk to VM " << vid << ", wrong state " + << vm->state_str() << "."; error_str = oss.str(); NebulaLog::log("DiM", Log::ERROR, error_str); @@ -1199,7 +1272,8 @@ int DispatchManager::detach( vm->get_lcm_state() != VirtualMachine::RUNNING ) && vm->get_state() != VirtualMachine::POWEROFF) { - oss << "Could not detach disk from VM " << vid << ", wrong state."; + oss << "Could not detach disk from VM " << vid << ", wrong state " + << vm->state_str() << "."; error_str = oss.str(); NebulaLog::log("DiM", Log::ERROR, error_str); @@ -1302,7 +1376,7 @@ int DispatchManager::snapshot_create( vm->get_lcm_state() != VirtualMachine::RUNNING ) { oss << "Could not create a new snapshot for VM " << vid - << ", wrong state."; + << ", wrong state " << vm->state_str() << "."; error_str = oss.str(); NebulaLog::log("DiM", Log::ERROR, error_str); @@ -1358,7 +1432,7 @@ int DispatchManager::snapshot_revert( vm->get_lcm_state() != VirtualMachine::RUNNING ) { oss << "Could not revert VM " << vid << " to snapshot " << snap_id - << ", wrong state."; + << ", wrong state " << vm->state_str() << "."; error_str = oss.str(); NebulaLog::log("DiM", Log::ERROR, error_str); @@ -1427,7 +1501,7 @@ int DispatchManager::snapshot_delete( vm->get_lcm_state() != VirtualMachine::RUNNING ) { oss << "Could not delete snapshot " << snap_id << " for VM " << vid - << ", wrong state."; + << ", wrong state " << vm->state_str() << "."; error_str = oss.str(); NebulaLog::log("DiM", Log::ERROR, error_str); @@ -1503,7 +1577,8 @@ int DispatchManager::attach_nic( vm->get_lcm_state() != VirtualMachine::RUNNING ) && vm->get_state() != VirtualMachine::POWEROFF ) { - oss << "Could not add a new NIC to VM " << vid << ", wrong state."; + oss << "Could not add a new NIC to VM " << vid << ", wrong state " + << vm->state_str() << "."; error_str = oss.str(); NebulaLog::log("DiM", Log::ERROR, error_str); @@ -1673,7 +1748,8 @@ int DispatchManager::detach_nic( vm->get_lcm_state() != VirtualMachine::RUNNING ) && vm->get_state() != VirtualMachine::POWEROFF ) { - oss << "Could not detach NIC from VM " << vid << ", wrong state."; + oss << "Could not detach NIC from VM " << vid << ", wrong state " + << vm->state_str() << "."; error_str = oss.str(); NebulaLog::log("DiM", Log::ERROR, error_str); diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index dee5806e0b..75ee730a69 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -477,6 +477,7 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList, DispatchManager * dm = nd.get_dm(); ostringstream oss; + string error; AuthRequest::Operation op = auth_op; History::VMAction action; @@ -543,58 +544,58 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList, switch (action) { case History::SHUTDOWN_ACTION: - rc = dm->shutdown(id); + rc = dm->shutdown(id, error); break; case History::HOLD_ACTION: - rc = dm->hold(id); + rc = dm->hold(id, error); break; case History::RELEASE_ACTION: - rc = dm->release(id); + rc = dm->release(id, error); break; case History::STOP_ACTION: - rc = dm->stop(id); + rc = dm->stop(id, error); break; case History::SHUTDOWN_HARD_ACTION: - rc = dm->cancel(id); + rc = dm->cancel(id, error); break; case History::SUSPEND_ACTION: - rc = dm->suspend(id); + rc = dm->suspend(id, error); break; case History::RESUME_ACTION: - rc = dm->resume(id); + rc = dm->resume(id, error); break; case History::BOOT_ACTION: - rc = dm->restart(id); + rc = dm->restart(id, error); break; case History::DELETE_ACTION: - rc = dm->finalize(id); + rc = dm->finalize(id, error); break; case History::DELETE_RECREATE_ACTION: - rc = dm->resubmit(id); + rc = dm->resubmit(id, error); break; case History::REBOOT_ACTION: - rc = dm->reboot(id); + rc = dm->reboot(id, error); break; case History::RESCHED_ACTION: - rc = dm->resched(id, true); + rc = dm->resched(id, true, error); break; case History::UNRESCHED_ACTION: - rc = dm->resched(id, false); + rc = dm->resched(id, false, error); break; case History::REBOOT_HARD_ACTION: - rc = dm->reset(id); + rc = dm->reset(id, error); break; case History::POWEROFF_ACTION: - rc = dm->poweroff(id, false); + rc = dm->poweroff(id, false, error); break; case History::POWEROFF_HARD_ACTION: - rc = dm->poweroff(id, true); + rc = dm->poweroff(id, true, error); break; case History::UNDEPLOY_ACTION: - rc = dm->undeploy(id, false); + rc = dm->undeploy(id, false, error); break; case History::UNDEPLOY_HARD_ACTION: - rc = dm->undeploy(id, true); + rc = dm->undeploy(id, true, error); break; default: rc = -3; @@ -612,10 +613,11 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList, att); break; case -2: - oss << "Wrong state to perform action \"" << action_st << "\""; + oss << "Error performing action \"" << action_st << "\" on " + << object_name(auth_object) << " [" << id << "]"; failure_response(ACTION, - request_error(oss.str(),""), + request_error(oss.str(),error), att); break; case -3: @@ -801,8 +803,12 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, vm->get_state() != VirtualMachine::STOPPED && vm->get_state() != VirtualMachine::UNDEPLOYED) { + ostringstream oss; + + oss << "Deploy action is not available for state " << vm->state_str(); + failure_response(ACTION, - request_error("Wrong state to perform action",""), + request_error(oss.str(),""), att); vm->unlock(); @@ -949,8 +955,12 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList (vm->get_lcm_state() != VirtualMachine::RUNNING && vm->get_lcm_state() != VirtualMachine::UNKNOWN)))) { + ostringstream oss; + + oss << "Migrate action is not available for state " << vm->state_str(); + failure_response(ACTION, - request_error("Wrong state to perform action",""), + request_error(oss.str(),""), att); vm->unlock(); @@ -1970,8 +1980,12 @@ void VirtualMachineResize::request_execute(xmlrpc_c::paramList const& paramList, case VirtualMachine::DONE: case VirtualMachine::SUSPENDED: case VirtualMachine::ACTIVE: + ostringstream oss; + + oss << "Resize action is not available for state " << vm->state_str(); + failure_response(ACTION, - request_error("Wrong state to perform action",""), + request_error(oss.str(),""), att); vm->unlock(); @@ -2102,8 +2116,12 @@ void VirtualMachineResize::request_execute(xmlrpc_c::paramList const& paramList, case VirtualMachine::DONE: case VirtualMachine::SUSPENDED: case VirtualMachine::ACTIVE: + ostringstream oss; + + oss << "Resize action is not available for state " << vm->state_str(); + failure_response(ACTION, - request_error("Wrong state to perform action",""), + request_error(oss.str(),""), att); vm->unlock(); @@ -2420,8 +2438,12 @@ void VirtualMachineRecover::request_execute( if(vm->get_state() != VirtualMachine::ACTIVE) { + ostringstream oss; + + oss << "Recover action is not available for state " << vm->state_str(); + failure_response(ACTION, - request_error("Wrong state to perform action",""), + request_error(oss.str(),""), att); vm->unlock();