Class: Rivet::LaunchConfig

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

Constant Summary collapse

LC_ATTRIBUTES =
['key_name','image_id','instance_type','security_groups','iam_instance_profile','bootstrap']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec, id_prefix = "rivet_") ⇒ LaunchConfig

Returns a new instance of LaunchConfig.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rivet/launch_config.rb', line 12

def initialize(spec,id_prefix="rivet_")
  @id_prefix = id_prefix

  LC_ATTRIBUTES.each do |a|

    if respond_to? "normalize_#{a}".to_sym
      spec[a] = self.send("normalize_#{a.to_sym}",spec[a])
    end

    Rivet::Log.debug("Setting LaunchConfig @#{a} to #{spec[a]}")
    instance_variable_set("@#{a}",spec[a])
  end
end

Instance Attribute Details

#id_prefixObject (readonly)

Returns the value of attribute id_prefix.



10
11
12
# File 'lib/rivet/launch_config.rb', line 10

def id_prefix
  @id_prefix
end

Instance Method Details

#identityObject



30
31
32
# File 'lib/rivet/launch_config.rb', line 30

def identity
  @identity ||= generate_identity
end

#saveObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rivet/launch_config.rb', line 34

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?

    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



26
27
28
# File 'lib/rivet/launch_config.rb', line 26

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