Class: Forger::Create

Inherits:
Base
  • Object
show all
Includes:
AwsServices, ErrorMessages
Defined in:
lib/forger/create.rb,
lib/forger/create/info.rb,
lib/forger/create/params.rb,
lib/forger/create/waiter.rb,
lib/forger/create/error_messages.rb

Defined Under Namespace

Modules: ErrorMessages Classes: Info, Params, Waiter

Constant Summary

Constants inherited from Base

Base::BUILD_ROOT, Base::SCRIPTS_INFO_PATH

Instance Method Summary collapse

Methods included from ErrorMessages

#handle_ec2_service_error!, #invalid_group_not_found, #invalid_parameter_combination, #invalid_subnet_id_not_found, #map_exception_to_method, #print_error_message

Methods included from AwsServices

#cfn, #ec2, #s3

Methods inherited from Base

#derandomize, #initialize, #randomize

Constructor Details

This class inherits a constructor from Forger::Base

Instance Method Details

#paramsObject

params are main derived from profile files



46
47
48
# File 'lib/forger/create.rb', line 46

def params
  @params ||= Params.new(@options).generate
end

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/forger/create.rb', line 9

def run
  Profile.new(@options).check!
  Hook.run(:before_run_instances, @options)

  sync_scripts_to_s3

  puts "Creating EC2 instance #{@name.color(:green)}"
  info = Info.new(@options, params)
  info.ec2_params
  if @options[:noop]
    puts "NOOP mode enabled. EC2 instance not created."
    return
  end

  resp = run_instances(params)

  instance_id = resp.instances.first.instance_id
  info.spot(instance_id)
  puts "EC2 instance with profile #{@name.color(:green)} created: #{instance_id} 🎉"
  puts "Visit https://console.aws.amazon.com/ec2/home to check on the status"
  info.cloudwatch(instance_id)

  Waiter.new(@options.merge(instance_id: instance_id)).wait
end

#run_instances(params) ⇒ Object



34
35
36
37
38
# File 'lib/forger/create.rb', line 34

def run_instances(params)
  ec2.run_instances(params)
rescue Aws::EC2::Errors::ServiceError => e
  handle_ec2_service_error!(e)
end

#sync_scripts_to_s3Object



40
41
42
43
# File 'lib/forger/create.rb', line 40

def sync_scripts_to_s3
  upload = Script::Upload.new(@options)
  upload.run
end