Skip to content

Commit

Permalink
Merge pull request #262 from nasark/persist_vm_host
Browse files Browse the repository at this point in the history
Persist VM with host

(cherry picked from commit fb81585)
  • Loading branch information
agrare authored and Fryguy committed Jan 7, 2025
1 parent c182027 commit d8dc153
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/manageiq/providers/kubevirt/inventory/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ def process_vm_instance(object)
vm_object = process_domain(object.namespace, object.memory, object.cpu_cores, uid, name)
process_status(vm_object, object.ip_address, object.node_name)

vm_object.host = host_collection.lazy_find(object.node_name, :ref => :by_name)

vm_object.raw_power_state = object.status
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def host_collection(targeted: false, ids: [])
add_collection(infra, :hosts) do |builder|
builder.add_properties(
:manager_uuids => ids,
:targeted => targeted
:targeted => targeted,
:secondary_refs => {:by_name => %i[name]}
)

builder.add_default_values(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
storage = FactoryBot.create(:storage)
allow(storage_collection).to receive(:lazy_find).and_return(storage)

host_collection = double("host_collection")
host = FactoryBot.create(:host)
allow(host_collection).to receive(:lazy_find).and_return(host)

hw_collection = double("hw_collection")
hardware = FactoryBot.create(:hardware)
allow(hw_collection).to receive(:find_or_build).and_return(hardware)
Expand All @@ -26,6 +30,7 @@

parser = described_class.new
parser.instance_variable_set(:@storage_collection, storage_collection)
parser.instance_variable_set(:@host_collection, host_collection)
parser.instance_variable_set(:@vm_collection, vm_collection)
parser.instance_variable_set(:@hw_collection, hw_collection)
parser.instance_variable_set(:@network_collection, network_collection)
Expand Down Expand Up @@ -53,6 +58,7 @@
:location => "my-project",
:connection_state => "connected",
)
expect(vm.host).to eq(host)

net = vm.hardware.networks.first
expect(net).to_not be_nil
Expand Down

0 comments on commit d8dc153

Please sign in to comment.