Module: KnifeSous::ProcessorCommand

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(other) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/knife_sous/processor_command.rb', line 5

def self.included(other)
  other.class_eval do
    option :node_manifest_file,
      :long        => '--node-manifest-file NODE_MANIFEST_FILE',
      :description => 'Alternate location for node manifest config file',
      :default => File.join("nodes", "nodes.rb")
  end
end

Instance Method Details

#manifest_file_pathObject



39
40
41
42
# File 'lib/knife_sous/processor_command.rb', line 39

def manifest_file_path
  config[:node_manifest_file] ||= default_config[:node_manifest_file]
  @manifest_file_path ||= File.expand_path(File.join(Dir.pwd, config[:node_manifest_file]))
end

#process_configObject



44
45
46
47
48
49
# File 'lib/knife_sous/processor_command.rb', line 44

def process_config
  validate_config!
  root_namespace = Namespace.new('')
  root_namespace.instance_eval(File.read(manifest_file_path), manifest_file_path)
  root_namespace
end

#root_namespaceObject



35
36
37
# File 'lib/knife_sous/processor_command.rb', line 35

def root_namespace
  @root_namespace ||= process_config
end

#search(target_qualifiers = []) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/knife_sous/processor_command.rb', line 26

def search(target_qualifiers = [])
  namespace = root_namespace
  target_qualifiers.each do |target_qualifier|
    return nil if namespace.nil?
    namespace = namespace.keep_if { |item| item.name == target_qualifier }.first
  end
  namespace
end

#validate_config!Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/knife_sous/processor_command.rb', line 14

def validate_config!
  unless File.exists?(manifest_file_path)
    ui.fatal("Couldn't find #{manifest_file_path}")
    exit 1
  end
  unless File.readable?(manifest_file_path)
    ui.fatal("Can't read #{manifest_file_path}")
    exit 1
  end
  true
end