Sha256: fe2084b2f972938ba25677d6d8e4f84c91dea120ae47f7af7c57a2eee2fd9e40

Contents?: true

Size: 1023 Bytes

Versions: 8

Compression:

Stored size: 1023 Bytes

Contents

require 'fog/core/collection'
require 'fog/vsphere/models/compute/server'

module Fog
  module Compute
    class Vsphere

      class Servers < Fog::Collection

        model Fog::Compute::Vsphere::Server

        def all
          response = connection.list_virtual_machines
          load(response['virtual_machines'])
        end

        def get(id)
          # Is the id a managed_object_reference?  This may be the case if we're reloading
          # a model of a VM in the process of being cloned, since it
          # will not have a instance_uuid yet.
          if id =~ /^vm-/
            response = connection.find_vm_by_ref('vm_ref' => id)
            server_attributes = response['virtual_machine']
          else
            response = connection.list_virtual_machines('instance_uuid' => id)
            server_attributes = response['virtual_machines'].first
          end
          new(server_attributes)
        rescue Fog::Compute::Vsphere::NotFound
          nil
        end

      end

    end
  end
end

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
brightbox-cli-0.16.0 lib/brightbox-cli/vendor/fog/lib/fog/vsphere/models/compute/servers.rb
fog-1.1.1 lib/fog/vsphere/models/compute/servers.rb
fog-1.1.0 lib/fog/vsphere/models/compute/servers.rb
brightbox-cli-0.15.0 lib/brightbox-cli/vendor/fog/lib/fog/vsphere/models/compute/servers.rb
tag-fog-1.0.1 lib/fog/vsphere/models/compute/servers.rb
brightbox-cli-0.14.1 lib/brightbox-cli/vendor/fog/lib/fog/vsphere/models/compute/servers.rb
brightbox-cli-0.14.0 lib/brightbox-cli/vendor/fog/lib/fog/vsphere/models/compute/servers.rb
fog-1.0.0 lib/fog/vsphere/models/compute/servers.rb