Class: ForemanResourceQuota::HostResources
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ForemanResourceQuota::HostResources
- Defined in:
- app/models/foreman_resource_quota/host_resources.rb
Instance Method Summary collapse
-
#missing_resources(only_active_resources: true) ⇒ Object
Returns an array of unknown host resources (returns an empty array if all are known) For example, completely unknown host resources returns: [ :cpu_cores, :memory_mb, :disk_gb, ] Consider only the resource_quota’s active resources by default.
- #resources ⇒ Object
- #resources=(val) ⇒ Object
Instance Method Details
#missing_resources(only_active_resources: true) ⇒ Object
Returns an array of unknown host resources (returns an empty array if all are known) For example, completely unknown host resources returns:
[
:cpu_cores,
:memory_mb,
:disk_gb,
]
Consider only the resource_quota’s active resources by default.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/foreman_resource_quota/host_resources.rb', line 31 def missing_resources(only_active_resources: true) empty_resources = [] resources_to_check = %i[cpu_cores memory_mb disk_gb] resources_to_check = host.resource_quota.active_resources if only_active_resources && host.resource_quota.present? resources_to_check.each do |single_resource| empty_resources << single_resource if send(single_resource).nil? end empty_resources end |
#resources ⇒ Object
10 11 12 13 14 15 16 |
# File 'app/models/foreman_resource_quota/host_resources.rb', line 10 def resources { cpu_cores: cpu_cores, memory_mb: memory_mb, disk_gb: disk_gb, } end |
#resources=(val) ⇒ Object
18 19 20 21 |
# File 'app/models/foreman_resource_quota/host_resources.rb', line 18 def resources=(val) allowed_attributes = val.slice(:cpu_cores, :memory_mb, :disk_gb) assign_attributes(allowed_attributes) # Set multiple attributes at once (given a hash) end |