From d33ce04a33f7b044794df6fb31893bdec64b5906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 30 Mar 2015 17:59:08 +0200 Subject: [PATCH] Bug #3716: Check if VM is imported for unsupported actions (cherry picked from commit 3a3647a91ddfb42a6e46375547441a2beeeffd09) --- src/rm/RequestManagerVirtualMachine.cc | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 279b885838..5e968a37d8 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -481,6 +481,8 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList, AuthRequest::Operation op = auth_op; History::VMAction action; + VirtualMachine * vm; + // Compatibility with 3.8 if (action_st == "cancel") { @@ -515,6 +517,29 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList, return; } + if ((vm = get_vm(id, att)) == 0) + { + return; + } + + if (vm->isImported() && ( + action == History::DELETE_RECREATE_ACTION || + action == History::UNDEPLOY_ACTION || + action == History::UNDEPLOY_HARD_ACTION || + action == History::STOP_ACTION)) + { + oss << "Action \"" << action_st << "\" is not supported for imported VMs"; + + failure_response(ACTION, + request_error(oss.str(),""), + att); + + vm->unlock(); + return; + } + + vm->unlock(); + switch (action) { case History::SHUTDOWN_ACTION: @@ -901,6 +926,16 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList return; } + if (vm->isImported()) + { + failure_response(ACTION, + request_error("Migration is not supported for imported VMs",""), + att); + + vm->unlock(); + return; + } + // Check we are not migrating to the same host c_hid = vm->get_hid();