Skip to content

Commit

Permalink
Merge pull request #882 from agrare/fix_host_parser_no_vendor
Browse files Browse the repository at this point in the history
Handle a HostSystem with missing product vendor

(cherry picked from commit 3bdb9cd)
  • Loading branch information
Fryguy committed Sep 27, 2023
1 parent 1855c0d commit 5829a26
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,23 @@ def parse_host_system_product(host_hash, props)
product = props.fetch_path(:summary, :config, :product)
return if product.nil?

vendor = product[:vendor].split(",").first.to_s.downcase
vendor = "unknown" unless Host::VENDOR_TYPES.include?(vendor)
host_hash[:vmm_vendor] = vendor
host_hash[:vmm_vendor] = host_system_vendor(product[:vendor])

product_name = product[:name]
host_hash[:vmm_product] = product_name.nil? ? nil : product_name.to_s.gsub(/^VMware\s*/i, "")
host_hash[:vmm_version] = product[:version]
host_hash[:vmm_buildnumber] = product[:build]
end

def host_system_vendor(vendor)
return "unknown" if vendor.nil?

vendor = vendor.split(",").first.to_s.downcase
vendor = "unknown" unless Host::VENDOR_TYPES.include?(vendor)

vendor
end

def parse_host_system_runtime(host_hash, props)
runtime = props.fetch_path(:summary, :runtime)
return if runtime.nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,15 @@
expect(custom_attrs.first).to have_attributes(:name => "foo", :value => "baz", :source => "VC")
end

it "with a host without a vendor sets vmm_vendor to unknown" do
host_system = RbVmomi::VIM.HostSystem(vim, "host-41")
host_config_storage_device_stub(host_system)
run_targeted_refresh(targeted_update_set([host_missing_vendor_object_update(host_system)]))

host = ems.hosts.find_by(:ems_ref => "host-41")
expect(host).to have_attributes(:vmm_vendor => "unknown")
end

it "deleting a host" do
managed_object_not_found_fault = RbVmomi::Fault.new(
"The object 'vim.HostSystem:host-41' has already been deleted or has not been completely created",
Expand Down Expand Up @@ -1078,6 +1087,18 @@ def host_create_object_update(host)
)
end

def host_missing_vendor_object_update(host)
RbVmomi::VIM.ObjectUpdate(
:kind => "enter",
:obj => host,
:changeSet => [
RbVmomi::VIM.PropertyChange(:name => "config.network.dnsConfig", :op => "assign", :val => {:domainName => "example.com", :hostName => "myhost"}),
RbVmomi::VIM.PropertyChange(:name => "summary.config.product", :op => "assign", :val => {:build => "5.0.0.19", :name => "VMware ESX", :osType => "vmnix-x86", :version => "5.0.0"}),
],
:missingSet => []
)
end

def host_delete_object_update(host)
RbVmomi::VIM.ObjectUpdate(
:kind => "leave",
Expand Down

0 comments on commit 5829a26

Please sign in to comment.