Sha256: f73fe8e7a039eada08b3a6a9d4f5bad8cb1471927992afecf96a0d4625b68013

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

require 'ridley'
require 'silver_spurs/chef_exceptions'

module SilverSpurs
  class ChefInterface

    def initialize(options)
      @chef_config = options
    end

    def chef_run(node_name, run_list = [])
      node = find_node node_name
      hostname = find_hostname(node_name, node)
      if run_list.size > 0
        ridley.node.run hostname, "chef-client -o '#{run_list.join(',')}'"
      else
        node.chef_run
      end
    end

    def update_node_attributes(node_name, attributes)
      node = find_node node_name
      attributes.each { |attr_name, value| node.set_chef_attribute(attr_name, value) }
      node.save
    end

    private

    def ridley
      @ridley ||= Ridley.new(@chef_config)
    end

    def find_node(node_name)
      node = ridley.node.find(node_name)
      raise NodeNotFoundException.new unless node
      node
    end

    # Waterfall through the options, use the node name as a last resort
    def find_hostname(node_name, node)
      return node.public_hostname if node.public_hostname
      return node.public_ipv4 if node.public_ipv4
      node_name
    end
    
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
silver_spurs-2.0.0.rc7 lib/silver_spurs/chef_interface.rb
silver_spurs-2.0.0.rc5 lib/silver_spurs/chef_interface.rb
silver_spurs-2.0.0.rc4 lib/silver_spurs/chef_interface.rb