Skip to content

Commit

Permalink
Save HostResources after host is saved
Browse files Browse the repository at this point in the history
A Hosts's HostResources are determined during the validation step but not saved,
because the Host must exist before its HostResources can be stored (not-null database constraint).
We add a routine which saves the HostResources immediately after a Host is saved in case its Host.host_resources changed
  • Loading branch information
bastian-src committed Nov 27, 2024
1 parent 7a00ee0 commit f4b0dd9
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module HostManagedExtensions

# A host shall always have a .host_resources attribute
before_validation :build_host_resources, unless: -> { host_resources.present? }
after_save :save_host_resources, if: -> { host_resources.changed? }
end

def verify_resource_quota
Expand Down Expand Up @@ -141,6 +142,10 @@ def quota_assigment_optional?
owner.resource_quota_is_optional || Setting[:resource_quota_optional_assignment]
end

def save_host_resources
host_resources.save
end

# Wrap into a function for easier testing
def call_utilization_helper(resources, hosts)
all_host_resources, missing_hosts = utilization_from_resource_origins(resources, hosts)
Expand Down

0 comments on commit f4b0dd9

Please sign in to comment.