class Bosh::AwsCliPlugin::Migrator
Attributes
migration_path[R]
Public Class Methods
new(config)
click to toggle source
# File lib/bosh_cli_plugin_aws/migrator.rb, line 5 def initialize(config) @config = config @migration_path = MigrationHelper.aws_migration_directory end
Public Instance Methods
environment_migrations()
click to toggle source
# File lib/bosh_cli_plugin_aws/migrator.rb, line 34 def environment_migrations @environment_migrations ||= load_migrations_for_env end
migrate()
click to toggle source
# File lib/bosh_cli_plugin_aws/migrator.rb, line 10 def migrate return unless needs_migration? run_migrations(pending_migrations) end
migrate_version(version)
click to toggle source
# File lib/bosh_cli_plugin_aws/migrator.rb, line 16 def migrate_version(version) return unless needs_migration? migration_to_run = pending_migrations.detect do |migration| migration.version == version.to_i end run_migrations([migration_to_run]) end
migrations()
click to toggle source
# File lib/bosh_cli_plugin_aws/migrator.rb, line 30 def migrations @migrations ||= load_migrations end
needs_migration?()
click to toggle source
# File lib/bosh_cli_plugin_aws/migrator.rb, line 38 def needs_migration? ensure_bucket_exists environment_migrations.nil? || environment_migrations != migrations end
pending_migrations()
click to toggle source
# File lib/bosh_cli_plugin_aws/migrator.rb, line 26 def pending_migrations migrations - environment_migrations end
Private Instance Methods
aws_s3()
click to toggle source
# File lib/bosh_cli_plugin_aws/migrator.rb, line 47 def aws_s3 @aws_s3 ||= Bosh::AwsCliPlugin::S3.new(@config['aws']) end
bucket_name()
click to toggle source
# File lib/bosh_cli_plugin_aws/migrator.rb, line 61 def bucket_name if aws_s3.bucket_exists?("#{@config['name']}-bosh-artifacts") "#{@config['name']}-bosh-artifacts" else "#{s3_safe_vpc_domain}-bosh-artifacts" end end
ensure_bucket_exists()
click to toggle source
# File lib/bosh_cli_plugin_aws/migrator.rb, line 51 def ensure_bucket_exists unless aws_s3.bucket_exists?(bucket_name) aws_s3.create_bucket(bucket_name) end end
load_migrations()
click to toggle source
# File lib/bosh_cli_plugin_aws/migrator.rb, line 80 def load_migrations Dir.glob(File.join(migration_path, "*.rb")).collect do |migration_file_path| version, name = migration_file_path.scan(/([0-9]+)_([_a-z0-9]*).rb\z/).first MigrationProxy.new(name,version.to_i) end.sort end
load_migrations_for_env()
click to toggle source
# File lib/bosh_cli_plugin_aws/migrator.rb, line 87 def load_migrations_for_env yaml_file = aws_s3.fetch_object_contents(bucket_name, migrations_name) || "" migrations = YAML.load(yaml_file) || [] migrations.collect do |migration_yaml| MigrationProxy.new(migration_yaml['name'],migration_yaml['version'].to_i) end.sort end
migrations_name()
click to toggle source
# File lib/bosh_cli_plugin_aws/migrator.rb, line 69 def migrations_name "aws_migrations/migrations.yaml" end
record_migration(migration)
click to toggle source
# File lib/bosh_cli_plugin_aws/migrator.rb, line 96 def record_migration(migration) environment_migrations << migration migration_yaml = YAML.dump(environment_migrations.collect do |m| m.to_hash end) aws_s3.upload_to_bucket(bucket_name, migrations_name, migration_yaml) end
run_migrations(migrations_to_run)
click to toggle source
# File lib/bosh_cli_plugin_aws/migrator.rb, line 73 def run_migrations(migrations_to_run) migrations_to_run.each do |migration| migration.load_class.new(@config, bucket_name).run record_migration(migration) end end
s3_safe_vpc_domain()
click to toggle source
# File lib/bosh_cli_plugin_aws/migrator.rb, line 57 def s3_safe_vpc_domain @config['vpc']['domain'].gsub('.', '-') end