Sha256: 983acd780b2f60cdc47c4352921a6900d12f318a7a68d1e3fcb4beff15eaa08e

Contents?: true

Size: 1.04 KB

Versions: 18

Compression:

Stored size: 1.04 KB

Contents

module AwsEc2
  class Base
    # constants really only used by script classes
    SCRIPTS_INFO_PATH = "tmp/data/scripts_info.txt"
    BUILD_ROOT = "tmp"

    def initialize(options={})
      @options = options.clone
      @name = randomize(@options[:name])
      AwsEc2.validate_in_project!
    end

    # Appends a short random string at the end of the ec2 instance name.
    # Later we will strip this same random string from the name.
    # Very makes it convenient.  We can just type:
    #
    #   aws-ec2 create server --randomize
    #
    # instead of:
    #
    #   aws-ec2 create server-123 --profile server
    #
    def randomize(name)
      if @options[:randomize]
        random = (0...3).map { (65 + rand(26)).chr }.join.downcase # Ex: jhx
        [name, random].join('-')
      else
        name
      end
    end

    # Strip the random string at end of the ec2 instance name
    def derandomize(name)
      if @options[:randomize]
        name.sub(/-(\w{3})$/,'') # strip the random part at the end
      else
        name
      end
    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
aws-ec2-1.4.9 lib/aws_ec2/base.rb
aws-ec2-1.4.8 lib/aws_ec2/base.rb
aws-ec2-1.4.7 lib/aws_ec2/base.rb
aws-ec2-1.4.6 lib/aws_ec2/base.rb
aws-ec2-1.4.5 lib/aws_ec2/base.rb
aws-ec2-1.4.4 lib/aws_ec2/base.rb
aws-ec2-1.4.3 lib/aws_ec2/base.rb
aws-ec2-1.4.2 lib/aws_ec2/base.rb
aws-ec2-1.4.1 lib/aws_ec2/base.rb
aws-ec2-1.4.0 lib/aws_ec2/base.rb
aws-ec2-1.3.2 lib/aws_ec2/base.rb
aws-ec2-1.3.1 lib/aws_ec2/base.rb
aws-ec2-1.3.0 lib/aws_ec2/base.rb
aws-ec2-1.2.2 lib/aws_ec2/base.rb
aws-ec2-1.2.1 lib/aws_ec2/base.rb
aws-ec2-1.2.0 lib/aws_ec2/base.rb
aws-ec2-1.1.0 lib/aws_ec2/base.rb
aws-ec2-1.0.0 lib/aws_ec2/base.rb