Sha256: 19abf6ff4e10dd133f96a3a5a343d681e83cd7ff71a66af8832cca5055aa4b2b

Contents?: true

Size: 1.33 KB

Versions: 23

Compression:

Stored size: 1.33 KB

Contents

module Fog
  module Vsphere
    class Compute
      class Real
        def list_datacenters(_filters = {})
          raw_datacenters.map do |dc|
            {
              id: managed_obj_id(dc),
              name: dc.name,
              path: raw_getpathmo(dc),
              status: dc.overallStatus
            }
          end
        end

        protected

        def raw_getpathmo(mo)
          if mo.parent.nil? || (mo.parent.name == connection.rootFolder.name)
            [mo.name]
          else
            [raw_getpathmo(mo.parent), mo.name].flatten
          end
        end

        def raw_datacenters(folder = nil)
          folder ||= connection.rootFolder
          @raw_datacenters ||= get_raw_datacenters_from_folder folder
        end

        def get_raw_datacenters_from_folder(folder = nil)
          folder.childEntity.map do |childE|
            if childE.is_a? RbVmomi::VIM::Datacenter
              childE
            elsif childE.is_a? RbVmomi::VIM::Folder
              get_raw_datacenters_from_folder childE
            end
          end.flatten
        end

        def find_datacenters(name = nil)
          name ? [find_raw_datacenter(name)] : raw_datacenters
        end
      end

      class Mock
        def list_datacenters(_filters = {})
          data[:datacenters].values
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
fog-vsphere-3.1.1 lib/fog/vsphere/requests/compute/list_datacenters.rb
fog-vsphere-3.1.0 lib/fog/vsphere/requests/compute/list_datacenters.rb
fog-vsphere-3.0.0 lib/fog/vsphere/requests/compute/list_datacenters.rb