Skip to content

Commit

Permalink
Support memory limit
Browse files Browse the repository at this point in the history
Memory limit feature was introduced in RHV 4.1.
It is already supported by manageiq as part of the vm provision process.
The patch adds support for total memory for providers of version 4.1 and
above.

https://bugzilla.redhat.com/show_bug.cgi?id=1461560
  • Loading branch information
masayag committed Jul 17, 2017
1 parent 985ded1 commit 0bd0c0b
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 6 deletions.
5 changes: 5 additions & 0 deletions app/models/manageiq/providers/redhat/infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,9 @@ def unsupported_migration_options
def supports_migrate_for_all?(vms)
vms.map(&:ems_cluster).uniq.compact.size == 1
end

def supported_in_version?(version)
ems_version = api_version[/\d+\.\d+/x]
Gem::Version.new(ems_version) >= Gem::Version.new(version)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ def method_missing(method_name, *args, &block)
end
end
end

def update_memory!(memory, _limit = nil)
# memory limit is not supported in v3
self.memory= memory
end
end

def get_mac_address_of_nic_on_requested_vlan(args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,10 @@ def update_description!(description)
update(vm)
end

def update_memory!(memory)
def update_memory!(memory, limit)
vm = get
vm.memory = memory
vm.memory = memory unless memory.zero?
vm.memory_policy.max = limit unless limit.zero?
update(vm)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ def configure_container_description(rhevm_vm)

def configure_memory(rhevm_vm)
vm_memory = get_option(:vm_memory).to_i * 1.megabyte
return if vm_memory.zero?
_log.info "Setting memory to:<#{vm_memory.inspect}>"
rhevm_vm.update_memory!(vm_memory)
memory_limit = get_option(:memory_limit).to_i * 1.megabyte
return if vm_memory.zero? && memory_limit.zero?

limit_message = ", total: <#{memory_limit}>" unless memory_limit.zero?
_log.info("Setting memory to:<#{vm_memory.inspect}>#{limit_message}")
rhevm_vm.update_memory!(vm_memory, memory_limit)
end

def configure_memory_reserve(rhevm_vm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,19 @@ def filter_allowed_hosts(all_hosts)
ovirt_services = ManageIQ::Providers::Redhat::InfraManager::OvirtServices::Builder.new(ems).build(:use_highest_supported_version => true).new(:ems => ems)
ovirt_services.filter_allowed_hosts(self, all_hosts)
end

def validate_memory_limit(_field, values, dlg, fld, _value)
limited = get_value(values[:memory_limit])
return nil if limited.nil? || limited.zero?

ems = source_ems
unless ems.supported_in_version?("4.1")
return _("Memory Limit is supported for RHV 4.1 and above. Current provider version is #{ems.api_version}.")
end

allocated = get_value(values[:vm_memory]).to_i
if allocated > limited.to_i
_("%{description} VM Memory is larger than Memory Limit") % {:description => required_description(dlg, fld)}
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def vm_inv_to_hashes(inv, _storage_inv, storage_uids, cluster_uids, host_uids, l

additional = {
:memory_reserve => vm_memory_reserve(vm_inv),
:memory_limit => extract_vm_memory_policy(vm_inv, :max),
:raw_power_state => raw_power_state,
:boot_time => boot_time,
:connection_state => 'connected',
Expand Down Expand Up @@ -280,7 +281,11 @@ def vm_inv_to_custom_attribute_hashes(inv)
require 'ostruct'

def vm_memory_reserve(vm_inv)
in_bytes = vm_inv.dig(:memory_policy, :guaranteed)
extract_vm_memory_policy(vm_inv, :guaranteed)
end

def extract_vm_memory_policy(vm_inv, type)
in_bytes = vm_inv.dig(:memory_policy, type)
in_bytes.nil? ? nil : in_bytes / Numeric::MEGABYTE
end
end
Expand Down
30 changes: 30 additions & 0 deletions spec/models/manageiq/providers/redhat/infra_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,34 @@
end
end
end

context "#supported_in_version?" do
let(:api_version) { "4.2" }
let(:ems) { FactoryGirl.create(:ems_redhat, :api_version => api_version) }

context "api version is higher or equal than checked version" do
it 'supports the right features' do
expect(ems.supported_in_version?("4.1")).to be_truthy

ems.api_version = "4.1.3.2-0.1.el7"
expect(ems.supported_in_version?("4.1")).to be_truthy

ems.api_version = "4.2.0_master"
expect(ems.supported_in_version?("4.1")).to be_truthy
end
end

context "api version is higher than checked version" do
let(:api_version) { "4.0" }
it 'supports the right features' do
expect(ems.supported_in_version?("4.1")).to be_falsey

ems.api_version = "4.0.3.2-0.1.el7"
expect(ems.supported_in_version?("4.1")).to be_falsey

ems.api_version = "4.0.0_master"
expect(ems.supported_in_version?("4.1")).to be_falsey
end
end
end
end

0 comments on commit 0bd0c0b

Please sign in to comment.