File: backup_runs.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 (38 lines) | stat: -rw-r--r-- 1,170 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
require "fog/core/collection"
require "fog/google/models/sql/backup_run"

module Fog
  module Google
    class SQL
      class BackupRuns < Fog::Collection
        model Fog::Google::SQL::BackupRun

        ##
        # Lists all backup runs associated with a given instance.
        #
        # @param [String] instance_id Instance ID
        # @return [Array<Fog::Google::SQL::BackupRun>] List of Backup run resources
        def all(instance_id)
          data = service.list_backup_runs(instance_id).to_h[:items] || []
          load(data)
        end

        ##
        # Retrieves a resource containing information about a backup run
        #
        # @param [String] instance_id Instance ID
        # @param [String] backup_run_id Backup Configuration ID
        # @return [Fog::Google::SQL::BackupRun] Backup run resource
        def get(instance_id, backup_run_id)
          backup_run = service.get_backup_run(instance_id, backup_run_id).to_h
          if backup_run
            new(backup_run)
          end
        rescue ::Google::Apis::ClientError => e
          raise e unless e.status_code == 404
          nil
        end
      end
    end
  end
end