Class: Vanagon::Engine::Ec2
Instance Attribute Summary collapse
-
#ami ⇒ Object
Returns the value of attribute ami.
-
#instance_type ⇒ Object
Returns the value of attribute instance_type.
-
#key ⇒ Object
Returns the value of attribute key.
-
#key_name ⇒ Object
Returns the value of attribute key_name.
-
#shutdown_behavior ⇒ Object
Returns the value of attribute shutdown_behavior.
-
#subnet_id ⇒ Object
Returns the value of attribute subnet_id.
-
#userdata ⇒ Object
Returns the value of attribute userdata.
Attributes inherited from Base
Instance Method Summary collapse
- #get_userdata ⇒ Object
-
#initialize(platform, target = nil, **opts) ⇒ Ec2
constructor
rubocop:disable Metrics/AbcSize.
- #instance ⇒ Object
- #instances ⇒ Object
- #name ⇒ Object
- #select_target ⇒ Object
- #teardown ⇒ Object
Methods inherited from Base
#build_host_name, #dispatch, #get_remote_workdir, #retrieve_built_artifact, #setup, #ship_workdir, #startup, #validate_platform
Constructor Details
#initialize(platform, target = nil, **opts) ⇒ Ec2
rubocop:disable Metrics/AbcSize
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vanagon/engine/ec2.rb', line 13 def initialize(platform, target = nil, **opts) # rubocop:disable Metrics/AbcSize super @ami = @platform.aws_ami @target_user = @platform.target_user @subnet_id = @platform.aws_subnet_id @userdata = @platform.aws_user_data @region = @platform.aws_region || 'us-east-1' @key_name = @platform.aws_key_name @key = @platform.aws_key @instance_type = @platform.aws_instance_type || "t1.micro" @required_attributes = ["ssh_port", "aws_ami", "aws_key_name"] @shutdown_behavior = @platform.aws_shutdown_behavior @ec2 = ::Aws::EC2::Client.new(region: @region) @resource = ::Aws::EC2::Resource.new(client: @ec2) end |
Instance Attribute Details
#ami ⇒ Object
Returns the value of attribute ami.
10 11 12 |
# File 'lib/vanagon/engine/ec2.rb', line 10 def ami @ami end |
#instance_type ⇒ Object
Returns the value of attribute instance_type.
11 12 13 |
# File 'lib/vanagon/engine/ec2.rb', line 11 def instance_type @instance_type end |
#key ⇒ Object
Returns the value of attribute key.
10 11 12 |
# File 'lib/vanagon/engine/ec2.rb', line 10 def key @key end |
#key_name ⇒ Object
Returns the value of attribute key_name.
10 11 12 |
# File 'lib/vanagon/engine/ec2.rb', line 10 def key_name @key_name end |
#shutdown_behavior ⇒ Object
Returns the value of attribute shutdown_behavior.
10 11 12 |
# File 'lib/vanagon/engine/ec2.rb', line 10 def shutdown_behavior @shutdown_behavior end |
#subnet_id ⇒ Object
Returns the value of attribute subnet_id.
11 12 13 |
# File 'lib/vanagon/engine/ec2.rb', line 11 def subnet_id @subnet_id end |
#userdata ⇒ Object
Returns the value of attribute userdata.
10 11 12 |
# File 'lib/vanagon/engine/ec2.rb', line 10 def userdata @userdata end |
Instance Method Details
#get_userdata ⇒ Object
35 36 37 38 39 |
# File 'lib/vanagon/engine/ec2.rb', line 35 def get_userdata unless @userdata.nil? Base64.encode64(ERB.new(@userdata).result(binding)) end end |
#instance ⇒ Object
56 57 58 |
# File 'lib/vanagon/engine/ec2.rb', line 56 def instance @instance ||= instances.first end |
#instances ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/vanagon/engine/ec2.rb', line 41 def instances @instances ||= @resource.create_instances({ image_id: ami, min_count: 1, max_count: 1, key_name: key_name, instance_type: instance_type, subnet_id: subnet_id, user_data: get_userdata, monitoring: { enabled: false, } }) end |
#name ⇒ Object
31 32 33 |
# File 'lib/vanagon/engine/ec2.rb', line 31 def name 'ec2' end |
#select_target ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/vanagon/engine/ec2.rb', line 60 def select_target VanagonLogger.info "Instance created id: #{instance.id}" VanagonLogger.info "Created instance waiting for status ok" @ec2.wait_until(:instance_status_ok, instance_ids: [instance.id]) VanagonLogger.info "Instance running" @target = instance.private_ip_address rescue ::Aws::Waiters::Errors::WaiterFailed => error fail "Failed to wait for ec2 instance to start got error #{error}" end |
#teardown ⇒ Object
70 71 72 73 |
# File 'lib/vanagon/engine/ec2.rb', line 70 def teardown VanagonLogger.info "Destroying instance on AWS id: #{instance.id}" instances.batch_terminate! end |