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
  self.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
  self.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
  self.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
83
84
# File 'lib/fog/google/models/sql/instance.rb', line 75

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

  data = service.clone_instance(self.identity, destination_name, options)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(self.instance, data.body['operation'])
  unless options.fetch(:async, true)
    operation.wait_for { ready? }
  end
  operation
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(self.identity, self.attributes[:tier], self.attributes)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(self.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



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

def database_flags
  self.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:



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

def destroy(options = {})
  requires :identity

  data = service.delete_instance(self.identity)
  operation = Fog::Google::SQL::Operations.new(:service => service).get(self.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:



137
138
139
140
141
142
143
144
145
146
# File 'lib/fog/google/models/sql/instance.rb', line 137

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

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



158
159
160
161
162
163
164
165
166
167
# File 'lib/fog/google/models/sql/instance.rb', line 158

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

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



173
174
175
# File 'lib/fog/google/models/sql/instance.rb', line 173

def ip_configuration_authorized_networks
  self.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



181
182
183
# File 'lib/fog/google/models/sql/instance.rb', line 181

def ip_configuration_enabled
  self.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



189
190
191
# File 'lib/fog/google/models/sql/instance.rb', line 189

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

#location_preference_zoneString

Returns the preferred Compute Engine zone

Returns:

  • (String)

    The preferred Compute Engine zone



205
206
207
# File 'lib/fog/google/models/sql/instance.rb', line 205

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

#location_preference_zone_follow_gae_applicationString

Returns the AppEngine application to follow

Returns:

  • (String)

    The AppEngine application to follow



197
198
199
# File 'lib/fog/google/models/sql/instance.rb', line 197

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

#pricing_planString

Returns the pricing plan for this instance

Returns:

  • (String)

    The pricing plan for this instance



213
214
215
# File 'lib/fog/google/models/sql/instance.rb', line 213

def pricing_plan
  self.settings['pricingPlan']
end

#ready?Boolean

Checks if the instance is running

Returns:

  • (Boolean)

    True if the instance is running; False otherwise



221
222
223
# File 'lib/fog/google/models/sql/instance.rb', line 221

def ready?
  self.state == RUNNABLE_STATE
end

#replication_typeString

Returns the type of replication this instance uses

Returns:

  • (String)

    The type of replication this instance uses



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

def replication_type
  self.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:



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

def reset_ssl_config(options = {})
  requires :identity

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



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

def restart(options = {})
  requires :identity

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



275
276
277
278
279
280
281
282
283
284
# File 'lib/fog/google/models/sql/instance.rb', line 275

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

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

#saveFog::Google::SQL::Instance

Saves a Cloud SQL instance

Returns:



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

def save
  self.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:



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

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

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

#settings_versionString

Returns the version of instance settings

Returns:

  • (String)

    The version of instance settings



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

def settings_version
  self.settings['settingsVersion']
end

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

Lists all of the current SSL certificates for the instance

Returns:



324
325
326
327
328
# File 'lib/fog/google/models/sql/instance.rb', line 324

def ssl_certs
  requires :identity

  service.ssl_certs.all(self.identity)
end

#tierString

Returns the tier of service for this instance

Returns:

  • (String)

    The tier of service for this instance



334
335
336
# File 'lib/fog/google/models/sql/instance.rb', line 334

def tier
  self.settings['tier']
end

#updateFog::Google::SQL::Instance

Updates settings of a Cloud SQL instance

Returns:



342
343
344
345
346
347
348
349
# File 'lib/fog/google/models/sql/instance.rb', line 342

def update
  requires :identity

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