Sha256: 295673a415a0f4cd4c7ae5cdefa1caabe7ebc9007e0dc25a0d69621b992c8db8

Contents?: true

Size: 1.09 KB

Versions: 22

Compression:

Stored size: 1.09 KB

Contents

require 'fog/core/collection'
require 'fog/google/models/sql/instance'

module Fog
  module Google
    class SQL
      class Instances < Fog::Collection
        model Fog::Google::SQL::Instance

        ##
        # Lists all instance
        #
        # @return [Array<Fog::Google::SQL::Instance>] List of instance resources
        def all
          data = service.list_instances.body['items'] || []
          load(data)
        end

        ##
        # Retrieves an instance
        #
        # @param [String] instance_id Instance ID
        # @return [Fog::Google::SQL::Instance] Instance resource
        def get(instance_id)
          if instance = service.get_instance(instance_id).body
            new(instance)
          end
        rescue Fog::Errors::NotFound
          nil
        rescue Fog::Errors::Error => e
          # Google SQL returns a 403 if we try to access a non-existing resource
          # The default behaviour in Fog is to return a nil
          return nil if e.message == 'The client is not authorized to make this request.'
          raise e
        end
      end
    end
  end
end

Version data entries

22 entries across 20 versions & 5 rubygems

Version Path
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-google-0.1.0/lib/fog/google/models/sql/instances.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-google-0.1.0/lib/fog/google/models/sql/instances.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-google-0.1.0/lib/fog/google/models/sql/instances.rb
fog-google-0.1.3 lib/fog/google/models/sql/instances.rb
fog-google-0.1.2 lib/fog/google/models/sql/instances.rb
fog-google-0.1.1 lib/fog/google/models/sql/instances.rb
fog-google-0.1.0 lib/fog/google/models/sql/instances.rb
fog-google-0.0.9 lib/fog/google/models/sql/instances.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-google-0.0.7/lib/fog/google/models/sql/instances.rb
fog-google-0.0.7 lib/fog/google/models/sql/instances.rb
fog-google-0.0.6 lib/fog/google/models/sql/instances.rb
fog-google-0.0.5 lib/fog/google/models/sql/instances.rb
fog-google-0.0.4 lib/fog/google/models/sql/instances.rb
fog-google-0.0.3 lib/fog/google/models/sql/instances.rb
fog-google-0.0.2 lib/fog/google/models/sql/instances.rb
fog-1.29.0 lib/fog/google/models/sql/instances.rb
fog-1.28.0 lib/fog/google/models/sql/instances.rb
fog-1.27.0 lib/fog/google/models/sql/instances.rb
fog-1.26.0 lib/fog/google/models/sql/instances.rb
fog-1.25.0 lib/fog/google/models/sql/instances.rb