Class: ForemanResourceQuota::ResourceOrigins::ComputeAttributesOrigin

Inherits:
ForemanResourceQuota::ResourceOrigin show all
Defined in:
app/services/foreman_resource_quota/resource_origins/compute_attributes_origin.rb

Constant Summary

Constants inherited from ForemanResourceQuota::ResourceOrigin

ForemanResourceQuota::ResourceOrigin::RESOURCE_FUNCTION_MAP

Instance Method Summary collapse

Methods inherited from ForemanResourceQuota::ResourceOrigin

#collect_resources!

Instance Method Details

#extract_cpu_cores(param) ⇒ Object



14
15
16
17
18
19
# File 'app/services/foreman_resource_quota/resource_origins/compute_attributes_origin.rb', line 14

def extract_cpu_cores(param)
  return nil unless param.key?(:cpus)
  param[:cpus].to_i
rescue StandardError
  nil
end

#extract_disk_gb(param) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'app/services/foreman_resource_quota/resource_origins/compute_attributes_origin.rb', line 32

def extract_disk_gb(param)
  return nil unless param.key?(:volumes_attributes)
  extract_volumes(param).sum do |disk|
    # key can be capactiy or size_gb
    return nil unless disk.key?(:capacity) || disk.key?(:size_gb)
    (disk[:size_gb] || disk[:capacity]).to_i
  end
rescue StandardError
  nil
end

#extract_memory_mb(param) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'app/services/foreman_resource_quota/resource_origins/compute_attributes_origin.rb', line 21

def extract_memory_mb(param)
  case determine_memory_key(param)
  when :memory
    param[:memory].to_i / ResourceQuotaHelper::FACTOR_B_TO_MB
  when :memory_mb
    param[:memory_mb].to_i
  end
rescue StandardError
  nil
end

#host_attribute_eager_nameObject



6
7
8
# File 'app/services/foreman_resource_quota/resource_origins/compute_attributes_origin.rb', line 6

def host_attribute_eager_name
  :compute_attributes
end

#host_attribute_nameObject



10
11
12
# File 'app/services/foreman_resource_quota/resource_origins/compute_attributes_origin.rb', line 10

def host_attribute_name
  :compute_attributes
end