-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The HostResources extend the Host::Managed by creating a table to track the quota-related resources of a host. Moreover, the quota-host relation is replaced by an additional ResourceQuotaHost table.
- Loading branch information
1 parent
84cbc43
commit cb7883e
Showing
9 changed files
with
131 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
module ForemanResourceQuota | ||
class HostResources < ApplicationRecord | ||
self.table_name = 'hosts_resources' | ||
|
||
belongs_to :host, class_name: '::Host::Managed' | ||
validates :host, { presence: true, uniqueness: true } | ||
|
||
def resources | ||
{ | ||
cpu_cores: cpu_cores, | ||
memory_mb: memory_mb, | ||
disk_gb: disk_gb, | ||
} | ||
end | ||
|
||
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 | ||
|
||
# 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. | ||
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 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
module ForemanResourceQuota | ||
class ResourceQuotaHost < ApplicationRecord | ||
self.table_name = 'resource_quotas_hosts' | ||
|
||
belongs_to :resource_quota, class_name: 'ResourceQuota' | ||
belongs_to :host, class_name: '::Host::Managed' | ||
end | ||
end |
10 changes: 0 additions & 10 deletions
10
app/models/foreman_resource_quota/resource_quota_missing_host.rb
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
db/migrate/20240611141744_remove_utilization_from_resource_quotas.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class RemoveUtilizationFromResourceQuotas < ActiveRecord::Migration[6.1] | ||
def change | ||
remove_column :resource_quotas, :utilization_cpu_cores, :integer | ||
remove_column :resource_quotas, :utilization_memory_mb, :integer | ||
remove_column :resource_quotas, :utilization_disk_gb, :integer | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class DropMissingHosts < ActiveRecord::Migration[6.1] | ||
def up | ||
drop_table :resource_quotas_missing_hosts | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateHostsResources < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :hosts_resources do |t| | ||
t.belongs_to :host, index: { unique: true }, foreign_key: true, null: false | ||
t.integer :cpu_cores, default: nil | ||
t.integer :memory_mb, default: nil | ||
t.integer :disk_gb, default: nil | ||
|
||
t.timestamps | ||
end | ||
|
||
create_table :resource_quotas_hosts do |t| | ||
t.belongs_to :host, index: { unique: true }, foreign_key: true, null: false | ||
t.belongs_to :resource_quota, foreign_key: true, null: false | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
db/migrate/20240618163434_remove_resource_quota_from_hosts.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class RemoveResourceQuotaFromHosts < ActiveRecord::Migration[6.1] | ||
def change | ||
remove_reference :hosts, :resource_quota, foreign_key: true | ||
end | ||
end |