Class: Exec::NodeInfo
- Inherits:
-
ExecutableCommand
- Object
- ExecutableCommand
- Exec::NodeInfo
- Defined in:
- lib/exec/node_info.rb
Overview
Allows the user to display node’s information.
Instance Attribute Summary
Attributes inherited from ExecutableCommand
#argv, #command_name, #logger, #options, #stderr, #stdin, #stdout, #values
Instance Method Summary collapse
-
#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) ⇒ NodeInfo
constructor
Default constructor of the class.
-
#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) ⇒ NodeInfo
Note:
Overrides default constructor by passing CustomCommandOption to super().
Default constructor of the class.
20 21 22 |
# File 'lib/exec/node_info.rb', line 20 def initialize(argv, stdin, stdout, stderr, command_name) super(argv, stdin, stdout, stderr, command_name) end |
Instance Method Details
#exec ⇒ Object (private)
The execution of the command.
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 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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/exec/node_info.rb', line 34 def exec() @logger.info("Exec::NodeInfo Executing NodeInfo") @logger.info("Exec::NodeDestroy Getting informations about the node '#{@values['node']}'") Color::print_log("NONE", "Displays informations for the node '#{@values['node']}'...", @stdout) node_name = @values['node'] if !if_node_exist(node_name, "Ready") raise NodeInfoError.new("The node '#{node_name}' doesn't exists or is not 'Ready.") end cmd = Command::NodeInfo.new(node_name) p = cmd.exec() output = "" unless p.nil? output += "Node '#{node_name}' informations:\n" output += " Machine:\n" if p['name'] != nil output += " -Name: " + p['name'] + "\n" end if p['os'] != nil output += " -OS: " + p['os'] + "\n" end if p['os_version'] output += " -OS version: " + p['os_version'] + "\n" end if p['dmi'] != nil if p['dmi']['system'] != nil if p['dmi']['system']['product_name'] != nil output += " -Product Name : " + p['dmi']['system']['product_name'] + "\n" end if p['dmi']['system']['version'] != nil output += " -Version : " + p['dmi']['system']['version'] + "\n" end end end if p['memory'] != nil if p['memory']['total'] != nil memory = (p['memory']['total'].to_f) / 1048576 output += " -Memory: " + "%5.2f" % memory.to_s + " GB\n" end end if p['platform'] output += " -Platform: " + p['platform'] + "\n" end if p['platform_version'] output += " -Platform version: " + p['platform_version'] + "\n" end if p['cpu'] != nil if p['cpu']['total'] != nil if p['cpu']['0'] != nil if p['cpu']['0']['model_name'] != nil output += " -CPU: " + p['cpu']['total'].to_s + " * " + p['cpu']['0']['model_name'] + "\n" end end end end output += "\n" output += " System:\n" if p['uptime'] != nil output += " -Uptime: " + p['uptime'] + "\n" end if p['idletime'] output += " -Idletime: " + p['idletime'] + "\n" end if p['raid'] != nil output += " -Raid: " + p['raid']['enable'].to_s + "\n" end output += "\n" output += " Network:\n" if p['hostname'] != nil output += " -Hostname: " + p['hostname'] + "\n" end if p['domain'] != nil output += " -Domain: " + p['domain'] + "\n" end if p['ipaddress'] != nil output += " -IP address: " + p['ipaddress'] + "\n" end if p['macaddress'] != nil output += " -MAC address: " + p['macaddress'] + "\n" end if p['fqdn'] != nil output += " -FQDN: " + p['fqdn'] + "\n" end output += "\n" output += " Crowbar/Chef:\n" if p['state'] != nil output += " -State: " + p['state'] + "\n" end if p['filesystem'] != nil output += " -Filesystem:\n" get_keys = p['filesystem'].keys get_keys.each { |x| if x.start_with?('/dev/') output += " -#{x}:\n" if p['filesystem'][x]['mount'] != nil output += " -Mount: " + p['filesystem'][x]['mount'] + "\n" end if p['filesystem'][x]['percent_used'] != nil output += " -Percent used: " + p['filesystem'][x]['percent_used'].gsub("%", "") + "\n" end if p['filesystem'][x]['fs_type'] != nil output += " -FS type: " + p['filesystem'][x]['fs_type'] + "\n" end end } end if p['crowbar'] != nil if p['crowbar']['disks'] != nil output += " -Disks:\n" get_keys = p['crowbar']['disks'].keys get_keys.each { |x| output += " -#{x}:\n" if p['crowbar']['disks'][x]['model'] != nil output += " -Model: " + p['crowbar']['disks'][x]['model'] + "\n" end if p['crowbar']['disks'][x]['vendor'] != nil output += " -Vendor: " + p['crowbar']['disks'][x]['vendor'] + "\n" end if p['crowbar']['disks'][x]['state'] != nil output += " -State: " + p['crowbar']['disks'][x]['state'] + "\n" end } end if p['crowbar']['hardware'] != nil output += " -Hardware:\n" if p['crowbar']['hardware']['bios_set'] != nil output += " -Bios set: " + p['crowbar']['hardware']['bios_set'] + "\n" end if p['crowbar']['hardware']['raid_set'] != nil output += " -Raid set: " + p['crowbar']['hardware']['raid_set'] + "\n" end end if p['crowbar']['network'] != nil && (p['crowbar']['network']['bmc'] != nil || p['crowbar']['network']['admin'] != nil) output += " -Network:\n" get_keys = p['crowbar']['network'].keys get_keys.each { |x| output += " -#{x}:\n" if p['crowbar']['network'][x]['address'] != nil output += " -Address: " + p['crowbar']['network'][x]['address'] + "\n" end if p['crowbar']['network'][x]['subnet'] != nil output += " -Subnet: " + p['crowbar']['network'][x]['subnet'] + "\n" end if p['crowbar']['network'][x]['netmask'] != nil output += " -Netmask: " + p['crowbar']['network'][x]['netmask'] + "\n" end if p['crowbar']['network'][x]['broadcast'] != nil output += " -Broadcast: " + p['crowbar']['network'][x]['broadcast'] + "\n" end } end end if p['roles'] != nil output += " -Roles:\n" p['roles'].each { |x| output += " -#{x}\n" } end if p['chef_packages'] != nil if p['chef_packages']['chef'] != nil output += " -Chef:\n" if p['chef_packages']['chef']['version'] output += " -Version: " + p['chef_packages']['chef']['version'] + "\n" end end end output += "\n" if p['kernel'] != nil output += " Kernel:\n" if p['kernel']['name'] != nil output += " -Name: " + p['kernel']['name'] + "\n" end if p['kernel']['version'] != nil output += " -Version: " + p['kernel']['version'] + "\n" end if p['kernel']['os'] != nil output += " -OS: " + p['kernel']['os'] + "\n" end if p['kernel']['release'] output += " -Release: " + p['kernel']['release'] + "\n" end if p['kernel']['machine'] output += " -Machine: " + p['kernel']['machine'] + "\n" end end output += "\n" if p['languages'] != nil output += " Languages versions:\n" get_keys = p['languages'].keys get_keys.each { |x| if p['languages'][x]['version'] != nil output += " -#{x}: " + p['languages'][x]['version'] + "\n" end } end end Color::echo_ok(@stdout) @logger.info(output) if !output.empty? && output.length > 1 @stdout.print output else @logger.info("Exec::NodeInfo No informations about the node '#{node_name}'.") @stdout.printf_red "No informations about the node '#{node_name}'.\n" end end |
#if_node_exist(node_name, status) ⇒ Boolean (private)
TODO:
refactor in a library
Check if the node exists or not
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/exec/node_info.rb', line 257 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 |
#set_options ⇒ Object (private)
Parse and check the parameters of the function.
27 28 29 30 |
# File 'lib/exec/node_info.rb', line 27 def @logger.info("Exec::NodeInfo Setting options") @options.add_option("n", "node", "Displays informations about a node.", true, true, method(:check_crowbar_node_name)) end |