class Bosh::AwsCliPlugin::MigrationHelper::RdsDb

Attributes

instance_id[RW]
receipt[RW]
subnet_ids[RW]
tag[RW]

Public Class Methods

all_rds_instances_available?(opts = {}) click to toggle source
# File lib/bosh_cli_plugin_aws/migration_helper.rb, line 105
def self.all_rds_instances_available?(opts = {})
  silent = opts[:silent]
  say("checking rds status...") unless silent
  aws_rds.databases.all? do |db_instance|
    say("  #{db_instance.db_name} #{db_instance.db_instance_status} #{db_instance.endpoint_address}") unless silent
    !db_instance.endpoint_address.nil?
  end
end
aws_rds() click to toggle source
# File lib/bosh_cli_plugin_aws/migration_helper.rb, line 85
def self.aws_rds
  @aws_rds
end
aws_rds=(arg) click to toggle source
# File lib/bosh_cli_plugin_aws/migration_helper.rb, line 89
def self.aws_rds=(arg)
  @aws_rds = arg
end
deployment_properties() click to toggle source
# File lib/bosh_cli_plugin_aws/migration_helper.rb, line 81
def self.deployment_properties
  RdsDb.receipt.fetch('deployment_manifest', {}).fetch('properties', {})
end
new(args = {}) click to toggle source
# File lib/bosh_cli_plugin_aws/migration_helper.rb, line 28
def initialize(args = {})
  vpc_receipt   = args.fetch(:vpc_receipt).fetch('vpc')
  vpc_subnets   = vpc_receipt.fetch('subnets')
  @rds_db_conf  = args.fetch(:rds_db_conf)
  @instance_id  = @rds_db_conf.fetch('instance')
  @tag          = @rds_db_conf.fetch('tag')
  @subnet_ids   = @rds_db_conf.fetch('subnets').map { |s| vpc_subnets[s] }
  @vpc_id       = vpc_receipt.fetch('id')
end
receipt() click to toggle source
# File lib/bosh_cli_plugin_aws/migration_helper.rb, line 93
def self.receipt
  @receipt ||= {}
end
was_rds_eventually_available?() click to toggle source
# File lib/bosh_cli_plugin_aws/migration_helper.rb, line 97
def self.was_rds_eventually_available?
  return true if all_rds_instances_available?(:silent => true)
  (1..540).any? do |attempt|  # wait up to 3 hours, checking every 20s
    Kernel.sleep 20
    all_rds_instances_available?
  end
end

Public Instance Methods

create!() click to toggle source
# File lib/bosh_cli_plugin_aws/migration_helper.rb, line 38
def create!
  return if RdsDb.aws_rds.database_exists? @instance_id
  creation_opts = [@instance_id, @subnet_ids, @vpc_id]

  if @rds_db_conf["aws_creation_options"]
    creation_opts << @rds_db_conf["aws_creation_options"]
  end

  @response = RdsDb.aws_rds.create_database(*creation_opts)
  output_rds_properties
end
output_rds_properties() click to toggle source
# File lib/bosh_cli_plugin_aws/migration_helper.rb, line 50
def output_rds_properties
  RdsDb.receipt["deployment_manifest"] ||= {}
  RdsDb.receipt["deployment_manifest"]["properties"] ||= {}
  RdsDb.receipt["deployment_manifest"]["properties"][@instance_id] = {
      "db_scheme" => @response[:engine],
      "roles" => [
          {
              "tag" => "admin",
              "name" => @response[:master_username],
              "password" => @response[:master_user_password]
          }
      ],
      "databases" => [
          {
              "tag" => @tag,
              "name" => @instance_id
          }
      ]
  }
end
update_receipt() click to toggle source
# File lib/bosh_cli_plugin_aws/migration_helper.rb, line 71
def update_receipt
  return unless RdsDb.deployment_properties[instance_id]

  db_instance = RdsDb.aws_rds.database(instance_id)
  RdsDb.receipt['deployment_manifest']['properties'][instance_id].merge!(
       'address' => db_instance.endpoint_address,
       'port'    => db_instance.endpoint_port
  )
end