Sha256: db653531eb0e033cf9e76f96fcc9307347e26c8f49cc3cabc5b6254516194532

Contents?: true

Size: 1.39 KB

Versions: 25

Compression:

Stored size: 1.39 KB

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

        # 'path' => '/Datacenters/vm/Jeff/Templates' will be MUCH faster.
        # than simply listing everything.
        def all(filters = {})
          # REVISIT: I'm not sure if this is the best way to implement search
          # filters on a collection but it does work.  I need to study the AWS
          # code more to make sure this matches up.
          filters['folder'] ||= attributes['folder']
          response = connection.list_virtual_machines(filters)
          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

25 entries across 25 versions & 9 rubygems

Version Path
fog-parser-fix-1.6.1 lib/fog/vsphere/models/compute/servers.rb
fog-test-again-1.6.0 lib/fog/vsphere/models/compute/servers.rb
fog-parser-fix-1.6.0 lib/fog/vsphere/models/compute/servers.rb
fog-maestrodev-1.7.0.20121114190951 lib/fog/vsphere/models/compute/servers.rb
fog-1.7.0 lib/fog/vsphere/models/compute/servers.rb
fog-1.6.0 lib/fog/vsphere/models/compute/servers.rb
fog-1.5.0 lib/fog/vsphere/models/compute/servers.rb
fog-1.4.0 lib/fog/vsphere/models/compute/servers.rb
brightbox-cli-0.18.1 lib/brightbox-cli/vendor/fog/lib/fog/vsphere/models/compute/servers.rb
michiels-fog-1.3.1 lib/fog/vsphere/models/compute/servers.rb
ftl-0.2.0 vendor/bundle/gems/fog-1.3.1/lib/fog/vsphere/models/compute/servers.rb
brightbox-cli-0.18.0 lib/brightbox-cli/vendor/fog/lib/fog/vsphere/models/compute/servers.rb
fog-1.3.1 lib/fog/vsphere/models/compute/servers.rb
fog-1.3.0 lib/fog/vsphere/models/compute/servers.rb
brightbox-cli-0.17.5 lib/brightbox-cli/vendor/fog/lib/fog/vsphere/models/compute/servers.rb
fog-1.2.0 lib/fog/vsphere/models/compute/servers.rb
ktheory-fog-1.1.2 lib/fog/vsphere/models/compute/servers.rb
brightbox-cli-0.17.4 lib/brightbox-cli/vendor/fog/lib/fog/vsphere/models/compute/servers.rb
brightbox-cli-0.17.3 lib/brightbox-cli/vendor/fog/lib/fog/vsphere/models/compute/servers.rb
brightbox-cli-0.17.2 lib/brightbox-cli/vendor/fog/lib/fog/vsphere/models/compute/servers.rb