Class: Rivet::LaunchConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/rivet/as/launch_config.rb

Constant Summary collapse

ATTRIBUTES =
[
  :bootstrap,
  :detailed_instance_monitoring,
  :spot_price
] + BASE_AWS_ATTRIBUTES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, id_prefix = 'rivet_') ⇒ LaunchConfig

Returns a new instance of LaunchConfig.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rivet/as/launch_config.rb', line 16

def initialize(config, id_prefix = 'rivet_')
  @config    = config
  @id_prefix = id_prefix

  ATTRIBUTES.each do |a|
    if config.respond_to?(a)
      Rivet::Log.debug "Setting LaunchConfig @#{a} to #{config.send(a)}"
      instance_variable_set("@#{a}", config.send(a))
    end
  end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



14
15
16
# File 'lib/rivet/as/launch_config.rb', line 14

def config
  @config
end

#id_prefixObject (readonly)

Returns the value of attribute id_prefix.



14
15
16
# File 'lib/rivet/as/launch_config.rb', line 14

def id_prefix
  @id_prefix
end

Instance Method Details

#identityObject



32
33
34
# File 'lib/rivet/as/launch_config.rb', line 32

def identity
  @identity ||= generate_identity
end

#saveObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rivet/as/launch_config.rb', line 36

def save
  AwsUtils.verify_security_groups(security_groups)

  lc_collection = AWS::AutoScaling.new.launch_configurations

  if lc_collection[identity].exists?
    Rivet::Log.info "Launch configuration #{identity} already exists in AWS"
  else
    options = {}
    options[:key_pair]                      = key_name                      unless key_name.nil?
    options[:security_groups]               = security_groups               unless security_groups.nil?
    options[:user_data]                     = user_data                     unless user_data.nil?
    options[:iam_instance_profile]          = iam_instance_profile          unless iam_instance_profile.nil?
    options[:associate_public_ip_address]   = associate_public_ip_address   unless associate_public_ip_address.nil?
    options[:detailed_instance_monitoring]  = detailed_instance_monitoring  unless detailed_instance_monitoring.nil?
    options[:block_device_mappings]         = block_device_mappings         unless block_device_mappings.nil?
    options[:kernel_id]                     = kernel_id                     unless kernel_id.nil?
    options[:ramdisk_id]                    = ramdisk_id                    unless ramdisk_id.nil?
    options[:spot_price]                    = spot_price                    unless spot_price.nil?

    Rivet::Log.info "Saving launch configuration #{identity} to AWS"
    Rivet::Log.debug "Launch Config options:\n #{options.inspect}"
    lc_collection.create(identity, image_id, instance_type, options)
  end
end

#user_dataObject



28
29
30
# File 'lib/rivet/as/launch_config.rb', line 28

def user_data
  @user_data ||= Bootstrap.new(@config).user_data
end