lib/kitchen/driver/ec2.rb in kitchen-ec2-0.6.0 vs lib/kitchen/driver/ec2.rb in kitchen-ec2-0.7.0

- old
+ new

@@ -15,10 +15,11 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require 'benchmark' +require 'json' require 'fog' require 'kitchen' module Kitchen @@ -33,11 +34,25 @@ default_config :region, 'us-east-1' default_config :availability_zone, 'us-east-1b' default_config :flavor_id, 'm1.small' default_config :groups, ['default'] default_config :tags, { 'created-by' => 'test-kitchen' } - default_config :username, 'root' + default_config :aws_access_key_id do |driver| + ENV['AWS_ACCESS_KEY'] + end + default_config :aws_secret_access_key do |driver| + ENV['AWS_SECRET_KEY'] + end + default_config :aws_ssh_key_id do |driver| + ENV['AWS_SSH_KEY_ID'] + end + default_config :image_id do |driver| + driver.default_ami + end + default_config :username do |driver| + driver.default_username + end required_config :aws_access_key_id required_config :aws_secret_access_key required_config :aws_ssh_key_id required_config :image_id @@ -47,11 +62,11 @@ state[:server_id] = server.id info("EC2 instance <#{state[:server_id]}> created.") server.wait_for { print "."; ready? } ; print "(server ready)" state[:hostname] = server.public_ip_address || server.private_ip_address - wait_for_sshd(state[:hostname]) ; print "(ssh ready)\n" + wait_for_sshd(state[:hostname], config[:username]) ; print "(ssh ready)\n" debug("ec2:create '#{state[:hostname]}'") rescue Fog::Errors::Error, Excon::Errors::Error => ex raise ActionFailed, ex.message end @@ -63,10 +78,19 @@ info("EC2 instance <#{state[:server_id]}> destroyed.") state.delete(:server_id) state.delete(:hostname) end + def default_ami + region = amis["regions"][config[:region]] + region && region[instance.platform.name] + end + + def default_username + amis["usernames"][instance.platform.name] || "root" + end + private def connection Fog::Compute.new( :provider => :aws, @@ -97,9 +121,17 @@ debug("ec2:image_id '#{config[:image_id]}'") debug("ec2:groups '#{config[:groups]}'") debug("ec2:tags '#{config[:tags]}'") debug("ec2:key_name '#{config[:aws_ssh_key_id]}'") debug("ec2:subnet_id '#{config[:subnet_id]}'") + end + + def amis + @amis ||= begin + json_file = File.join(File.dirname(__FILE__), + %w{.. .. .. data amis.json}) + JSON.load(IO.read(json_file)) + end end end end end