Class: Aerosol::LaunchConfiguration

Inherits:
Object
  • Object
show all
Includes:
AWSModel, Dockly::Util::Logger::Mixin
Defined in:
lib/aerosol/launch_configuration.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AWSModel

#create, #default_identifier, #destroy, #exists?, included, #initialize, #namespaced_name

Class Method Details

.request_allObject



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/aerosol/launch_configuration.rb', line 67

def self.request_all
  next_token = nil
  lcs = []

  begin
    new_lcs = request_all_for_token(next_token)
    lcs.concat(new_lcs.launch_configurations)
    next_token = new_lcs.next_token
  end until next_token.nil?

  lcs
end

.request_all_for_token(next_token) ⇒ Object



62
63
64
65
# File 'lib/aerosol/launch_configuration.rb', line 62

def self.request_all_for_token(next_token)
  options = next_token.nil? ? {} : { next_token: next_token }
  Aerosol::AWS.auto_scaling.describe_launch_configurations(options)
end

Instance Method Details

#all_instancesObject



55
56
57
58
59
60
# File 'lib/aerosol/launch_configuration.rb', line 55

def all_instances
  Aerosol::Instance.all.select { |instance|
    !instance.launch_configuration.nil? &&
      (instance.launch_configuration.launch_configuration_name == launch_configuration_name)
  }.each(&:description)
end

#ami(name = nil) ⇒ Object



24
25
26
27
# File 'lib/aerosol/launch_configuration.rb', line 24

def ami(name=nil)
  warn 'Warning: Use `image_id` instead `ami` for a launch configuration'
  image_id(name)
end

#corrected_user_dataObject



97
98
99
100
101
# File 'lib/aerosol/launch_configuration.rb', line 97

def corrected_user_data
  realized_user_data = user_data.is_a?(Proc) ? user_data.call : user_data

  Base64.encode64(Aerosol::Util.strip_heredoc(realized_user_data || ''))
end

#create!Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/aerosol/launch_configuration.rb', line 38

def create!
  ensure_present! :image_id, :instance_type

  info self.to_s
  conn.create_launch_configuration({
    image_id: image_id,
    instance_type: instance_type,
    launch_configuration_name: launch_configuration_name,
  }.merge(create_options))
  sleep 10 # TODO: switch to fog models and .wait_for { ready? }
end

#destroy!Object



50
51
52
53
# File 'lib/aerosol/launch_configuration.rb', line 50

def destroy!
  info self.to_s
  conn.delete_launch_configuration(launch_configuration_name: launch_configuration_name)
end

#iam_role(name = nil) ⇒ Object



29
30
31
32
# File 'lib/aerosol/launch_configuration.rb', line 29

def iam_role(name=nil)
  warn 'Warning: Use `iam_instance_profile` instead `iam_role` for a launch configuration'
  iam_instance_profile(name)
end

#launch_configuration_name(arg = nil) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/aerosol/launch_configuration.rb', line 15

def launch_configuration_name(arg = nil)
  if arg
    raise "You cannot set the launch_configuration_name directly" unless from_aws
    @launch_configuration_name = arg
  else
    @launch_configuration_name || default_identifier
  end
end

#security_group(group) ⇒ Object



34
35
36
# File 'lib/aerosol/launch_configuration.rb', line 34

def security_group(group)
  security_groups << group
end

#to_sObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/aerosol/launch_configuration.rb', line 80

def to_s
  %{Aerosol::LaunchConfiguration { \
"launch_configuration_name" => "#{launch_configuration_name}", \
"image_id" => "#{image_id}", \
"instance_type" => "#{instance_type}", \
"security_groups" => #{security_groups.to_s}, \
"user_data" => "#{user_data}", \
"iam_instance_profile" => "#{iam_instance_profile}", \
"kernel_id" => "#{kernel_id}", \
"key_name" => "#{key_name}", \
"spot_price" => "#{spot_price}", \
"created_time" => "#{created_time}", \
"block_device_mappings" => #{block_device_mappings}", \
"ebs_optimized" => #{ebs_optimized} \
}}
end