Sha256: b9dc81cef964e8fc34f190d1f6a061706c817b4606bb389fdd3de4050cdd6bfe

Contents?: true

Size: 1.35 KB

Versions: 11

Compression:

Stored size: 1.35 KB

Contents

require 'fog/core/collection'
require 'fog/google/models/compute/target_instance'

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

11 entries across 9 versions & 3 rubygems

Version Path
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-google-0.1.0/lib/fog/google/models/compute/target_instances.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-google-0.1.0/lib/fog/google/models/compute/target_instances.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-google-0.1.0/lib/fog/google/models/compute/target_instances.rb
fog-google-0.1.3 lib/fog/google/models/compute/target_instances.rb
fog-google-0.1.2 lib/fog/google/models/compute/target_instances.rb
fog-google-0.1.1 lib/fog/google/models/compute/target_instances.rb
fog-google-0.1.0 lib/fog/google/models/compute/target_instances.rb
fog-google-0.0.9 lib/fog/google/models/compute/target_instances.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-google-0.0.7/lib/fog/google/models/compute/target_instances.rb
fog-google-0.0.7 lib/fog/google/models/compute/target_instances.rb
fog-google-0.0.6 lib/fog/google/models/compute/target_instances.rb