Class: Fog::Google::SQL::Instance

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/google/models/sql/instance.rb

Constant Summary collapse

MAINTENANCE_STATE =
"MAINTENANCE".freeze
PENDING_CREATE_STATE =
"PENDING_CREATE".freeze
RUNNABLE_STATE =
"RUNNABLE".freeze
SUSPENDED_STATE =
"SUSPENDED".freeze
UNKNOWN_STATE =
"UNKNOWN_STATE".freeze

Instance Method Summary collapse

Instance Method Details

#activation_policyString

Returns the activation policy for this instance

Returns:

  • (String)

    The activation policy for this instance


46
47
48
# File 'lib/fog/google/models/sql/instance.rb', line 46

def activation_policy
  settings[:activation_policy]
end

#authorized_gae_applicationsArray<String>

Returns the AppEngine app ids that can access this instance

Returns:

  • (Array<String>)

    The AppEngine app ids that can access this instance


54
55
56
# File 'lib/fog/google/models/sql/instance.rb', line 54

def authorized_gae_applications
  settings[:authorized_gae_applications]
end

#backup_configurationHash

Returns the daily backup configuration for the instance

Returns:

  • (Hash)

    The daily backup configuration for the instance


62
63
64
# File 'lib/fog/google/models/sql/instance.rb', line 62

def backup_configuration
  settings["backup_configuration"]
end

#clone(destination_name, async: true, log_filename: nil, log_position: nil) ⇒ Fog::Google::SQL::Operation

Creates a Cloud SQL instance as a clone of the source instance

Parameters:

  • destination_name (String)

    Name of the Cloud SQL instance to be created as a clone

  • async (Boolean) (defaults to: true)

    If the operation must be performed asynchronously (true by default)

  • log_filename (String) (defaults to: nil)

    Name of the binary log file for a Cloud SQL instance

  • log_position (Integer) (defaults to: nil)

    Position (offset) within the binary log file

Returns:


74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fog/google/models/sql/instance.rb', line 74

def clone(destination_name, async: true, log_filename: nil, log_position: nil)
  requires :identity

  data = service.clone_instance(
    identity, destination_name,
    :log_filename => log_filename,
    :log_position => log_position
  )
  operation = Fog::Google::SQL::Operations.new(:service => service).get(data.name)
  operation.tap { |o| o.wait_for { ready? } unless async }
end

#createFog::Google::SQL::Instance

Creates a Cloud SQL instance

Returns:


90
91
92
93
94
95
96
97
# File 'lib/fog/google/models/sql/instance.rb', line 90

def create
  requires :identity

  data = service.insert_instance(identity, attributes[:tier], attributes)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(data.name)
  operation.wait_for { !pending? }
  reload
end

#database_flagsArray<Hash>

Returns the database flags passed to the instance at startup

Returns:

  • (Array<Hash>)

    The database flags passed to the instance at startup


103
104
105
# File 'lib/fog/google/models/sql/instance.rb', line 103

def database_flags
  settings[:database_flags]
end

#destroy(async: nil) ⇒ Fog::Google::SQL::Operation

Deletes a Cloud SQL instance

Parameters:

  • :async (Boolean)

    If the operation must be performed asynchronously (true by default)

Returns:


112
113
114
115
116
117
118
# File 'lib/fog/google/models/sql/instance.rb', line 112

def destroy(async: nil)
  requires :identity

  data = service.delete_instance(identity)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(data.name)
  operation.tap { |o| o.wait_for { ready? } unless async }
end

#export(uri, options: {}) ⇒ Fog::Google::SQL::Operation

Exports data from a Cloud SQL instance to a Google Cloud Storage bucket as a MySQL dump file

Parameters:

  • uri (String)

    The path to the file in Google Cloud Storage where the export will be stored, or where it was already stored

  • options (Hash) (defaults to: {})

    Method options

Options Hash (options:):

  • :databases (Array<String>)

    Databases (for example, guestbook) from which the export is made. If unspecified, all databases are exported.

  • :tables (Array<String>)

    Tables to export, or that were exported, from the specified database. If you specify tables, specify one and only one database.

  • :async (Boolean)

    If the operation must be performed asynchronously (true by default)

Returns:


132
133
134
135
136
137
138
# File 'lib/fog/google/models/sql/instance.rb', line 132

def export(uri, options: {})
  requires :identity

  data = service.export_instance(identity, uri, options)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(data.name)
  operation.tap { |o| o.wait_for { ready? } unless async }
end

#import(uri, options = {}) ⇒ Fog::Google::SQL::Operation

Imports data into a Cloud SQL instance from a MySQL dump file in Google Cloud Storage

Parameters:

  • uri (Array<String>)

    A path to the MySQL dump file in Google Cloud Storage from which the import is made

  • options (Hash) (defaults to: {})

    Method options

Options Hash (options):

  • :database (String)

    The database (for example, guestbook) to which the import is made. If not set, it is assumed that the database is specified in the file to be imported.

  • :async (Boolean)

    If the operation must be performed asynchronously (true by default)

Returns:


150
151
152
153
154
155
156
# File 'lib/fog/google/models/sql/instance.rb', line 150

def import(uri, options = {})
  requires :identity

  data = service.import_instance(identity, uri, options)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(data.name)
  operation.tap { |o| o.wait_for { ready? } unless options.fetch(:async, true) }
end

#ip_configuration_authorized_networksArray<String>

Returns the list of external networks that are allowed to connect to the instance using the IP

Returns:

  • (Array<String>)

    The list of external networks that are allowed to connect to the instance using the IP


162
163
164
165
# File 'lib/fog/google/models/sql/instance.rb', line 162

def ip_configuration_authorized_networks
  settings.fetch(:ip_configuration, {})
          .fetch(:authorized_networks, [])
end

#ip_configuration_ipv4_enabledBoolean

Returns whether the instance should be assigned an IP address or not

Returns:

  • (Boolean)

    Whether the instance should be assigned an IP address or not


171
172
173
# File 'lib/fog/google/models/sql/instance.rb', line 171

def ip_configuration_ipv4_enabled
  settings.fetch(:ip_configuration, {})[:ipv4_enabled]
end

#ip_configuration_require_sslBoolean

Returns whether SSL connections over IP should be enforced or not.

Returns:

  • (Boolean)

    Whether SSL connections over IP should be enforced or not.


179
180
181
# File 'lib/fog/google/models/sql/instance.rb', line 179

def ip_configuration_require_ssl
  settings.fetch(:ip_configuration, {})[:require_ssl]
end

#location_preference_zoneString

Returns the preferred Compute Engine zone

Returns:

  • (String)

    The preferred Compute Engine zone


195
196
197
# File 'lib/fog/google/models/sql/instance.rb', line 195

def location_preference_zone
  settings.fetch(:location_preference, {})[:zone]
end

#location_preference_zone_follow_gae_applicationString

Returns the AppEngine application to follow

Returns:

  • (String)

    The AppEngine application to follow


187
188
189
# File 'lib/fog/google/models/sql/instance.rb', line 187

def location_preference_zone_follow_gae_application
  settings.fetch(:location_preference, {})[:follow_gae_application]
end

#pricing_planString

Returns the pricing plan for this instance

Returns:

  • (String)

    The pricing plan for this instance


203
204
205
# File 'lib/fog/google/models/sql/instance.rb', line 203

def pricing_plan
  settings[:pricing_plan]
end

#ready?Boolean

Checks if the instance is running

Returns:

  • (Boolean)

    True if the instance is running; False otherwise


211
212
213
# File 'lib/fog/google/models/sql/instance.rb', line 211

def ready?
  state == RUNNABLE_STATE
end

#reloadFog::Google::SQL::Instance

Reload a Cloud SQL instance

Returns:


314
315
316
317
318
319
320
# File 'lib/fog/google/models/sql/instance.rb', line 314

def reload
  requires :identity

  data = collection.get(identity)
  merge_attributes(data.attributes)
  self
end

#replication_typeString

Returns the type of replication this instance uses

Returns:

  • (String)

    The type of replication this instance uses


219
220
221
# File 'lib/fog/google/models/sql/instance.rb', line 219

def replication_type
  settings[:replication_type]
end

#reset_ssl_config(async: true) ⇒ Fog::Google::SQL::Operation

Deletes all client certificates and generates a new server SSL certificate for the instance

Parameters:

  • async (Boolean) (defaults to: true)

    If the operation must be performed asynchronously (true by default)

Returns:


228
229
230
231
232
233
234
# File 'lib/fog/google/models/sql/instance.rb', line 228

def reset_ssl_config(async: true)
  requires :identity

  data = service.reset_instance_ssl_config(identity)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(data.name)
  operation.tap { |o| o.wait_for { ready? } unless async }
end

#restart(async: true) ⇒ Fog::Google::SQL::Operation

Restarts a Cloud SQL instance

Parameters:

  • async (Boolean) (defaults to: true)

    If the operation must be performed asynchronously (true by default)

Returns:


241
242
243
244
245
246
247
# File 'lib/fog/google/models/sql/instance.rb', line 241

def restart(async: true)
  requires :identity

  data = service.restart_instance(identity)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(data.name)
  operation.tap { |o| o.wait_for { ready? } unless async }
end

#restore_backup(backup_run_id, async: true) ⇒ Fog::Google::SQL::Operation

Restores a backup of a Cloud SQL instance

Parameters:

  • backup_run_id (String)

    The identifier of the backup configuration

  • async (Boolean) (defaults to: true)

    If the operation must be performed asynchronously (true by default)

Returns:


255
256
257
258
259
260
261
# File 'lib/fog/google/models/sql/instance.rb', line 255

def restore_backup(backup_run_id, async: true)
  requires :identity

  data = service.restore_instance_backup(identity, backup_run_id)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(data.name)
  operation.tap { |o| o.wait_for { ready? } unless async }
end

#saveFog::Google::SQL::Instance

Saves a Cloud SQL instance

Returns:


267
268
269
# File 'lib/fog/google/models/sql/instance.rb', line 267

def save
  etag ? update : create
end

#settings_versionString

Returns the version of instance settings

Returns:

  • (String)

    The version of instance settings


275
276
277
# File 'lib/fog/google/models/sql/instance.rb', line 275

def settings_version
  settings[:settings_version]
end

#ssl_certsArray<Fog::Google::SQL::SslCert>

Lists all of the current SSL certificates for the instance

Returns:


283
284
285
286
287
# File 'lib/fog/google/models/sql/instance.rb', line 283

def ssl_certs
  requires :identity

  service.ssl_certs.all(identity)
end

#tierString

Returns the tier of service for this instance

Returns:

  • (String)

    The tier of service for this instance


293
294
295
# File 'lib/fog/google/models/sql/instance.rb', line 293

def tier
  settings[:tier]
end

#updateFog::Google::SQL::Instance

Updates settings of a Cloud SQL instance

Returns:


301
302
303
304
305
306
307
308
# File 'lib/fog/google/models/sql/instance.rb', line 301

def update
  requires :identity, :settings_version, :tier

  data = service.update_instance(identity, settings_version, tier, settings)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(data.name)
  operation.wait_for { !pending? }
  reload
end