Class: SmallWonder::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/small_wonder/utils.rb

Class Method Summary collapse

Class Method Details

.consume_config_file(cli, file) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/small_wonder/utils.rb', line 4

def self.consume_config_file(cli, file)
  if File.exists?(file)
    SmallWonder::Config.from_file(file)
    SmallWonder::Config.merge!(cli.config)

    SmallWonder::Log.level(SmallWonder::Config.log_level)
  else
    SmallWonder::Log.error("#{file} doesn't exist!")
    exit(1)
  end
end

.write_file(data, path) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/small_wonder/utils.rb', line 26

def self.write_file(data, path)
  begin
    file = File.new(path,"w")
    file.puts data
  rescue Exception => e
    SmallWonder::Log.error("Error writing file (#{path}).")
    SmallWonder::Log.error(e)
    exit(1)
  ensure
    file.close
  end
end

.write_node_data_file(node) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/small_wonder/utils.rb', line 16

def self.write_node_data_file(node)
  data = Chef::Node.load(node)

  file = "#{SmallWonder::Config.chef_repo_path}/nodes/#{node}.json"

  SmallWonder::Log.info("Writing node file (#{file}).")

  write_file(JSON.pretty_generate(data), file)
end