Sha256: 0223625d051d9819977f97afa5986579827dfe1994ca4f9fe8de569c4913a6b1

Contents?: true

Size: 1.33 KB

Versions: 8

Compression:

Stored size: 1.33 KB

Contents

module Ironfan
  class Provider

    class Ec2 < Ironfan::IaasProvider

      def self.resources
        [ Machine, EbsVolume, KeyPair, SecurityGroup ]
      end

      #
      # Utility functions
      #
      def self.connection
        @@connection ||= Fog::Compute.new({
          :provider              => 'AWS',
          :aws_access_key_id     => Chef::Config[:knife][:aws_access_key_id],
          :aws_secret_access_key => Chef::Config[:knife][:aws_secret_access_key],
          :region                => Chef::Config[:knife][:region]
        })
      end
      
      def self.aws_account_id()
        Chef::Config[:knife][:aws_account_id]
      end

      # Ensure that a fog object (machine, volume, etc.) has the proper tags on it
      def self.ensure_tags(tags,fog)
        tags.delete_if {|k, v| fog.tags[k] == v.to_s  rescue false }
        return if tags.empty?

        Ironfan.step(fog.name,"tagging with #{tags.inspect}", :green)
        tags.each do |k, v|
          Chef::Log.debug( "tagging #{fog.name} with #{k} = #{v}" )
          Ironfan.safely do
            config = {:key => k, :value => v.to_s, :resource_id => fog.id }
            connection.tags.create(config)
          end
        end
      end

      def self.applicable(computer)
        computer.server and computer.server.clouds.include?(:ec2)
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ironfan-4.0.9 lib/ironfan/provider/ec2.rb
ironfan-4.0.8 lib/ironfan/provider/ec2.rb
ironfan-4.0.5 lib/ironfan/provider/ec2.rb
ironfan-4.0.4 lib/ironfan/provider/ec2.rb
ironfan-4.0.3 lib/ironfan/provider/ec2.rb
ironfan-4.0.2 lib/ironfan/provider/ec2.rb
ironfan-4.0.1 lib/ironfan/provider/ec2.rb
ironfan-4.0.0 lib/ironfan/provider/ec2.rb