From 7d1df849beca39dd8d7c310d17351f0bb6cc79b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 11 Dec 2012 15:41:59 +0100 Subject: [PATCH 1/5] Feature #1338: Add new param to enforce host capacity in one.vm.deploy and one.vm.migrate --- include/RequestManagerVirtualMachine.h | 8 ++- src/rm/RequestManagerVirtualMachine.cc | 80 ++++++++++++++++++++++---- 2 files changed, 75 insertions(+), 13 deletions(-) diff --git a/include/RequestManagerVirtualMachine.h b/include/RequestManagerVirtualMachine.h index 6530741303..879ec92527 100644 --- a/include/RequestManagerVirtualMachine.h +++ b/include/RequestManagerVirtualMachine.h @@ -62,7 +62,9 @@ protected: string& vnm, string& tm, string& ds_location, - int& ds_id, + int& ds_id, + int& free_cpu, + int& free_mem, RequestAttributes& att, PoolObjectAuth& host_perms); @@ -106,7 +108,7 @@ public: VirtualMachineDeploy(): RequestManagerVirtualMachine("VirtualMachineDeploy", "Deploys a virtual machine", - "A:sii") + "A:siib") { auth_op = AuthRequest::ADMIN; }; @@ -126,7 +128,7 @@ public: VirtualMachineMigrate(): RequestManagerVirtualMachine("VirtualMachineMigrate", "Migrates a virtual machine", - "A:siib") + "A:siibb") { auth_op = AuthRequest::ADMIN; }; diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 016354557d..c0ca8f0e08 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -102,6 +102,8 @@ int RequestManagerVirtualMachine::get_host_information(int hid, string& tm, string& ds_location, int& ds_id, + int& free_cpu, + int& free_mem, RequestAttributes& att, PoolObjectAuth& host_perms) { @@ -129,6 +131,9 @@ int RequestManagerVirtualMachine::get_host_information(int hid, vmm = host->get_vmm_mad(); vnm = host->get_vnm_mad(); + free_cpu = host->get_share_max_cpu() - host->get_share_cpu_usage(); + free_mem = host->get_share_max_mem() - host->get_share_mem_usage(); + host->get_permissions(host_perms); cluster_id = host->get_cluster_id(); @@ -386,15 +391,18 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, string tm_mad; string ds_location; int ds_id; + int free_cpu; + int free_mem; - int id = xmlrpc_c::value_int(paramList.getInt(1)); - int hid = xmlrpc_c::value_int(paramList.getInt(2)); + int id = xmlrpc_c::value_int(paramList.getInt(1)); + int hid = xmlrpc_c::value_int(paramList.getInt(2)); + bool enforce = xmlrpc_c::value_boolean(paramList.getBoolean(3)); bool auth = false; if (get_host_information( - hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id, att, - host_perms) != 0) + hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id, + free_cpu, free_mem, att, host_perms) != 0) { return; } @@ -421,6 +429,30 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, return; } + if ( enforce ) + { + int vm_cpu, vm_mem, vm_disk; + + vm->get_requirements(vm_cpu, vm_mem, vm_disk); + + if ( free_cpu < vm_cpu || free_mem < vm_mem ) + { + ostringstream oss; + + oss << object_name(PoolObjectSQL::HOST) + << " [" << hid << "] does not have enough capacity. CPU: Free " + << free_cpu << " Requested " << vm_cpu << ", MEMORY: Free " + << free_mem << " Requested " << vm_mem; + + failure_response(ACTION, + request_error(oss.str(),""), + att); + + vm->unlock(); + return; + } + } + if ( add_history( vm,hid,hostname,vmm_mad,vnm_mad,tm_mad,ds_location,ds_id,att) != 0) { @@ -453,21 +485,25 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList string tm_mad; string ds_location; int ds_id; + int free_cpu; + int free_mem; PoolObjectAuth aux_perms; int current_ds_id; string aux_st; int current_hid; + int aux_int; - int id = xmlrpc_c::value_int(paramList.getInt(1)); - int hid = xmlrpc_c::value_int(paramList.getInt(2)); - bool live = xmlrpc_c::value_boolean(paramList.getBoolean(3)); + int id = xmlrpc_c::value_int(paramList.getInt(1)); + int hid = xmlrpc_c::value_int(paramList.getInt(2)); + bool live = xmlrpc_c::value_boolean(paramList.getBoolean(3)); + bool enforce = xmlrpc_c::value_boolean(paramList.getBoolean(4)); bool auth = false; if (get_host_information( - hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id, att, - host_perms) != 0) + hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id, + free_cpu, free_mem, att, host_perms) != 0) { return; } @@ -502,7 +538,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList if (get_host_information( current_hid, aux_st, aux_st, aux_st, aux_st, aux_st, current_ds_id, - att, aux_perms) != 0) + aux_int, aux_int, att, aux_perms) != 0) { return; } @@ -529,6 +565,30 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList return; } + if ( enforce ) + { + int vm_cpu, vm_mem, vm_disk; + + vm->get_requirements(vm_cpu, vm_mem, vm_disk); + + if ( free_cpu < vm_cpu || free_mem < vm_mem ) + { + ostringstream oss; + + oss << object_name(PoolObjectSQL::HOST) + << " [" << hid << "] does not have enough capacity. CPU: Free " + << free_cpu << " Requested " << vm_cpu << ", MEMORY: Free " + << free_mem << " Requested " << vm_mem; + + failure_response(ACTION, + request_error(oss.str(),""), + att); + + vm->unlock(); + return; + } + } + if ( add_history(vm, hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id, att) != 0) { From 6ebd41e2188730649f128e9ea34ce2762fe574c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 11 Dec 2012 15:42:36 +0100 Subject: [PATCH 2/5] Feature #1338: Update scheduler deploy and migrate xml-rpc calls --- src/scheduler/src/pool/VirtualMachinePoolXML.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/scheduler/src/pool/VirtualMachinePoolXML.cc b/src/scheduler/src/pool/VirtualMachinePoolXML.cc index 1b4852cb69..244d6afd57 100644 --- a/src/scheduler/src/pool/VirtualMachinePoolXML.cc +++ b/src/scheduler/src/pool/VirtualMachinePoolXML.cc @@ -112,27 +112,28 @@ int VirtualMachinePoolXML::dispatch(int vid, int hid, bool resched) const try { - //TODO Get live migration from config file if (resched == true) { client->call(client->get_endpoint(), // serverUrl "one.vm.migrate", // methodName - "siib", // arguments format + "siibb", // arguments format &deploy_result, // resultP client->get_oneauth().c_str(), // argument 0 (AUTH) vid, // argument 1 (VM) hid, // argument 2 (HOST) - live_resched); // argument 3 (LIVE) + live_resched, // argument 3 (LIVE) + false); // argument 4 (ENFORCE) } else { client->call(client->get_endpoint(), // serverUrl "one.vm.deploy", // methodName - "sii", // arguments format + "siib", // arguments format &deploy_result, // resultP client->get_oneauth().c_str(), // argument 0 (AUTH) vid, // argument 1 (VM) - hid); // argument 2 (HOST) + hid, // argument 2 (HOST) + false); // argument 3 (ENFORCE) } } catch (exception const& e) From 06eceb43cb6b0540a5d7770b8ae5c853bb575576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 11 Dec 2012 15:43:31 +0100 Subject: [PATCH 3/5] Feature #1338: Add enforce param to CLI and Ruby OCA --- src/cli/onevm | 31 ++++++++++--- src/oca/ruby/OpenNebula/VirtualMachine.rb | 55 +++++++++++++---------- 2 files changed, 57 insertions(+), 29 deletions(-) diff --git a/src/cli/onevm b/src/cli/onevm index 0e1f3c15de..fc1cf77cb5 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -56,6 +56,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do :description => "Device where the image will be attached" } + ENFORCE={ + :name => "enforce", + :short => "-e", + :large => "--enforce", + :description => "Enforce that the host capacity is not exceeded" + } + ######################################################################## # Global Options ######################################################################## @@ -287,12 +294,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: PENDING EOT - command :deploy, deploy_desc, [:range,:vmid_list], :hostid do + command :deploy, deploy_desc, [:range,:vmid_list], :hostid, :options=>[ENFORCE] do host_id = args[1] verbose = "deploying in host #{host_id}" helper.perform_actions(args[0],options,verbose) do |vm| - vm.deploy(host_id) + if !options[:enforce].nil? + vm.deploy(host_id, options[:enforce]) + else + vm.deploy(host_id) + end end end @@ -302,12 +313,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: RUNNING EOT - command :livemigrate, livemigrate_desc, [:range,:vmid_list], :hostid do + command :livemigrate, livemigrate_desc, [:range,:vmid_list], :hostid, :options=>[ENFORCE] do host_id = args[1] verbose = "live migrating to #{host_id}" helper.perform_actions(args[0],options,verbose) do |vm| - vm.live_migrate(host_id) + if !options[:enforce].nil? + vm.live_migrate(host_id, options[:enforce]) + else + vm.live_migrate(host_id) + end end end @@ -317,12 +332,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: RUNNING EOT - command :migrate, migrate_desc, [:range,:vmid_list], :hostid do + command :migrate, migrate_desc, [:range,:vmid_list], :hostid, :options=>[ENFORCE] do host_id = args[1] verbose = "migrating to #{host_id}" helper.perform_actions(args[0],options,verbose) do |vm| - vm.migrate(host_id) + if !options[:enforce].nil? + vm.migrate(host_id, options[:enforce]) + else + vm.migrate(host_id) + end end end diff --git a/src/oca/ruby/OpenNebula/VirtualMachine.rb b/src/oca/ruby/OpenNebula/VirtualMachine.rb index 5e7c061c8b..d4efcb6a18 100644 --- a/src/oca/ruby/OpenNebula/VirtualMachine.rb +++ b/src/oca/ruby/OpenNebula/VirtualMachine.rb @@ -140,15 +140,16 @@ module OpenNebula # Initiates the instance of the VM on the target host. # - # +host_id+ The host id (hid) of the target host where - # the VM will be instantiated. - def deploy(host_id) - return Error.new('ID not defined') if !@pe_id - - rc = @client.call(VM_METHODS[:deploy], @pe_id, host_id.to_i) - rc = nil if !OpenNebula.is_error?(rc) - - return rc + # @param host_id [Interger] The host id (hid) of the target host where + # the VM will be instantiated. + # @param enforce [true|false] If it is set to true, the host capacity + # will be checked, and the deployment will fail if the host is + # overcommited. Defaults to false + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def deploy(host_id, enforce=false) + return call(VM_METHODS[:deploy], @pe_id, host_id.to_i, enforce) end # Shutdowns an already deployed VM @@ -247,23 +248,31 @@ module OpenNebula end # Saves a running VM and starts it again in the specified host - def migrate(host_id) - return Error.new('ID not defined') if !@pe_id - - rc = @client.call(VM_METHODS[:migrate], @pe_id, host_id.to_i, false) - rc = nil if !OpenNebula.is_error?(rc) - - return rc + # + # @param host_id [Interger] The host id (hid) of the target host where + # the VM will be migrated. + # @param enforce [true|false] If it is set to true, the host capacity + # will be checked, and the deployment will fail if the host is + # overcommited. Defaults to false + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def migrate(host_id, enforce=false) + return call(VM_METHODS[:migrate], @pe_id, host_id.to_i, false, enforce) end # Migrates a running VM to another host without downtime - def live_migrate(host_id) - return Error.new('ID not defined') if !@pe_id - - rc = @client.call(VM_METHODS[:migrate], @pe_id, host_id.to_i, true) - rc = nil if !OpenNebula.is_error?(rc) - - return rc + # + # @param host_id [Interger] The host id (hid) of the target host where + # the VM will be migrated. + # @param enforce [true|false] If it is set to true, the host capacity + # will be checked, and the deployment will fail if the host is + # overcommited. Defaults to false + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def live_migrate(host_id, enforce=false) + return call(VM_METHODS[:migrate], @pe_id, host_id.to_i, true, enforce) end # Set the specified vm's disk to be saved in a new image From b79a9fc6c6ae5c410b9abea238ac36b91be6ab7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 11 Dec 2012 15:46:25 +0100 Subject: [PATCH 4/5] Feature #1338: Add enforce param to Java OCA --- .../opennebula/client/vm/VirtualMachine.java | 63 +++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java index d402c835d2..f32359bda6 100644 --- a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java +++ b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java @@ -290,6 +290,21 @@ public class VirtualMachine extends PoolElement{ return response; } + /** + * Initiates the instance of the VM on the target host. + * + * @param hostId The host id (hid) of the target host where + * the VM will be instantiated. + * @param enforce If it is set to true, the host capacity + * will be checked, and the deployment will fail if the host is + * overcommited. Defaults to false + * @return If an error occurs the error message contains the reason. + */ + public OneResponse deploy(int hostId, boolean enforce) + { + return client.call(DEPLOY, id, hostId, enforce); + } + /** * Initiates the instance of the VM on the target host. * @@ -299,7 +314,7 @@ public class VirtualMachine extends PoolElement{ */ public OneResponse deploy(int hostId) { - return client.call(DEPLOY, id, hostId); + return deploy(hostId, false); } /** @@ -337,11 +352,14 @@ public class VirtualMachine extends PoolElement{ * the vm. * @param live If true we are indicating that we want livemigration, * otherwise false. + * @param enforce If it is set to true, the host capacity + * will be checked, and the deployment will fail if the host is + * overcommited. Defaults to false * @return If an error occurs the error message contains the reason. */ - public OneResponse migrate(int hostId, boolean live) + public OneResponse migrate(int hostId, boolean live, boolean enforce) { - return client.call(MIGRATE, id, hostId, live); + return client.call(MIGRATE, id, hostId, live, enforce); } /** @@ -628,6 +646,24 @@ public class VirtualMachine extends PoolElement{ return action("unresched"); } + /** + * Migrates the virtual machine to the target host (hid). + *
+ * It does the same as {@link VirtualMachine#migrate(int, boolean)} + * with live set to false. + * + * @param hostId The target host id (hid) where we want to migrate + * the vm. + * @param enforce If it is set to true, the host capacity + * will be checked, and the deployment will fail if the host is + * overcommited. Defaults to false + * @return If an error occurs the error message contains the reason. + */ + public OneResponse migrate(int hostId, boolean enforce) + { + return migrate(hostId, false, enforce); + } + /** * Migrates the virtual machine to the target host (hid). *
@@ -643,6 +679,25 @@ public class VirtualMachine extends PoolElement{ return migrate(hostId, false); } + /** + * Performs a live migration of the virtual machine to the + * target host (hid). + *
+ * It does the same as {@link VirtualMachine#migrate(int, boolean)} + * with live set to true. + * + * @param hostId The target host id (hid) where we want to migrate + * the vm. + * @param enforce If it is set to true, the host capacity + * will be checked, and the deployment will fail if the host is + * overcommited. Defaults to false + * @return If an error occurs the error message contains the reason. + */ + public OneResponse liveMigrate(int hostId, boolean enforce) + { + return migrate(hostId, true, enforce); + } + /** * Performs a live migration of the virtual machine to the * target host (hid). @@ -656,7 +711,7 @@ public class VirtualMachine extends PoolElement{ */ public OneResponse liveMigrate(int hostId) { - return migrate(hostId, true); + return liveMigrate(hostId, false); } public int state() From d28b234c9cc16914317519d1d8e62512143b96d4 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 15 Dec 2012 03:11:30 +0100 Subject: [PATCH 5/5] feature #1338: Make use of Host::test_capacity in core checks. --- include/RequestManagerVirtualMachine.h | 8 +- src/rm/RequestManagerVirtualMachine.cc | 191 ++++++++++++++++--------- 2 files changed, 128 insertions(+), 71 deletions(-) diff --git a/include/RequestManagerVirtualMachine.h b/include/RequestManagerVirtualMachine.h index 879ec92527..ca61931a76 100644 --- a/include/RequestManagerVirtualMachine.h +++ b/include/RequestManagerVirtualMachine.h @@ -63,11 +63,15 @@ protected: string& tm, string& ds_location, int& ds_id, - int& free_cpu, - int& free_mem, RequestAttributes& att, PoolObjectAuth& host_perms); + bool check_host(int hid, + int cpu, + int mem, + int disk, + string& error); + int add_history(VirtualMachine * vm, int hid, const string& hostname, diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index c0ca8f0e08..5ebda25003 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -102,8 +102,6 @@ int RequestManagerVirtualMachine::get_host_information(int hid, string& tm, string& ds_location, int& ds_id, - int& free_cpu, - int& free_mem, RequestAttributes& att, PoolObjectAuth& host_perms) { @@ -131,9 +129,6 @@ int RequestManagerVirtualMachine::get_host_information(int hid, vmm = host->get_vmm_mad(); vnm = host->get_vnm_mad(); - free_cpu = host->get_share_max_cpu() - host->get_share_cpu_usage(); - free_mem = host->get_share_max_mem() - host->get_share_mem_usage(); - host->get_permissions(host_perms); cluster_id = host->get_cluster_id(); @@ -205,6 +200,46 @@ int RequestManagerVirtualMachine::get_host_information(int hid, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +bool RequestManagerVirtualMachine::check_host(int hid, + int cpu, + int mem, + int disk, + string& error) +{ + Nebula& nd = Nebula::instance(); + HostPool * hpool = nd.get_hpool(); + + Host * host; + bool test; + + host = hpool->get(hid, true); + + if (host == 0) + { + error = "Host no longer exists"; + return false; + } + + test = host->test_capacity(cpu, mem, disk); + + if (!test) + { + ostringstream oss; + + oss << object_name(PoolObjectSQL::HOST) + << " " << hid << " does not have enough capacity."; + + error = oss.str(); + } + + host->unlock(); + + return test; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + VirtualMachine * RequestManagerVirtualMachine::get_vm(int id, RequestAttributes& att) { @@ -391,8 +426,6 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, string tm_mad; string ds_location; int ds_id; - int free_cpu; - int free_mem; int id = xmlrpc_c::value_int(paramList.getInt(1)); int hid = xmlrpc_c::value_int(paramList.getInt(2)); @@ -400,26 +433,32 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, bool auth = false; - if (get_host_information( - hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id, - free_cpu, free_mem, att, host_perms) != 0) + if (get_host_information(hid, + hostname, + vmm_mad, + vnm_mad, + tm_mad, + ds_location, + ds_id, + att, + host_perms) != 0) { return; } auth = vm_authorization(id, 0, 0, att, &host_perms, 0, auth_op); - if ( auth == false ) + if (auth == false) { return; } - if ( (vm = get_vm(id, att)) == 0 ) + if ((vm = get_vm(id, att)) == 0) { return; } - if ( vm->get_state() != VirtualMachine::PENDING ) + if (vm->get_state() != VirtualMachine::PENDING) { failure_response(ACTION, request_error("Wrong state to perform action",""), @@ -429,32 +468,36 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, return; } - if ( enforce ) + if (enforce) { - int vm_cpu, vm_mem, vm_disk; + int cpu, mem, disk; + string error; - vm->get_requirements(vm_cpu, vm_mem, vm_disk); + vm->get_requirements(cpu, mem, disk); - if ( free_cpu < vm_cpu || free_mem < vm_mem ) + vm->unlock(); + + if (check_host(hid, cpu, mem, disk, error) == false) { - ostringstream oss; + failure_response(ACTION, request_error(error,""), att); + return; + } - oss << object_name(PoolObjectSQL::HOST) - << " [" << hid << "] does not have enough capacity. CPU: Free " - << free_cpu << " Requested " << vm_cpu << ", MEMORY: Free " - << free_mem << " Requested " << vm_mem; - - failure_response(ACTION, - request_error(oss.str(),""), - att); - - vm->unlock(); + if ((vm = get_vm(id, att)) == 0) + { return; } } - if ( add_history( - vm,hid,hostname,vmm_mad,vnm_mad,tm_mad,ds_location,ds_id,att) != 0) + if (add_history(vm, + hid, + hostname, + vmm_mad, + vnm_mad, + tm_mad, + ds_location, + ds_id, + att) != 0) { vm->unlock(); return; @@ -485,14 +528,11 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList string tm_mad; string ds_location; int ds_id; - int free_cpu; - int free_mem; PoolObjectAuth aux_perms; int current_ds_id; string aux_st; int current_hid; - int aux_int; int id = xmlrpc_c::value_int(paramList.getInt(1)); int hid = xmlrpc_c::value_int(paramList.getInt(2)); @@ -501,21 +541,27 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList bool auth = false; - if (get_host_information( - hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id, - free_cpu, free_mem, att, host_perms) != 0) + if (get_host_information(hid, + hostname, + vmm_mad, + vnm_mad, + tm_mad, + ds_location, + ds_id, + att, + host_perms) != 0) { return; } auth = vm_authorization(id, 0, 0, att, &host_perms, 0, auth_op); - if ( auth == false ) + if (auth == false) { return; } - if ( (vm = get_vm(id, att)) == 0 ) + if ((vm = get_vm(id, att)) == 0) { return; } @@ -534,11 +580,35 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList current_hid = vm->get_hid(); - vm->unlock(); + if (enforce) + { + int cpu, mem, disk; + string error; - if (get_host_information( - current_hid, aux_st, aux_st, aux_st, aux_st, aux_st, current_ds_id, - aux_int, aux_int, att, aux_perms) != 0) + vm->get_requirements(cpu, mem, disk); + + vm->unlock(); + + if (check_host(hid, cpu, mem, disk, error) == false) + { + failure_response(ACTION, request_error(error,""), att); + return; + } + } + else + { + vm->unlock(); + } + + if (get_host_information(current_hid, + aux_st, + aux_st, + aux_st, + aux_st, + aux_st, + current_ds_id, + att, + aux_perms) != 0) { return; } @@ -565,38 +635,21 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList return; } - if ( enforce ) - { - int vm_cpu, vm_mem, vm_disk; - - vm->get_requirements(vm_cpu, vm_mem, vm_disk); - - if ( free_cpu < vm_cpu || free_mem < vm_mem ) - { - ostringstream oss; - - oss << object_name(PoolObjectSQL::HOST) - << " [" << hid << "] does not have enough capacity. CPU: Free " - << free_cpu << " Requested " << vm_cpu << ", MEMORY: Free " - << free_mem << " Requested " << vm_mem; - - failure_response(ACTION, - request_error(oss.str(),""), - att); - - vm->unlock(); - return; - } - } - - if ( add_history(vm, hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, - ds_id, att) != 0) + if (add_history(vm, + hid, + hostname, + vmm_mad, + vnm_mad, + tm_mad, + ds_location, + ds_id, + att) != 0) { vm->unlock(); return; } - if ( live == true ) + if (live == true) { dm->live_migrate(vm); }