Class: Exec::NodeInstall

Inherits:
ExecutableCommand show all
Defined in:
lib/exec/node_install.rb

Overview

Allows the user to deploy nodes on a cluster with Crowbar.

Defined Under Namespace

Classes: CustomCommandOption

Instance Attribute Summary

Attributes inherited from ExecutableCommand

#argv, #command_name, #logger, #options, #stderr, #stdin, #stdout, #values

Instance Method Summary collapse

Methods inherited from ExecutableCommand

#check_parameters, #create_logger, #run

Constructor Details

#initialize(argv, stdin, stdout, stderr, command_name) ⇒ NodeInstall

Note:

Overrides default constructor by passing CustomCommandOption to super().

Default constructor of the class.



22
23
24
# File 'lib/exec/node_install.rb', line 22

def initialize(argv, stdin, stdout, stderr, command_name)
  super(argv, stdin, stdout, stderr, command_name, CustomCommandOption)
end

Instance Method Details

#execObject (private)

The execution of the command.



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
112
113
114
115
116
117
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_install.rb', line 40

def exec()
  @logger.info("Exec::NodeInstall   Executing NodeInstall")

  output = ""

  ### All installations ###
  if @values['all'] && !@values['force'] && @values['node'].nil?
    @logger.info("Exec::NodeInstall   All installations")
    Color::print_log("NONE", "Installation of all node 'Discovered'...", @stdout)

    # Retrieves the list of nodes.
    begin
      @logger.info("Exec::NodeInstall   Getting the nodes list.")
      cmd = Command::CrowbarNodeList.new(@logger, "Discovered")
      list_nodes = cmd.exec
    rescue => e
      raise NodeListError.new("Retrieves the list of nodes with the status 'Discovered'.")
    end

    bios_name = @values['bios']
    raid_name = @values['raid']

    if !list_nodes.nil? && list_nodes.length > 0
      list_nodes.each { |node_name|
        begin
          output += install_node(node_name, bios_name, raid_name) + "\n"
        rescue => e
          raise NodeInstallError.new("Installation of the node '#{node_name}'.")
        end
      }
    else
      raise NodeInstallError.new("No machines are Discovered.")
    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

  ### Installation on one node ###
  if !@values['all'] && !@values['force'] && !@values['node'].nil?
    @logger.info("Exec::NodeInstall   Installation on the node '#{@values['node']}'")
    Color::print_log("NONE", "Installation of the node '#{@values['node']}'...", @stdout)

    node_name = @values['node']
    bios_name = @values['bios']
    raid_name = @values['raid']

    if !if_node_exist(node_name, "Discovered")
      raise NodeInfoError.new("The node '#{node_name}' doesn't exists or is not 'Discovered'.")
    end

    begin
      output += install_node(node_name, bios_name, raid_name) + "\n"
    rescue => e
      raise NodeInstallError.new("Installation of the node '#{node_name}'.")
    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

  ### Reinstallation on one node Ready ###
  if !@values['all'] && @values['force'] && !@values['node'].nil?
    @logger.info("Exec::NodeInstall   Reinstallation on the node '#{@values['node']}'")
    Color::print_log("NONE", "Reinstallation of the node '#{@values['node']}'...", @stdout)

    node_name = @values['node']
    bios_name = @values['bios']
    raid_name = @values['raid']

    if !if_node_exist(node_name, "Ready")
      raise NodeInfoError.new("The node '#{node_name}' doesn't exists or is not 'Ready.")
    end

    begin
      output += reinstall_node(node_name, bios_name, raid_name) + "\n"
    rescue => e
      raise NodeReinstallError.new("Reinstallation of the node '#{node_name}'.")
    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
end

#if_node_exist(node_name, status) ⇒ Boolean (private)

TODO:

refactor in a library

Check if the node exists or not



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/exec/node_install.rb', line 191

def if_node_exist(node_name, status)
  @logger.info("Exec::NodeInstall   Check if the node '#{node_name}' exists or not.")

  # Retrieves the list of nodes.
  begin
    @logger.info("Exec::NodeInstall   Getting the nodes list.")
    cmd = Command::CrowbarNodeList.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.split(" ").at(0).strip.to_s() == node.split(" ").at(0).strip.to_s()
        return true
      end
    }
  end

  return false
end

#install_node(node_name, bios_name = nil, raid_name = nil) ⇒ Object

Install a node

Raises:

  • NodeError If the node don’t exists or is not Discovered



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/exec/node_install.rb', line 148

def install_node(node_name, bios_name = nil, raid_name = nil)
  @logger.info("Exec::NodeInstall   install_node(#{node_name}, #{bios_name}, #{raid_name})")

  output = ""
  unless node_name.nil?
    if if_node_exist(node_name, "Discovered")
      cmd = Command::NodeInstall.new(node_name, bios_name, raid_name)
      cmd.exec
      output += "Installation of the node '#{node_name}'.\n"
    else
      raise NodeInstallError.new("The node '#{node_name}' doesn't exists or is not 'Discovered.")
    end
  end
  return output
end

#reinstall_node(node_name, bios_name = nil, raid_name = nil) ⇒ Object

Reinstall a node

Raises:

  • NodeError If the node don’t exists or is not Discovered



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/exec/node_install.rb', line 169

def reinstall_node(node_name, bios_name = nil, raid_name = nil)
  @logger.info("Exec::NodeInstall   reinstall_node(#{node_name}, #{bios_name}, #{raid_name})")

  output = ""
  unless node_name.nil?
    if if_node_exist(node_name, "Ready")
      cmd = Command::NodeReinstall.new(node_name, bios_name, raid_name)
      cmd.exec
      output += "Reinstallation of the node '#{node_name}'.\n"
    else
      raise NodeReinstallError.new("The node '#{node_name}' doesn't exists or is not 'Ready.")
    end
  end
  return output
end

#set_optionsObject (private)

Parse and check the parameters of the function.



29
30
31
32
33
34
35
36
# File 'lib/exec/node_install.rb', line 29

def set_options()
  @logger.info("Exec::NodeInstall   Setting options")
  @options.add_option("n", "node", "The Node name that will be installed.", true, true, method(:check_crowbar_node_name))
  @options.add_option("a", "all", "install OS on all nodes.", true, false)
  @options.add_option("b", "bios", "Set the bios name (Hadoop, HadoopInfra, Storage or Virtualization)", false, true)
  @options.add_option("r", "raid", "Set the raid name (Raid10 or JBODOnly).", false, true, method(:check_param_for_raid))
  @options.add_option("f", "force", "force the reinstallation of an already installed node.", false)
end