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

#create(async = false) ⇒ Fog::Google::SQL::Instance

Creates a Cloud SQL instance

Parameters:

  • async (Boolean) (defaults to: false)

    If the operation must be performed asynchronously

    This is true by default since SQL instances return Google::Apis::ClientError: invalidState whenever an instance is in a transition process (creation, deletion, etc.) which makes it hard to operate unless one puts guard clauses on Google::Apis::ClientError everywhere.

    TODO: Rethink this when API graduates out of beta. (Written as of V1beta4)

Returns:



97
98
99
100
101
102
103
104
# File 'lib/fog/google/models/sql/instance.rb', line 97

def create(async = false)
  requires :identity

  data = service.insert_instance(identity, attributes[:tier], attributes)
  operation = Fog::Google::SQL::Operations.new(service: service).get(data.name)
  operation.wait_for { ready? } unless async
  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



110
111
112
# File 'lib/fog/google/models/sql/instance.rb', line 110

def database_flags
  settings[:database_flags]
end

#destroy(async = false) ⇒ Fog::Google::SQL::Operation

Deletes a Cloud SQL instance

Parameters:

  • async (Boolean) (defaults to: false)

    If the operation must be performed asynchronously (false by default) See Fog::Google::SQL::Instance.create on details why default is set this way.

Returns:



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/fog/google/models/sql/instance.rb', line 121

def destroy(async = false)
  requires :identity

  # TODO(2.0): Add a deprecation warning here, depending on the decision in #27
  # This is a compatibility fix leftover from breaking named parameter change
  if async.is_a?(Hash)
    async = async[:async]
  end

  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:



147
148
149
150
151
152
153
# File 'lib/fog/google/models/sql/instance.rb', line 147

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:



165
166
167
168
169
170
171
# File 'lib/fog/google/models/sql/instance.rb', line 165

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



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

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



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

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.



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

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



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

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



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

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



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

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



226
227
228
# File 'lib/fog/google/models/sql/instance.rb', line 226

def ready?
  state == RUNNABLE_STATE
end

#reloadFog::Google::SQL::Instance

Reload a Cloud SQL instance

Returns:



329
330
331
332
333
334
335
# File 'lib/fog/google/models/sql/instance.rb', line 329

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



234
235
236
# File 'lib/fog/google/models/sql/instance.rb', line 234

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:



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

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:



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

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:



270
271
272
273
274
275
276
# File 'lib/fog/google/models/sql/instance.rb', line 270

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:



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

def save
  etag ? update : create
end

#settings_versionString

Returns the version of instance settings

Returns:

  • (String)

    The version of instance settings



290
291
292
# File 'lib/fog/google/models/sql/instance.rb', line 290

def settings_version
  settings[:settings_version]
end

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

Lists all of the current SSL certificates for the instance

Returns:



298
299
300
301
302
# File 'lib/fog/google/models/sql/instance.rb', line 298

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



308
309
310
# File 'lib/fog/google/models/sql/instance.rb', line 308

def tier
  settings[:tier]
end

#updateFog::Google::SQL::Instance

Updates settings of a Cloud SQL instance

Returns:



316
317
318
319
320
321
322
323
# File 'lib/fog/google/models/sql/instance.rb', line 316

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 { ready? }
  reload
end