fog-vsphere icon indicating copy to clipboard operation
fog-vsphere copied to clipboard

list_hosts function does not return standalone hosts

Open derekmwright opened this issue 7 years ago • 3 comments

Might need to refactor this but I'm not sure what it will break. Here's what I'm thinking:

  1. Default w/ no Arg is return all hosts within all datacenters, return :datacenter & :cluster =|| nil (nil indicating standalone) attributes
  2. Provide :datacenter attribute to filter to DC, list all hosts across all clusters
  3. Provide :datacenter & :cluster to filter hosts to a DC and cluster

Here's some class names on a vsphere I have in this scenario:

irb(main):106:0> compute.raw_clusters('Some Datacenter').each do |c|
irb(main):107:1* puts c.class.name
irb(main):108:1> end
RbVmomi::VIM::ComputeResource
RbVmomi::VIM::ComputeResource
RbVmomi::VIM::ComputeResource
RbVmomi::VIM::ClusterComputeResource
RbVmomi::VIM::ClusterComputeResource
RbVmomi::VIM::ClusterComputeResource
RbVmomi::VIM::ClusterComputeResource
RbVmomi::VIM::ClusterComputeResource
RbVmomi::VIM::ClusterComputeResource
RbVmomi::VIM::ClusterComputeResource
RbVmomi::VIM::ClusterComputeResource
RbVmomi::VIM::ClusterComputeResource
RbVmomi::VIM::ClusterComputeResource
RbVmomi::VIM::ClusterComputeResource
RbVmomi::VIM::ClusterComputeResource
RbVmomi::VIM::ClusterComputeResource

derekmwright avatar Aug 02 '17 17:08 derekmwright

Yes, and if you have no any clusters in your deployment, all of this is effectively useless. I will think of a solution in a moment.

istolpov avatar Feb 15 '18 23:02 istolpov

Okay, I have several questions. Either I am dumb, or current logic is completely broken (in several places). I had a hard time untangling this code, but that's what I got.

https://github.com/wyde19/fog-vsphere/commit/97e44675e84d859fe37c0e5e40eb2d3302dffb00 Please, make a review @jrgarcia and write what do you think about it.

Anyway, at least that really returns hosts right now. Although, there are still space for improvements. For example, I did not change compute.hosts.all yet, it still requires both :datacenter and :cluster (which is non-sense).

[5] pry(Host)> compute.hosts.all
ArgumentError: datacenter and cluster are required for this operation
from /Users/istolpov/.rvm/gems/ruby-2.4.0/gems/fog-core-2.0.0/lib/fog/core/attributes.rb:157:in `requires'
[6] pry(Host)> compute.list_hosts
=> [{:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-43.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-44.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-45.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-39.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-46.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-47.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-48.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-49.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-38.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-37.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-36.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-35.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-50.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-51.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-34.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-33.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-32.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-31.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-10.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-12.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-14.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-41.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-42.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-21.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-15.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-22.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-20.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-19.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-18.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-6.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-40.genesyslab.com"},
 {:datacenter=>"HPE.FMT", :cluster=>nil, :name=>"esx-hpe-5.genesyslab.com"}]

istolpov avatar Feb 16 '18 01:02 istolpov

@derekmwright I understand this issue is long overdue, but could you make few checks? Please, check if instance of ClusterComputeResource when invoked with #is_a?(ComputeResource) returns true. Also, do you have all those fields available on ComputeResource? https://github.com/wyde19/fog-vsphere/commit/97e44675e84d859fe37c0e5e40eb2d3302dffb00#r27595863

istolpov avatar Feb 16 '18 01:02 istolpov