Sha256: ca97b8681c85b9ae9af733be920501b2498cfd0f08548db8e7df7bb721310535

Contents?: true

Size: 1.11 KB

Versions: 14

Compression:

Stored size: 1.11 KB

Contents

module Fog
  module Compute
    class Google
      class Disks < Fog::Collection
        model Fog::Compute::Google::Disk

        def all(filters = {})
          if filters["zone"]
            data = service.list_disks(filters["zone"]).body["items"] || []
          else
            data = []
            service.list_aggregated_disks.body["items"].each_value do |zone|
              data.concat(zone["disks"]) if zone["disks"]
            end
          end
          load(data)
        end

        def get(identity, zone = nil)
          response = nil
          if zone
            response = service.get_disk(identity, zone).body
          else
            disks = service.list_aggregated_disks(:filter => "name eq .*#{identity}").body["items"]
            disk = disks.each_value.select { |zone| zone.key?("disks") }

            # It can only be 1 disk with the same name across all regions
            response = disk.first["disks"].first unless disk.empty?
          end
          return nil if response.nil?
          new(response)
        rescue Fog::Errors::NotFound
          nil
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
fog-google-0.6.0 lib/fog/compute/google/models/disks.rb
fog-google-0.5.5 lib/fog/compute/google/models/disks.rb
fog-google-0.5.4 lib/fog/compute/google/models/disks.rb
fog-google-0.5.3 lib/fog/compute/google/models/disks.rb
fog-google-0.5.2 lib/fog/compute/google/models/disks.rb
fog-google-0.5.1 lib/fog/compute/google/models/disks.rb
fog-google-0.5.0 lib/fog/compute/google/models/disks.rb
fog-google-0.4.2 lib/fog/compute/google/models/disks.rb
fog-google-0.4.1 lib/fog/compute/google/models/disks.rb
fog-google-0.4.0 lib/fog/compute/google/models/disks.rb
fog-google-0.3.2 lib/fog/compute/google/models/disks.rb
fog-google-0.3.1 lib/fog/compute/google/models/disks.rb
fog-google-0.3.0 lib/fog/compute/google/models/disks.rb
fog-google-0.2.0 lib/fog/compute/google/models/disks.rb