Class: Stem::Family::Member

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/stem/family/member.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#get_filter_opts, #swirl, #tags_to_filter, #tagset_to_hash

Constructor Details

#initialize(family, config, options = {}) ⇒ Member

Returns a new instance of Member.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/stem/family/member.rb', line 7

def initialize(family, config, options = {})
  aggregate_hash_options_for_ami!(config)
  @time = Time.now.utc
  @family = family
  @sha1 = if options[:userdata]
    Family.image_hash(config, options.delete(:userdata))
  elsif options[:sha1]
    options.delete(:sha1)
  else
    raise ArgumentError.new("Must specify either userdata or sha1")
  end
  @source_ami = config['ami']
end

Instance Attribute Details

#familyObject (readonly)

Returns the value of attribute family.



5
6
7
# File 'lib/stem/family/member.rb', line 5

def family
  @family
end

#sha1Object (readonly)

Returns the value of attribute sha1.



5
6
7
# File 'lib/stem/family/member.rb', line 5

def sha1
  @sha1
end

#source_amiObject (readonly)

Returns the value of attribute source_ami.



5
6
7
# File 'lib/stem/family/member.rb', line 5

def source_ami
  @source_ami
end

#timeObject (readonly)

Returns the value of attribute time.



5
6
7
# File 'lib/stem/family/member.rb', line 5

def time
  @time
end

Instance Method Details

#==(member) ⇒ Object



21
22
23
24
25
# File 'lib/stem/family/member.rb', line 21

def ==(member)
  [ :family, :sha1, :source_ami, :time ].map do |attribute|
    self.send(attribute) == member.send(attribute)
  end.all?
end

#already_built?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/stem/family/member.rb', line 27

def already_built?
  !Stem::Image.tagged(:family => family, :sha1 => sha1).empty?
end

#architectureObject



31
32
33
# File 'lib/stem/family/member.rb', line 31

def architecture
  Stem::Image.describe(source_ami)['architecture']
end

#capture(instance_id) ⇒ Object



35
36
37
# File 'lib/stem/family/member.rb', line 35

def capture(instance_id)
  Stem::Image.create(name, instance_id)
end

#nameObject



39
40
41
# File 'lib/stem/family/member.rb', line 39

def name
  [family, timestamp.gsub(':', '_'), architecture].join('-')
end

#tag(ami_id) ⇒ Object



43
44
45
# File 'lib/stem/family/member.rb', line 43

def tag(ami_id)
  Stem::Tag.create(ami_id, tags)
end

#tagsObject



47
48
49
50
51
52
53
54
# File 'lib/stem/family/member.rb', line 47

def tags
  {
    :created => timestamp,
    :family => family,
    :sha1 => sha1,
    :source_ami => source_ami
  }
end

#timestampObject



56
57
58
# File 'lib/stem/family/member.rb', line 56

def timestamp
  time.iso8601
end