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"
PENDING_CREATE_STATE =
"PENDING_CREATE"
RUNNABLE_STATE =
"RUNNABLE"
SUSPENDED_STATE =
"SUSPENDED"
UNKNOWN_STATE =
"UNKNOWN_STATE"

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["activationPolicy"]
end

#autorized_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 autorized_gae_applications
  settings["authorizedGaeApplications"]
end

#backup_configurationArray<Hash>

Returns the daily backup configuration for the instance

Returns:

  • (Array<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["backupConfiguration"]
end

#clone(destination_name, options = {}) ⇒ 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

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

    Method options

Options Hash (options):

  • :log_filename (String)

    Name of the binary log file for a Cloud SQL instance

  • :log_position (Integer)

    Position (offset) within the binary log file

  • :async (Boolean)

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

Returns:



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

def clone(destination_name, options = {})
  requires :identity

  data = service.clone_instance(identity, destination_name, options)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(instance, data.body["operation"])
  operation.wait_for { ready? } unless options.fetch(:async, true)
  operation
end

#createFog::Google::SQL::Instance

Creates a Cloud SQL instance

Returns:



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

def create
  requires :identity

  data = service.insert_instance(identity, attributes[:tier], attributes)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(instance, data.body["operation"])
  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



101
102
103
# File 'lib/fog/google/models/sql/instance.rb', line 101

def database_flags
  settings["databaseFlags"]
end

#destroy(options = {}) ⇒ Fog::Google::SQL::Operation

Deletes a Cloud SQL instance

Parameters:

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

    Method options

Options Hash (options):

  • :async (Boolean)

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

Returns:



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

def destroy(options = {})
  requires :identity

  data = service.delete_instance(identity)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(instance, data.body["operation"])
  unless options.fetch(:async, true)
    # DISABLED: A delete instance operation never reachs a 'DONE' state (bug?)
    # operation.wait_for { ready? }
  end
  operation
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:



135
136
137
138
139
140
141
142
# File 'lib/fog/google/models/sql/instance.rb', line 135

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

  data = service.export_instance(identity, uri, options)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(instance, data.body["operation"])
  operation.wait_for { ready? } unless options.fetch(:async, true)
  operation
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:



154
155
156
157
158
159
160
161
# File 'lib/fog/google/models/sql/instance.rb', line 154

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

  data = service.import_instance(identity, uri, options)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(instance, data.body["operation"])
  operation.wait_for { ready? } unless options.fetch(:async, true)
  operation
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



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

def ip_configuration_authorized_networks
  settings.fetch("ipConfiguration", {})["authorizedNetworks"]
end

#ip_configuration_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



175
176
177
# File 'lib/fog/google/models/sql/instance.rb', line 175

def ip_configuration_enabled
  settings.fetch("ipConfiguration", {})["enabled"]
end

#ip_configuration_require_sslBoolean

Returns whether the mysqld should default to ‘REQUIRE X509’ for users connecting over IP

Returns:

  • (Boolean)

    Whether the mysqld should default to ‘REQUIRE X509’ for users connecting over IP



183
184
185
# File 'lib/fog/google/models/sql/instance.rb', line 183

def ip_configuration_require_ssl
  settings.fetch("ipConfiguration", {})["requireSsl"]
end

#location_preference_zoneString

Returns the preferred Compute Engine zone

Returns:

  • (String)

    The preferred Compute Engine zone



199
200
201
# File 'lib/fog/google/models/sql/instance.rb', line 199

def location_preference_zone
  settings.fetch("locationPreference", {})["zone"]
end

#location_preference_zone_follow_gae_applicationString

Returns the AppEngine application to follow

Returns:

  • (String)

    The AppEngine application to follow



191
192
193
# File 'lib/fog/google/models/sql/instance.rb', line 191

def location_preference_zone_follow_gae_application
  settings.fetch("locationPreference", {})["followGaeApplication"]
end

#pricing_planString

Returns the pricing plan for this instance

Returns:

  • (String)

    The pricing plan for this instance



207
208
209
# File 'lib/fog/google/models/sql/instance.rb', line 207

def pricing_plan
  settings["pricingPlan"]
end

#ready?Boolean

Checks if the instance is running

Returns:

  • (Boolean)

    True if the instance is running; False otherwise



215
216
217
# File 'lib/fog/google/models/sql/instance.rb', line 215

def ready?
  state == RUNNABLE_STATE
end

#replication_typeString

Returns the type of replication this instance uses

Returns:

  • (String)

    The type of replication this instance uses



223
224
225
# File 'lib/fog/google/models/sql/instance.rb', line 223

def replication_type
  settings["replicationType"]
end

#reset_ssl_config(options = {}) ⇒ Fog::Google::SQL::Operation

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

Parameters:

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

    Method options

Options Hash (options):

  • :async (Boolean)

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

Returns:



233
234
235
236
237
238
239
240
# File 'lib/fog/google/models/sql/instance.rb', line 233

def reset_ssl_config(options = {})
  requires :identity

  data = service.reset_instance_ssl_config(identity)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(instance, data.body["operation"])
  operation.wait_for { ready? } unless options.fetch(:async, true)
  operation
end

#restart(options = {}) ⇒ Fog::Google::SQL::Operation

Restarts a Cloud SQL instance

Parameters:

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

    Method options

Options Hash (options):

  • :async (Boolean)

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

Returns:



248
249
250
251
252
253
254
255
# File 'lib/fog/google/models/sql/instance.rb', line 248

def restart(options = {})
  requires :identity

  data = service.restart_instance(identity)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(instance, data.body["operation"])
  operation.wait_for { ready? } unless options.fetch(:async, true)
  operation
end

#restore_backup(backup_configuration, due_time, options = {}) ⇒ Fog::Google::SQL::Operation

Restores a backup of a Cloud SQL instance

Parameters:

  • backup_configuration (String)

    The identifier of the backup configuration

  • due_time (String)

    The time when this run is due to start in RFC 3339 format

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

    Method options

Options Hash (options):

  • :async (Boolean)

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

Returns:



265
266
267
268
269
270
271
272
# File 'lib/fog/google/models/sql/instance.rb', line 265

def restore_backup(backup_configuration, due_time, options = {})
  requires :identity

  data = service.restore_instance_backup(identity, backup_configuration, due_time)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(instance, data.body["operation"])
  operation.wait_for { ready? } unless options.fetch(:async, true)
  operation
end

#saveFog::Google::SQL::Instance

Saves a Cloud SQL instance

Returns:



278
279
280
# File 'lib/fog/google/models/sql/instance.rb', line 278

def save
  etag ? update : create
end

#set_root_password(password, options = {}) ⇒ Fog::Google::SQL::Operation

Sets the password for the root user

Parameters:

  • password (String)

    The password for the root user

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

    Method options

Options Hash (options):

  • :async (Boolean)

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

Returns:



289
290
291
292
293
294
295
296
# File 'lib/fog/google/models/sql/instance.rb', line 289

def set_root_password(password, options = {})
  requires :identity

  data = service.set_instance_root_password(identity, password)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(instance, data.body["operation"])
  operation.wait_for { ready? } unless options.fetch(:async, true)
  operation
end

#settings_versionString

Returns the version of instance settings

Returns:

  • (String)

    The version of instance settings



302
303
304
# File 'lib/fog/google/models/sql/instance.rb', line 302

def settings_version
  settings["settingsVersion"]
end

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

Lists all of the current SSL certificates for the instance

Returns:



310
311
312
313
314
# File 'lib/fog/google/models/sql/instance.rb', line 310

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



320
321
322
# File 'lib/fog/google/models/sql/instance.rb', line 320

def tier
  settings["tier"]
end

#updateFog::Google::SQL::Instance

Updates settings of a Cloud SQL instance

Returns:



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

def update
  requires :identity

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