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 16, 2017
1 parent 985ded1 commit f737bfa
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
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.to_s}>" unless memory_limit.zero?
_log.info "Setting memory to:<#{vm_memory.inspect}>#{limit_message.to_s}"
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 unless limited

ems_version = source_ems.api_version[/\d+\.\d+/x]
if Gem::Version.new("4.1") > Gem::Version.new(ems_version)
return _("Memory Limit is supported for RHV 4.1 and above. Current provider version is #{ems_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

0 comments on commit f737bfa

Please sign in to comment.