Sha256: 782591fd9867b4b2a2f73d1c6e15b9f6f9b56f24523a53a2e5d0f58b29be37b6

Contents?: true

Size: 1.45 KB

Versions: 17

Compression:

Stored size: 1.45 KB

Contents

module Fog
  module Compute
    class Vsphere
      class Real
        def get_virtual_machine(id, datacenter_name = nil)
          convert_vm_mob_ref_to_attr_hash(get_vm_ref(id, datacenter_name))
        end

        protected

        def get_vm_ref(id, dc = nil)
          raw_datacenter = find_raw_datacenter(dc) if dc
          vm = case is_uuid?(id)
            # UUID based
            when true
              params = {:uuid => id, :vmSearch => true, :instanceUuid => true}
              params[:datacenter] = raw_datacenter if dc
              @connection.searchIndex.FindByUuid(params)
            else
              # try to find based on VM name
              if dc
                raw_datacenter.find_vm(id)
              else
                raw_datacenters.map { |d| d.find_vm(id) }.compact.first
              end
          end
          vm ? vm : raise(Fog::Compute::Vsphere::NotFound, "#{id} was not found")
        end
      end

      class Mock
        def get_virtual_machine(id, datacenter_name = nil)
          if is_uuid?(id)
            vm = list_virtual_machines({ 'instance_uuid' => id, 'datacenter' => datacenter_name }).first
          else
            # try to find based on VM name. May need to handle the path of the VM
            vm = list_virtual_machines({ 'name' => id, 'datacenter' => datacenter_name }).first
          end
          vm ? vm : raise(Fog::Compute::Vsphere::NotFound, "#{id} was not found")
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
vagrant-cloudstack-1.1.0 vendor/bundle/gems/fog-1.22.1/lib/fog/vsphere/requests/compute/get_virtual_machine.rb
fog-1.27.0 lib/fog/vsphere/requests/compute/get_virtual_machine.rb
fog-1.26.0 lib/fog/vsphere/requests/compute/get_virtual_machine.rb
fog-1.25.0 lib/fog/vsphere/requests/compute/get_virtual_machine.rb
nsidc-fog-1.24.1 lib/fog/vsphere/requests/compute/get_virtual_machine.rb
fog-1.24.0 lib/fog/vsphere/requests/compute/get_virtual_machine.rb
ns-fog-1.22.11 lib/fog/vsphere/requests/compute/get_virtual_machine.rb
ns-fog-1.22.10 lib/fog/vsphere/requests/compute/get_virtual_machine.rb
ns-fog-1.22.9 lib/fog/vsphere/requests/compute/get_virtual_machine.rb
ns-fog-1.22.8 lib/fog/vsphere/requests/compute/get_virtual_machine.rb
ns-fog-1.22.7 lib/fog/vsphere/requests/compute/get_virtual_machine.rb
ns-fog-1.22.6 lib/fog/vsphere/requests/compute/get_virtual_machine.rb
fog-1.23.0 lib/fog/vsphere/requests/compute/get_virtual_machine.rb
ns-fog-1.22.4 lib/fog/vsphere/requests/compute/get_virtual_machine.rb
ns-fog-1.22.3 lib/fog/vsphere/requests/compute/get_virtual_machine.rb
ns-fog-1.22.2 lib/fog/vsphere/requests/compute/get_virtual_machine.rb
fog-1.22.1 lib/fog/vsphere/requests/compute/get_virtual_machine.rb