mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[google|sql] Add support for BackupRuns
- Add models and requests for BackupRuns
This commit is contained in:
parent
200d81558f
commit
04bf64fb04
5 changed files with 140 additions and 0 deletions
34
lib/fog/google/models/sql/backup_run.rb
Normal file
34
lib/fog/google/models/sql/backup_run.rb
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
require 'fog/core/model'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module Google
|
||||||
|
class SQL
|
||||||
|
##
|
||||||
|
# A database instance backup run resource
|
||||||
|
#
|
||||||
|
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/backupRuns
|
||||||
|
class BackupRun < Fog::Model
|
||||||
|
identity :backup_configuration, :aliases => 'backupConfiguration'
|
||||||
|
|
||||||
|
attribute :due_time, :aliases => 'dueTime'
|
||||||
|
attribute :end_time, :aliases => 'endTime'
|
||||||
|
attribute :enqueued_time, :aliases => 'enqueuedTime'
|
||||||
|
attribute :error
|
||||||
|
attribute :instance
|
||||||
|
attribute :kind
|
||||||
|
attribute :start_time, :aliases => 'startTime'
|
||||||
|
attribute :status
|
||||||
|
|
||||||
|
DONE_STATE = 'DONE'
|
||||||
|
|
||||||
|
##
|
||||||
|
# Checks if the instance backup run is done
|
||||||
|
#
|
||||||
|
# @return [Boolean] True if the backup run is done; False otherwise
|
||||||
|
def ready?
|
||||||
|
self.state == DONE_STATE
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
38
lib/fog/google/models/sql/backup_runs.rb
Normal file
38
lib/fog/google/models/sql/backup_runs.rb
Normal file
|
@ -0,0 +1,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 and configuration
|
||||||
|
#
|
||||||
|
# @param [String] instance_id Instance ID
|
||||||
|
# @param [String] backup_configuration_id Backup Configuration ID
|
||||||
|
# @return [Array<Fog::Google::SQL::BackupRun>] List of Backup run resources
|
||||||
|
def all(instance_id, backup_configuration_id)
|
||||||
|
data = service.list_backup_runs(instance_id, backup_configuration_id).body['items'] || []
|
||||||
|
load(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Retrieves a resource containing information about a backup run
|
||||||
|
#
|
||||||
|
# @param [String] instance_id Instance ID
|
||||||
|
# @param [String] backup_configuration_id Backup Configuration ID
|
||||||
|
# @param [String] due_time The time when this run is due to start in RFC 3339 format
|
||||||
|
# @return [Fog::Google::SQL::BackupRun] Backup run resource
|
||||||
|
def get(instance_id, backup_configuration_id, due_time)
|
||||||
|
if backup_run = service.get_backup_run(instance_id, backup_configuration_id, due_time).body
|
||||||
|
new(backup_run)
|
||||||
|
end
|
||||||
|
rescue Fog::Errors::NotFound
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
30
lib/fog/google/requests/sql/get_backup_run.rb
Normal file
30
lib/fog/google/requests/sql/get_backup_run.rb
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
module Fog
|
||||||
|
module Google
|
||||||
|
class SQL
|
||||||
|
##
|
||||||
|
# Retrieves a resource containing information about a backup run
|
||||||
|
#
|
||||||
|
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/backupRuns/get
|
||||||
|
|
||||||
|
class Real
|
||||||
|
def get_backup_run(instance_id, backup_configuration_id, due_time)
|
||||||
|
api_method = @sql.backup_runs.get
|
||||||
|
parameters = {
|
||||||
|
'project' => @project,
|
||||||
|
'instance' => instance_id,
|
||||||
|
'backupConfiguration' => backup_configuration_id,
|
||||||
|
'dueTime' => due_time,
|
||||||
|
}
|
||||||
|
|
||||||
|
request(api_method, parameters)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
def get_backup_run(instance_id, backup_configuration_id, due_time)
|
||||||
|
Fog::Mock.not_implemented
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
30
lib/fog/google/requests/sql/list_backup_runs.rb
Normal file
30
lib/fog/google/requests/sql/list_backup_runs.rb
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
module Fog
|
||||||
|
module Google
|
||||||
|
class SQL
|
||||||
|
##
|
||||||
|
# Lists all backup runs associated with a given instance and configuration in the
|
||||||
|
# reverse chronological order of the enqueued time
|
||||||
|
#
|
||||||
|
# @see https://developers.google.com/cloud-sql/docs/admin-api/v1beta3/backupRuns/list
|
||||||
|
|
||||||
|
class Real
|
||||||
|
def list_backup_runs(instance_id, backup_configuration_id)
|
||||||
|
api_method = @sql.backup_runs.list
|
||||||
|
parameters = {
|
||||||
|
'project' => @project,
|
||||||
|
'instance' => instance_id,
|
||||||
|
'backupConfiguration' => backup_configuration_id,
|
||||||
|
}
|
||||||
|
|
||||||
|
request(api_method, parameters)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
def list_backup_runs(instance_id, backup_configuration_id)
|
||||||
|
Fog::Mock.not_implemented
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -16,6 +16,10 @@ module Fog
|
||||||
# MODELS
|
# MODELS
|
||||||
model_path 'fog/google/models/sql'
|
model_path 'fog/google/models/sql'
|
||||||
|
|
||||||
|
# Backup Run
|
||||||
|
model :backup_run
|
||||||
|
collection :backup_runs
|
||||||
|
|
||||||
# Flag
|
# Flag
|
||||||
model :flag
|
model :flag
|
||||||
collection :flags
|
collection :flags
|
||||||
|
@ -40,6 +44,10 @@ module Fog
|
||||||
# REQUESTS
|
# REQUESTS
|
||||||
request_path 'fog/google/requests/sql'
|
request_path 'fog/google/requests/sql'
|
||||||
|
|
||||||
|
# Backup Run
|
||||||
|
request :get_backup_run
|
||||||
|
request :list_backup_runs
|
||||||
|
|
||||||
# Flag
|
# Flag
|
||||||
request :list_flags
|
request :list_flags
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue