module Chef::Knife::StencilBase
This module is included everywhere, as per the conventions for knife plugins. It includes various helper methods.
Public Instance Methods
build_plugin_klass(plugin, command, action)
click to toggle source
Return a real Class built from the options given. Used to build EC2ServerCreate, for example
# File lib/chef/knife/stencil_base.rb, line 65 def build_plugin_klass(plugin, command, action) begin klass = Object.const_get('Chef').const_get('Knife').const_get(plugin.to_s.capitalize + command.to_s.capitalize + action.to_s.capitalize) klass.respond_to?(:new) rescue NameError, NoMethodError => e puts("I can't find the correct gem for plugin #{config[:plugin]}, it does not declare class #{klas}, or that class does not repsond to 'new'. #{e}") puts("Try: gem install knife-#{config[:plugin]}") end return klass end
explain(string)
click to toggle source
Output method for explanation sub-command. Very basic at present.
# File lib/chef/knife/stencil_base.rb, line 78 def explain(string) if $*[2].to_s.downcase == "explain" puts "EXPLAIN: #{string}" end end
invoked_as_stencil?()
click to toggle source
Return true if the stencil plugin has been invoked
# File lib/chef/knife/stencil_base.rb, line 35 def invoked_as_stencil? if $*[0].downcase == 'stencil' return true end return false end
locate_config_value(key)
click to toggle source
This is used seemingly at random inside knife. Force our values.
# File lib/chef/knife/stencil_base.rb, line 29 def locate_config_value(key) key = key.to_sym config[key] || Chef::Config[:knife][key] end
normalize_path(path, root)
click to toggle source
Do exactly that
# File lib/chef/knife/stencil_base.rb, line 56 def normalize_path(path, root) unless path[0] == File::SEPARATOR # FIXME: This will probably make this nasty on Windows return File.join(root, path).to_s else return path end end
stencil_root()
click to toggle source
Determine where to look for stencils
# File lib/chef/knife/stencil_base.rb, line 44 def stencil_root stencil_root = '/' unless Chef::Config[:knife][:stencil_root] && Dir.exist?(Chef::Config[:knife][:stencil_root]) && stencil_root = Chef::Config[:knife][:stencil_root] [ '/etc/chef/stencils', "#{File.join(ENV['HOME'], '.chef/stencils')}" ].each do |directory| stencil_root = directory if Dir.exist?(directory) end end return stencil_root end