Sha256: 792202020438ba88997b49335a86fab7c0e56c8c7616f0733c6af2bac2b34e06

Contents?: true

Size: 1.27 KB

Versions: 14

Compression:

Stored size: 1.27 KB

Contents

module Fog
  module Compute
    class Google
      class TargetInstances < Fog::Collection
        model Fog::Compute::Google::TargetInstance

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

        def get(identity, zone = nil)
          response = nil
          if zone
            response = service.get_target_instance(identity, zone).body
          else
            target_instances = service.list_aggregated_target_instances(:filter => "name eq .*#{identity}").body["items"]
            target_instance = target_instances.each_value.select { |zone| zone.key?("targetInstances") }

            # It can only be 1 target_instance with the same name across all regions
            response = target_instance.first["targetInstances"].first unless target_instance.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/target_instances.rb
fog-google-0.5.5 lib/fog/compute/google/models/target_instances.rb
fog-google-0.5.4 lib/fog/compute/google/models/target_instances.rb
fog-google-0.5.3 lib/fog/compute/google/models/target_instances.rb
fog-google-0.5.2 lib/fog/compute/google/models/target_instances.rb
fog-google-0.5.1 lib/fog/compute/google/models/target_instances.rb
fog-google-0.5.0 lib/fog/compute/google/models/target_instances.rb
fog-google-0.4.2 lib/fog/compute/google/models/target_instances.rb
fog-google-0.4.1 lib/fog/compute/google/models/target_instances.rb
fog-google-0.4.0 lib/fog/compute/google/models/target_instances.rb
fog-google-0.3.2 lib/fog/compute/google/models/target_instances.rb
fog-google-0.3.1 lib/fog/compute/google/models/target_instances.rb
fog-google-0.3.0 lib/fog/compute/google/models/target_instances.rb
fog-google-0.2.0 lib/fog/compute/google/models/target_instances.rb