Sha256: 2702e8e09820986663f03465f6c71f8b70392bb95dbaa0f56a8dadf4b3031a69

Contents?: true

Size: 1.16 KB

Versions: 37

Compression:

Stored size: 1.16 KB

Contents

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

module Fog
  module Compute
    class Vsphere

      class Volumes < Fog::Collection

        attribute :server

        model Fog::Compute::Vsphere::Volume

        def all(filters = {})
          requires :server

          case server
            when Fog::Compute::Vsphere::Server
              load service.list_vm_volumes(server.id)
            when Fog::Compute::Vsphere::Template
              load service.list_template_volumes(server.id)
            else
              raise 'volumes should have vm or template'
            end

          self.each { |volume| volume.server_id = server.id }
          self
        end

        def get(id)
          new service.get_volume(id)
        end

        def new(attributes = {})
          if server
            # Default to the root volume datastore if one is not configured.
            datastore = ! attributes.has_key?(:datastore) && self.any? ? self.first.datastore : nil

            super({ :server_id => server.id, :datastore => datastore }.merge!(attributes))
          else
            super
          end
        end

     end
    end
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
fog-1.22.0 lib/fog/vsphere/models/compute/volumes.rb
fog-1.21.0 lib/fog/vsphere/models/compute/volumes.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/vsphere/models/compute/volumes.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/vsphere/models/compute/volumes.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/vsphere/models/compute/volumes.rb
fog-1.20.0 lib/fog/vsphere/models/compute/volumes.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/vsphere/models/compute/volumes.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/vsphere/models/compute/volumes.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/vsphere/models/compute/volumes.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/vsphere/models/compute/volumes.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/vsphere/models/compute/volumes.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/vsphere/models/compute/volumes.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/vsphere/models/compute/volumes.rb
fog-1.19.0 lib/fog/vsphere/models/compute/volumes.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/vsphere/models/compute/volumes.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/vsphere/models/compute/volumes.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/vsphere/models/compute/volumes.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/vsphere/models/compute/volumes.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/vsphere/models/compute/volumes.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/vsphere/models/compute/volumes.rb