Class: Exec::NodeLs
- Inherits:
-
ExecutableCommand
- Object
- ExecutableCommand
- Exec::NodeLs
- Defined in:
- lib/exec/node_ls.rb
Overview
Allows the user to list the nodes along with some piece of information.
Instance Attribute Summary
Attributes inherited from ExecutableCommand
#argv, #command_name, #logger, #options, #stderr, #stdin, #stdout, #values
Instance Method Summary collapse
-
#display_list(list_nodes) ⇒ Object
private
Displays the elements of the list return [String] The output standard.
-
#exec ⇒ Object
private
The execution of the command.
-
#initialize(argv, stdin, stdout, stderr, command_name) ⇒ NodeLs
constructor
Default constructor of the class.
-
#is_correct_status(status_node) ⇒ Boolean
private
True if the status is correct, false else.
-
#set_options ⇒ Object
private
Parse and check the parameters of the function.
Methods inherited from ExecutableCommand
#check_parameters, #create_logger, #run
Constructor Details
#initialize(argv, stdin, stdout, stderr, command_name) ⇒ NodeLs
Note:
Overrides default constructor by passing CustomCommandOption to super().
Default constructor of the class.
18 19 20 |
# File 'lib/exec/node_ls.rb', line 18 def initialize(argv, stdin, stdout, stderr, command_name) super(argv, stdin, stdout, stderr, command_name) end |
Instance Method Details
#display_list(list_nodes) ⇒ Object (private)
Displays the elements of the list return [String] The output standard
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/exec/node_ls.rb', line 118 def display_list(list_nodes) @logger.info("Exec::NodeLs display_list(list_nodes)") output = "" begin if !list_nodes.nil? && list_nodes.length > 0 list_nodes_to_diplay = Array.new list_nodes.each { |node| list_nodes_to_diplay.<< " - #{node}" } if !list_nodes_to_diplay.nil? && list_nodes_to_diplay.length > 0 output += "\n" list_nodes_to_diplay.sort.each { |node| output += "#{node}\n" } end end rescue => e raise NodeListError.new("Displays the elements of the list.") end return output end |
#exec ⇒ Object (private)
The execution of the command.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/exec/node_ls.rb', line 33 def exec @logger.info("Exec::NodeLs Executing NodeLs") output = "" ### Normal displays ### if !@values['follow'] && @values['status'].nil? @logger.info("Exec::NodeLs Executing of a normal displays") @logger.info("Exec::NodeLs Display nodes into the bash screen...") Color::print_log("NONE", "Display nodes into the bash screen...", @stdout) # Retrieves the list of nodes. begin @logger.info("Exec::NodeLs Getting the nodes list.") cmd = Command::.new(@logger) list_nodes = cmd.exec rescue => e raise NodeListError.new("Retrieves the list of nodes.") end # Displays the list of all nodes. begin output += "#{display_list(list_nodes)}\n" rescue => e raise NodeListError.new("Displays the list of all nodes.") end Color::echo_ok(@stdout) @logger.info(output) if !output.empty? && output.length > 1 @stdout.print output else @logger.info("Exec::NodeLs No machines available!") @stdout.printf_red "No machines available!\n" end end ### Status displays ### if !@values['follow'] && !@values['status'].nil? @logger.info("Exec::NodeLs Executing of a status displays") Color::print_log("NONE", "Display nodes into the bash screen with status '#{@values['status']}'...", @stdout) # Retrieves the list of nodes. begin @logger.info("Exec::NodeLs Getting the nodes list.") cmd = Command::.new(@logger, @values['status']) list_nodes = cmd.exec rescue => e raise NodeListError.new("Retrieves the list of nodes with the status '#{@values['status']}'..") end # Displays the list of all nodes. if is_correct_status(@values['status']) list_nodes = cmd.exec output += "#{display_list(list_nodes)}\n" else raise NodeListError.new("The status '#{@values['status']}' is not correct.") end Color::echo_ok(@stdout) @logger.info(output) if !output.empty? && output.length > 1 @stdout.print output else @logger.info("Exec::NodeLs No machines available!") @stdout.print "No machines '#{@values['status']}' available!\n" end @logger.end_execution() end ### Waiting displays ### if @values['follow'] && @values['status'].nil? #`watch -d -n 4 bin/cb-node-ls` @stdout.puts "TODO" @logger.info("Exec::NodeLs Follow display nodes to do!") # @todo The waiting displays for cb-node-ls end end |
#is_correct_status(status_node) ⇒ Boolean (private)
TODO:
refactor in a library
Returns true if the status is correct, false else.
147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/exec/node_ls.rb', line 147 def is_correct_status(status_node) list_status = ["Applying", "Delete", "Delete Final", "Deleting Final", "Discovered", "Discovering", "Hardware Installed", "Hardware Installing", "Hardware Updated", "Hardware Updating", "Installed", "Installing", "Pending", "Ready", "Readying", "Reinstall", "Reset", "Update", "Updated"] list_status.each { |status| if status_node == status return true end } return false end |
#set_options ⇒ Object (private)
Parse and check the parameters of the function.
25 26 27 28 29 |
# File 'lib/exec/node_ls.rb', line 25 def @logger.info("Exec::NodeLs Setting options") .add_option("s", "status", "Filter by status : \n\t\t\t\t\t Delete, Installed, Delete Final, Ready, Discovered, Readying, Hardware Installed,\n\t\t\t\t\t Reinstall, Hardware Installing, Reset, Hardware Updated, Update or Hardware Updating.", false, true) .add_option("f", "follow", "Display informations until interruption of the user (Ctrl+C).", false) end |