class MU::Cloud::Google::Database

A database as configured in {MU::Config::BasketofKittens::databases}

Public Class Methods

cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, region: MU.curRegion, credentials: nil, flags: {}) click to toggle source

Called by {MU::Cleanup}. Locates resources that were created by the currently-loaded deployment, and purges them. @param noop [Boolean]: If true, will only print what would be done @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server @param region [String]: The cloud provider region in which to operate @return [void]

# File modules/mu/providers/google/database.rb, line 103
        def self.cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, region: MU.curRegion, credentials: nil, flags: {})
          flags["habitat"] ||= MU::Cloud::Google.defaultProject(credentials)

#          instances = MU::Cloud::Google.sql(credentials: credentials).list_instances(flags['habitat'], filter: %Q{userLabels.mu-id:"#{MU.deploy_id.downcase}"})
#          if instances and instances.items
#            instances.items.each { |instance|
#              MU.log "Deleting Cloud SQL instance #{instance.name}"
#              MU::Cloud::Google.sql(credentials: credentials).delete_instance(flags['habitat'], instance.name) if !noop
#            }
#          end
        end
find(**args) click to toggle source

Locate an existing Database or Databases and return an array containing matching GCP resource descriptors for those that match. @return [Array<Hash<String,OpenStruct>>]: The cloud provider's complete descriptions of matching Databases

# File modules/mu/providers/google/database.rb, line 63
def self.find(**args)
  args = MU::Cloud::Google.findLocationArgs(args)
end
isGlobal?() click to toggle source

Does this resource type exist as a global (cloud-wide) artifact, or is it localized to a region/zone? @return [Boolean]

# File modules/mu/providers/google/database.rb, line 87
def self.isGlobal?
  false
end
new(**args) click to toggle source

Initialize this cloud resource object. Calling super will invoke the initializer defined under {MU::Cloud}, which should set the attribtues listed in {MU::Cloud::PUBLIC_ATTRS} as well as applicable dependency shortcuts, like @vpc, for us. @param args [Hash]: Hash of named arguments passed via Ruby's double-splat

Calls superclass method
# File modules/mu/providers/google/database.rb, line 23
def initialize(**args)
  super
  @config["groomer"] = MU::Config.defaultGroomer unless @config["groomer"]
  @groomclass = MU::Groomer.loadGroomer(@config["groomer"])

  @mu_name ||= @deploy.getResourceName(@config["name"], max_length: 63)
end
quality() click to toggle source

Denote whether this resource implementation is experiment, ready for testing, or ready for production use.

# File modules/mu/providers/google/database.rb, line 93
def self.quality
  MU::Cloud::ALPHA
end
schema(_config) click to toggle source

Cloud-specific configuration properties. @param _config [MU::Config]: The calling MU::Config object @return [Array<Array,Hash>]: List of required fields, and json-schema Hash of cloud-specific configuration parameters for this resource

# File modules/mu/providers/google/database.rb, line 118
def self.schema(_config)
  toplevel_required = []
  schema = {}
  [toplevel_required, schema]
end
validateConfig(db, _configurator) click to toggle source

Cloud-specific pre-processing of {MU::Config::BasketofKittens::databases}, bare and unvalidated. @param db [Hash]: The resource to process and validate @param _configurator [MU::Config]: The overall deployment configurator of which this resource is a member @return [Boolean]: True if validation succeeded, False otherwise

# File modules/mu/providers/google/database.rb, line 128
def self.validateConfig(db, _configurator)
  ok = true

  if db["create_cluster"]
    MU.log "Database clusters not currently available in Google Cloud". MU::ERR
    ok = false
  end

  ok
end

Public Instance Methods

allowHost(cidr) click to toggle source

Permit a host to connect to the given database instance. @param cidr [String]: The CIDR-formatted IP address or block to allow access. @return [void]

# File modules/mu/providers/google/database.rb, line 81
def allowHost(cidr)
end
create() click to toggle source

Called automatically by {MU::Deploy#createResources} @return [String]: The cloud provider's identifier for this database instance.

# File modules/mu/providers/google/database.rb, line 33
        def create
          @project_id = MU::Cloud::Google.projectLookup(@config['project'], @deploy).cloud_id
          labels = {}
          MU::MommaCat.listStandardTags.each_pair { |name, value|
            if !value.nil?
              labels[name.downcase] = value.downcase.gsub(/[^a-z0-9\-\_]/i, "_")
            end
          }
          labels["name"] = MU::Cloud::Google.nameStr(@mu_name)

          settings = MU::Cloud::Google.sql(:Settings).new(
            user_labels: labels,
#            data_disk_size_gb: @config['storage'],
            tier: "D0" # XXX this is instance size, basically
          )
          instance_desc = MU::Cloud::Google.sql(:DatabaseInstance).new(
            name: MU::Cloud::Google.nameStr(@mu_name),
            settings: settings,
#            backend_type: "SECOND_GEN",
            description: @deploy.deploy_id,
            database_version: "MYSQL_5_6", # TODO construct from config
#            region: "us-central1", # XXX super restricted, this
            instance_type: "CLOUD_SQL_INSTANCE" # TODO: READ_REPLICA_INSTANCE
          )
          pp instance_desc
          pp MU::Cloud::Google.sql(credentials: @config['credentials']).insert_instance(@project_id, instance_desc)
        end
groom() click to toggle source

Called automatically by {MU::Deploy#createResources}

# File modules/mu/providers/google/database.rb, line 68
def groom
  @project_id = MU::Cloud::Google.projectLookup(@config['project'], @deploy).cloud_id
end
notify() click to toggle source

Register a description of this database instance with this deployment's metadata. Register read replicas as separate instances, while we're at it.

# File modules/mu/providers/google/database.rb, line 75
def notify
end