Class: Bosh::AwsCliPlugin::MigrationHelper::RdsDb

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh_cli_plugin_aws/migration_helper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ RdsDb

Returns a new instance of RdsDb.


28
29
30
31
32
33
34
35
36
# 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

Instance Attribute Details

#instance_idObject

Returns the value of attribute instance_id.


26
27
28
# File 'lib/bosh_cli_plugin_aws/migration_helper.rb', line 26

def instance_id
  @instance_id
end

#receiptObject

Returns the value of attribute receipt.


26
27
28
# File 'lib/bosh_cli_plugin_aws/migration_helper.rb', line 26

def receipt
  @receipt
end

#subnet_idsObject

Returns the value of attribute subnet_ids.


26
27
28
# File 'lib/bosh_cli_plugin_aws/migration_helper.rb', line 26

def subnet_ids
  @subnet_ids
end

#tagObject

Returns the value of attribute tag.


26
27
28
# File 'lib/bosh_cli_plugin_aws/migration_helper.rb', line 26

def tag
  @tag
end

Class Method Details

.all_rds_instances_available?(opts = {}) ⇒ Boolean

Returns:

  • (Boolean)

105
106
107
108
109
110
111
112
# 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_rdsObject


85
86
87
# File 'lib/bosh_cli_plugin_aws/migration_helper.rb', line 85

def self.aws_rds
  @aws_rds
end

.aws_rds=(arg) ⇒ Object


89
90
91
# File 'lib/bosh_cli_plugin_aws/migration_helper.rb', line 89

def self.aws_rds=(arg)
  @aws_rds = arg
end

.deployment_propertiesObject


81
82
83
# File 'lib/bosh_cli_plugin_aws/migration_helper.rb', line 81

def self.deployment_properties
  RdsDb.receipt.fetch('deployment_manifest', {}).fetch('properties', {})
end

.receiptObject


93
94
95
# File 'lib/bosh_cli_plugin_aws/migration_helper.rb', line 93

def self.receipt
  @receipt ||= {}
end

.was_rds_eventually_available?Boolean

Returns:

  • (Boolean)

97
98
99
100
101
102
103
# 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

Instance Method Details

#create!Object


38
39
40
41
42
43
44
45
46
47
48
# 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_propertiesObject


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 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_receiptObject


71
72
73
74
75
76
77
78
79
# 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