Class: MCollective::Application::Describe_filter

Inherits:
MCollective::Application show all
Defined in:
lib/mcollective/application/describe_filter.rb

Instance Method Summary collapse

Methods inherited from MCollective::Application

[], []=, #application_cli_arguments, #application_description, #application_failure, #application_options, application_options, #application_parse_options, #application_usage, #clioptions, #configuration, description, #disconnect, exclude_argument_sections, #halt, #halt_code, #help, intialize_application_options, option, #options, #rpcclient, #run, usage, #validate_cli_options, #validate_option

Methods included from RPC

const_missing, discovered, #empty_filter?, #printrpc, #printrpcstats, #rpcclient, #rpcoptions, stats

Instance Method Details

#describe_c_filter(classes) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/mcollective/application/describe_filter.rb', line 53

def describe_c_filter(classes)
  puts "-C filter expands to the following class checks:"
  puts
  classes.each do |c|
    puts "  " + get_class_string(c)
  end
end

#describe_f_filter(facts) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/mcollective/application/describe_filter.rb', line 45

def describe_f_filter(facts)
  puts "-F filter expands to the following fact comparisons:"
  puts
  facts.each do |f|
    puts "  " + get_fact_string(f[:fact], f[:value], f[:operator])
  end
end

#describe_s_filter(stack) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mcollective/application/describe_filter.rb', line 9

def describe_s_filter(stack)
  indent = "  "
  old_indent = "  "
  puts "-S Query expands to the following instructions:"
  puts
  stack.each do |token|
    if token.keys[0] == "statement"
      if token.values[0] =~ /(<=|>=|=|=~|=)/
        op = $1
        k,v = token.values[0].split(op)
        puts indent + get_fact_string(k, v, op)
      else
        puts indent + get_class_string(token.values[0])
      end
    elsif token.keys[0] == "fstatement"
      v = token.values[0]
      result_string = indent + "Execute the Data Query '#{v["name"]}'"
      if v["params"]
        result_string += " with parameters (#{v["params"]})"
      end
      result_string += ". "
      result_string += "Check if the query's '#{v["value"]}' value #{v["operator"]} '#{v["r_compare"]}'  "
      puts result_string
    elsif token.keys[0] == "("
      puts indent + "("
      old_indent = indent
      indent *= 2
    elsif token.keys[0] == ")"
      indent = old_indent
      puts indent + ")"
    else
      puts indent + token.keys[0].upcase
    end
  end
end

#mainObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/mcollective/application/describe_filter.rb', line 61

def main
  if !(@options[:filter]["fact"].empty?)
    describe_f_filter(@options[:filter]["fact"])
    puts
  end

  if !(@options[:filter]["cf_class"].empty?)
    describe_c_filter(@options[:filter]["cf_class"])
    puts
  end

  if !(@options[:filter]["compound"].empty?)
    describe_s_filter(@options[:filter]["compound"][0])
    puts
  end
end