Skip to content

Commit

Permalink
Feature: look up snapshot ids by region from chef config data.
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 960d7abba089d9046bf567b434ed126bd66221c3
Author: Chris Howe <howech@infochimps.com>
Date:   Wed May 28 17:01:59 2014 -0500

    When building a machine, lookup the snapshot name in chef config data so that we can associate a different snapshot with each name by region.

    Change-Id: Id12fcff2e9c1b3d88e571a47b5454c3b3cbd0ed5

commit 2b1ed75634ab6c134c73ea287147e293c97a7f70
Author: Chris Howe <howech@infochimps.com>
Date:   Wed May 28 17:01:03 2014 -0500

    Added an error message to the "mismatched regions" error that allows you to know which setting is wrong.

    Change-Id: I681ef1e59984798bc95acce2f8a4940c2236dffe

commit ca0afc982125ba5aa30fec0c3f459aae195f0ca0
Author: Chris Howe <howech@infochimps.com>
Date:   Wed May 28 17:00:33 2014 -0500

    removed crufty VOLUME_IDS lookup for snashot_id

    Change-Id: I01621d6d94bc3d373e333e0e134b8a12100a6a9c

Change-Id: I1a4d6e91c3d5ce81dc359490b02711bed8291ae1
  • Loading branch information
Chris Howe committed May 28, 2014
1 parent cda9a32 commit be017d4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
17 changes: 16 additions & 1 deletion lib/ironfan/broker/computer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,29 @@ class Computer < Builder
field :name, String
field :bogus, Array, :default => []

def lookup_snapshot_id(region, snapshot_name)
keys = [region.to_s, snapshot_name.to_s]
return Chef::Config[:ec2_snapshot_info][ keys ][:snapshot_id] rescue nil
end

def initialize(*args)
super
providers[:chef] ||= Ironfan::Provider::ChefServer
return unless server
providers[:iaas] = server.selected_cloud.provider
volumes = server.volumes.values
puts server.selected_cloud
region = server.selected_cloud.region


# Turn snapshot names into snapshot ids corresponding to the server region
volumes.each do |vol|
vol.snapshot_id || vol.snapshot_id(lookup_snapshot_id(region, vol.snapshot_name))
end

volumes += server.implied_volumes
volumes.each{|vol| self.drive vol.name, :volume => vol }

rescue StandardError => err ; err.polish("#{self.class} on '#{args.inspect}'") rescue nil ; raise
end

Expand Down Expand Up @@ -365,7 +380,7 @@ def slice(cluster_name = nil, facet_name = nil, slice_indexes = nil)
select do |mach|
mach.bogus? || (
# facet match, and index match (or no indexes specified)
(mach.server.cluster_name == cluster_name) &&
(mach.server.cluster_name == cluster_name) &&
(mach.server.facet_name == facet_name || facet_name.nil?) &&
(slice_array.include?(mach.server.index) || slice_indexes.nil?))
end
Expand Down
11 changes: 0 additions & 11 deletions lib/ironfan/dsl/volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@ class Volume < Ironfan::Dsl
magic :snapshot_name, String
magic :tags, Hash, :default => {}

VOLUME_IDS ||= {}
VOLUME_IDS.merge!({
:blank_xfs => 'snap-d9c1edb1',
:blank_xfs_tokyo => 'snap-049d1921',
:blank_xfs_california => 'snap-514b5c5a', # us-west-1
})

def snapshot_id(*)
Ironfan.todo("CODE SMELL: EBS specific information in Dsl::Volume::VOLUME_IDS")
super || VOLUME_IDS[snapshot_name]
end
end

class RaidGroup < Volume
Expand Down
9 changes: 7 additions & 2 deletions lib/ironfan/provider/ec2/machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,13 @@ def self.lint(computer)
errors['Missing client'] = info unless computer.client?
errors['Missing private_key'] = computer.client unless computer.private_key
#
all_asserted_regions = [Ec2.connection.region, cloud.region, Chef::Config[:knife][:region], Ironfan.chef_config[:region]].compact.uniq
errors["mismatched region"] = all_asserted_regions unless all_asserted_regions.count == 1
asserted_regions = {
:ec2_connection => Ec2.connection.region,
:cloud => cloud.region,
:knife => Chef::Config[:knife][:region],
:chef_config => Ironfan.chef_config[:region]
}
errors["mismatched region"] = asserted_regions unless asserted_regions.values.compact.uniq.count == 1
#
errors
end
Expand Down

0 comments on commit be017d4

Please sign in to comment.