Sha256: 601759b9a3b05a9e383a3063b2f829c0ea2498301b37e48066aaeab0b0b6b350

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

module Fog
  module Compute
    class Vsphere
      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 or mo.parent.name == @connection.rootFolder.name then
            [ 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 = {}
          [ {:name => "Solutions", :status => "grey"}, {:name => "Solutions2", :status => "green" }]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fog-1.22.0 lib/fog/vsphere/requests/compute/list_datacenters.rb
fog-1.21.0 lib/fog/vsphere/requests/compute/list_datacenters.rb