File: instances.rb

package info (click to toggle)
ruby-fog-google 1.19.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,568 kB
  • sloc: ruby: 16,775; makefile: 3
file content (39 lines) | stat: -rw-r--r-- 1,148 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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.to_h[:items] || []
          load(data)
        end

        ##
        # Retrieves an instance
        #
        # @param [String] instance_id Instance ID
        # @return [Fog::Google::SQL::Instance] Instance resource
        def get(instance_id)
          instance = service.get_instance(instance_id).to_h
          # XXX if we pass `nil` to get() it returns empty DB object with
          # kind set to "sql#instancesList"
          # see https://github.com/google/google-api-ruby-client/issues/699
          if instance[:kind].eql?("sql#instance")
            new(instance)
          end
        rescue ::Google::Apis::ClientError => e
          raise e unless e.status_code == 404 || e.status_code == 403
          nil
        end
      end
    end
  end
end