Class: Exec::NodeDestroy
- Inherits:
-
ExecutableCommand
- Object
- ExecutableCommand
- Exec::NodeDestroy
- Defined in:
- lib/exec/node_destroy.rb
Overview
Allows the user to destroy node’s of crowbar server
Instance Attribute Summary
Attributes inherited from ExecutableCommand
#argv, #command_name, #logger, #options, #stderr, #stdin, #stdout, #values
Instance Method Summary collapse
-
#destroy_node(node_name) ⇒ Object
Destroy a node from the server Crowbar.
-
#exec ⇒ Object
private
The execution of the command.
-
#if_node_exist(node_name, status) ⇒ Boolean
private
Check if the node exists or not.
-
#initialize(argv, stdin, stdout, stderr, command_name) ⇒ NodeDestroy
constructor
Default constructor of the class.
- #set_options ⇒ Object private
Methods inherited from ExecutableCommand
#check_parameters, #create_logger, #run
Constructor Details
#initialize(argv, stdin, stdout, stderr, command_name) ⇒ NodeDestroy
Note:
Overrides default constructor by passing CustomCommandOption to super().
Default constructor of the class.
22 23 24 |
# File 'lib/exec/node_destroy.rb', line 22 def initialize(argv, stdin, stdout, stderr, command_name) super(argv, stdin, stdout, stderr, command_name) end |
Instance Method Details
#destroy_node(node_name) ⇒ Object
Destroy a node from the server Crowbar
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 |
# File 'lib/exec/node_destroy.rb', line 45 def destroy_node(node_name) @logger.info("Exec::NodeDestroy destroy_node(#{node_name})") Color::print_log("NONE", "Destroy the node '#{node_name}'...", @stdout) output = "" unless node_name.nil? if if_node_exist(node_name, "Ready") cmd = Command::NodeDestroy.new(node_name) cmd.exec #output += "Destroy the node '#{node_name}'.\n" else raise NodeDestroyError.new("The node '#{node_name}' doesn't exists or is not 'Ready'.") end else raise NodeDestroyError.new("The node name is nil.") 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 |
#exec ⇒ Object (private)
The execution of the command.
35 36 37 38 |
# File 'lib/exec/node_destroy.rb', line 35 def exec @logger.info("Exec::NodeDestroy Executing NodeDestroy") destroy_node(@values['node']) end |
#if_node_exist(node_name, status) ⇒ Boolean (private)
TODO:
refactor in a library
Check if the node exists or not
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/exec/node_destroy.rb', line 78 def if_node_exist(node_name, status) @logger.info("Exec::NodeDestroy Check if the node '#{node_name}' exists or not.") # Retrieves the list of nodes. begin @logger.info("Exec::NodeDestroy Getting the nodes list.") cmd = Command::.new(@logger, status) list_nodes = cmd.exec rescue => e raise NodeListError.new("Retrieves the list of nodes with the status '#{status}'.") end if !list_nodes.nil? && list_nodes.length > 0 list_nodes.each { |node| if node_name == node.split(" ").at(0).strip.to_s() return true end } end return false end |
#set_options ⇒ Object (private)
28 29 30 31 |
# File 'lib/exec/node_destroy.rb', line 28 def () @logger.info("Exec::NodeDestroy Setting options") .add_option("n", "node", "The Node name that will be Destroy.", true, true, method(:check_crowbar_node_name)) end |