rubyipmi 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/rubyipmi/commands/basecommand.rb +15 -0
- data/lib/rubyipmi/freeipmi/commands/basecommand.rb +13 -0
- data/lib/rubyipmi/freeipmi/commands/fru.rb +59 -0
- data/lib/rubyipmi/freeipmi/connection.rb +4 -0
- data/lib/rubyipmi/ipmitool/commands/basecommand.rb +12 -0
- data/lib/rubyipmi/ipmitool/commands/fru.rb +63 -0
- data/lib/rubyipmi/ipmitool/connection.rb +4 -0
- data/lib/rubyipmi.rb +12 -1
- data/rubyipmi.gemspec +5 -2
- data/spec/fru_spec.rb +38 -0
- data/spec/rubyipmi_spec.rb +4 -0
- metadata +7 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
@@ -1,10 +1,12 @@
|
|
1
1
|
require "observer"
|
2
|
+
require 'tempfile'
|
2
3
|
|
3
4
|
module Rubyipmi
|
4
5
|
|
5
6
|
class BaseCommand
|
6
7
|
include Observable
|
7
8
|
|
9
|
+
|
8
10
|
attr_reader :cmd
|
9
11
|
attr_accessor :options
|
10
12
|
attr_reader :lastcall
|
@@ -13,6 +15,15 @@ module Rubyipmi
|
|
13
15
|
# override in subclass
|
14
16
|
end
|
15
17
|
|
18
|
+
def setpass
|
19
|
+
@passfile = Tempfile.new('')
|
20
|
+
@passfile.open
|
21
|
+
end
|
22
|
+
|
23
|
+
def removepass
|
24
|
+
@passfile.close!
|
25
|
+
end
|
26
|
+
|
16
27
|
def to_s
|
17
28
|
makecommand
|
18
29
|
end
|
@@ -86,6 +97,7 @@ module Rubyipmi
|
|
86
97
|
|
87
98
|
|
88
99
|
def run(debug=false)
|
100
|
+
setpass
|
89
101
|
@result = nil
|
90
102
|
command = makecommand
|
91
103
|
if debug
|
@@ -94,6 +106,7 @@ module Rubyipmi
|
|
94
106
|
|
95
107
|
@lastcall = "#{command}"
|
96
108
|
@result = `#{command} 2>&1`
|
109
|
+
removepass
|
97
110
|
#puts "Last Call: #{@lastcall}"
|
98
111
|
|
99
112
|
# sometimes the command tool doesnt return the correct result
|
@@ -108,12 +121,14 @@ module Rubyipmi
|
|
108
121
|
|
109
122
|
|
110
123
|
def run_without_opts(args=[], debug=false)
|
124
|
+
setpass
|
111
125
|
@result = ""
|
112
126
|
if debug
|
113
127
|
return "#{cmd} #{args.join(" ")}"
|
114
128
|
else
|
115
129
|
@lastcall = "#{cmd} #{args.join(" ")}"
|
116
130
|
@result = `#{cmd} #{args.join(" ")} 2>&1`
|
131
|
+
removepass
|
117
132
|
end
|
118
133
|
|
119
134
|
process_status = validate_status($?)
|
@@ -2,6 +2,15 @@ module Rubyipmi::Freeipmi
|
|
2
2
|
|
3
3
|
class BaseCommand < Rubyipmi::BaseCommand
|
4
4
|
|
5
|
+
def setpass
|
6
|
+
super
|
7
|
+
@options["config-file"] = @passfile.path
|
8
|
+
@passfile.puts "password #{@options["password"]}\n"
|
9
|
+
@passfile.puts "username #{@options["username"]}"
|
10
|
+
|
11
|
+
@passfile.close
|
12
|
+
end
|
13
|
+
|
5
14
|
def makecommand
|
6
15
|
# need to format the options to freeipmi format
|
7
16
|
args = @options.collect { |k, v|
|
@@ -11,6 +20,10 @@ module Rubyipmi::Freeipmi
|
|
11
20
|
"--#{k}=#{v}"
|
12
21
|
end
|
13
22
|
}.join(" ")
|
23
|
+
# must remove from command line as its handled via conf file
|
24
|
+
args.delete("--password")
|
25
|
+
args.delete("--username")
|
26
|
+
|
14
27
|
|
15
28
|
return "#{cmd} #{args}"
|
16
29
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Rubyipmi::Freeipmi
|
2
|
+
|
3
|
+
class Fru < Rubyipmi::Freeipmi::BaseCommand
|
4
|
+
|
5
|
+
def initialize(opts = ObservableHash.new)
|
6
|
+
super("ipmi-fru", opts)
|
7
|
+
end
|
8
|
+
|
9
|
+
# return the list of fru information in a hash
|
10
|
+
def list
|
11
|
+
@list ||= parse(command)
|
12
|
+
end
|
13
|
+
|
14
|
+
def serial
|
15
|
+
list["chassis_serial_number"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def manufacturer
|
19
|
+
list["board_manufacturer"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def product
|
23
|
+
list["board_product_name"]
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def method_missing(method, *args, &block)
|
29
|
+
if not list.has_key?(method.to_s)
|
30
|
+
raise NoMethodError
|
31
|
+
else
|
32
|
+
list[method.to_s]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# parse the fru information
|
37
|
+
def parse(data)
|
38
|
+
datalist = {}
|
39
|
+
data.lines.each do |line|
|
40
|
+
key, value = line.split(':')
|
41
|
+
next if key =~ /\n/
|
42
|
+
value = value.strip
|
43
|
+
key = key.gsub(/FRU/, '').strip.gsub(/\ /, '_').downcase
|
44
|
+
datalist[key] = value.strip
|
45
|
+
end
|
46
|
+
return datalist
|
47
|
+
end
|
48
|
+
|
49
|
+
# run the command and return result
|
50
|
+
def command
|
51
|
+
value = runcmd
|
52
|
+
if value
|
53
|
+
return @result
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -2,6 +2,15 @@ module Rubyipmi::Ipmitool
|
|
2
2
|
|
3
3
|
class BaseCommand < Rubyipmi::BaseCommand
|
4
4
|
|
5
|
+
def setpass
|
6
|
+
super
|
7
|
+
@options["f"] = @passfile.path
|
8
|
+
@passfile.puts "#{@options["P"]}"
|
9
|
+
@passfile.close
|
10
|
+
|
11
|
+
|
12
|
+
end
|
13
|
+
|
5
14
|
def makecommand
|
6
15
|
args = ""
|
7
16
|
# need to format the options to ipmitool format
|
@@ -9,6 +18,9 @@ module Rubyipmi::Ipmitool
|
|
9
18
|
next if k == "cmdargs"
|
10
19
|
args << "-#{k} #{v} "
|
11
20
|
end
|
21
|
+
# must remove from command line as its handled via conf file
|
22
|
+
args.delete("-P")
|
23
|
+
|
12
24
|
# since ipmitool requires commands to be in specific order
|
13
25
|
args << " " + options["cmdargs"]
|
14
26
|
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Rubyipmi::Ipmitool
|
2
|
+
|
3
|
+
class Fru < Rubyipmi::Ipmitool::BaseCommand
|
4
|
+
|
5
|
+
def initialize(opts = ObservableHash.new)
|
6
|
+
super("ipmitool", opts)
|
7
|
+
end
|
8
|
+
|
9
|
+
# return the list of fru information in a hash
|
10
|
+
def list
|
11
|
+
@list ||= parse(command)
|
12
|
+
end
|
13
|
+
|
14
|
+
# returns the serial of the board
|
15
|
+
def serial
|
16
|
+
list["board_serial"]
|
17
|
+
end
|
18
|
+
|
19
|
+
# returns the manufacturer of the server
|
20
|
+
def manufacturer
|
21
|
+
list["product_manufacturer"]
|
22
|
+
end
|
23
|
+
|
24
|
+
# returns the product name of the server
|
25
|
+
def product
|
26
|
+
list["product_name"]
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def method_missing(method, *args, &block)
|
32
|
+
if not list.has_key?(method.to_s)
|
33
|
+
raise NoMethodError
|
34
|
+
else
|
35
|
+
list[method.to_s]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# parse the fru information
|
40
|
+
def parse(data)
|
41
|
+
datalist = {}
|
42
|
+
data.lines.each do |line|
|
43
|
+
key, value = line.split(':')
|
44
|
+
next if key =~ /\n/
|
45
|
+
key = key.strip.gsub(/\ /, '_').downcase
|
46
|
+
datalist[key] = value.strip
|
47
|
+
end
|
48
|
+
return datalist
|
49
|
+
end
|
50
|
+
|
51
|
+
# run the command and return result
|
52
|
+
def command
|
53
|
+
@options["cmdargs"] = "fru"
|
54
|
+
value = runcmd
|
55
|
+
@options.delete_notify("cmdargs")
|
56
|
+
if value
|
57
|
+
return @result
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/lib/rubyipmi.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'rubyipmi/ipmitool/connection'
|
2
2
|
require 'rubyipmi/freeipmi/connection'
|
3
|
+
require 'net/smtp'
|
4
|
+
|
3
5
|
|
4
6
|
module Rubyipmi
|
5
7
|
|
@@ -77,4 +79,13 @@ module Rubyipmi
|
|
77
79
|
end
|
78
80
|
return available
|
79
81
|
end
|
80
|
-
|
82
|
+
|
83
|
+
def self.printdiag(user, pass, host)
|
84
|
+
@conn = Rubyipmi::connect(user, pass, host)
|
85
|
+
puts "Product: #{@conn.fru.product}"
|
86
|
+
puts "Manufacturer: #{@conn.fru.manufacturer}"
|
87
|
+
puts "BMC Info #{@conn.bmc.info.inspect}\n"
|
88
|
+
puts "Please email to corey@logicminds.biz when troubleshooting"
|
89
|
+
return true
|
90
|
+
end
|
91
|
+
end
|
data/rubyipmi.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "rubyipmi"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Corey Osman"]
|
12
|
-
s.date = "2012-08-
|
12
|
+
s.date = "2012-08-28"
|
13
13
|
s.description = "A ruby wrapper for ipmi command line tools that supports ipmitool and freeipmi"
|
14
14
|
s.email = "corey@logicminds.biz"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
|
|
35
35
|
"lib/rubyipmi/freeipmi/commands/bmcinfo.rb",
|
36
36
|
"lib/rubyipmi/freeipmi/commands/chassis.rb",
|
37
37
|
"lib/rubyipmi/freeipmi/commands/chassisconfig.rb",
|
38
|
+
"lib/rubyipmi/freeipmi/commands/fru.rb",
|
38
39
|
"lib/rubyipmi/freeipmi/commands/lan.rb",
|
39
40
|
"lib/rubyipmi/freeipmi/commands/power.rb",
|
40
41
|
"lib/rubyipmi/freeipmi/commands/sensors.rb",
|
@@ -44,6 +45,7 @@ Gem::Specification.new do |s|
|
|
44
45
|
"lib/rubyipmi/ipmitool/commands/bmc.rb",
|
45
46
|
"lib/rubyipmi/ipmitool/commands/chassis.rb",
|
46
47
|
"lib/rubyipmi/ipmitool/commands/chassisconfig.rb",
|
48
|
+
"lib/rubyipmi/ipmitool/commands/fru.rb",
|
47
49
|
"lib/rubyipmi/ipmitool/commands/lan.rb",
|
48
50
|
"lib/rubyipmi/ipmitool/commands/power.rb",
|
49
51
|
"lib/rubyipmi/ipmitool/commands/sensors.rb",
|
@@ -55,6 +57,7 @@ Gem::Specification.new do |s|
|
|
55
57
|
"spec/chassis_config_spec.rb",
|
56
58
|
"spec/chassis_spec.rb",
|
57
59
|
"spec/connection_spec.rb",
|
60
|
+
"spec/fru_spec.rb",
|
58
61
|
"spec/lan_spec.rb",
|
59
62
|
"spec/power_spec.rb",
|
60
63
|
"spec/rubyipmi_spec.rb",
|
data/spec/fru_spec.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Fru" do
|
4
|
+
|
5
|
+
attr_accessor :provider
|
6
|
+
before :each do
|
7
|
+
user = ENV["ipmiuser"]
|
8
|
+
pass = ENV["ipmipass"]
|
9
|
+
host = ENV["ipmihost"]
|
10
|
+
provider = ENV["ipmiprovider"]
|
11
|
+
@conn = Rubyipmi.connect(user, pass, host, provider)
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
it "test should return manufacturer" do
|
16
|
+
@conn.fru.manufacturer.should_not be nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "test should return serial" do
|
20
|
+
@conn.fru.serial.should_not be nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "test should return product name" do
|
24
|
+
@conn.fru.product.should_not be nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "test should return fru list" do
|
28
|
+
@conn.fru.list.length.should be > 1
|
29
|
+
end
|
30
|
+
|
31
|
+
it "test missing method with known good method" do
|
32
|
+
@conn.fru.chassis_type.should_not be nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it "test missing method with known bad method" do
|
36
|
+
expect {@conn.fru.blah}.to raise_exception
|
37
|
+
end
|
38
|
+
end
|
data/spec/rubyipmi_spec.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyipmi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Corey Osman
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-08-
|
18
|
+
date: 2012-08-28 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
requirement: &id001 !ruby/object:Gem::Requirement
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/rubyipmi/freeipmi/commands/bmcinfo.rb
|
123
123
|
- lib/rubyipmi/freeipmi/commands/chassis.rb
|
124
124
|
- lib/rubyipmi/freeipmi/commands/chassisconfig.rb
|
125
|
+
- lib/rubyipmi/freeipmi/commands/fru.rb
|
125
126
|
- lib/rubyipmi/freeipmi/commands/lan.rb
|
126
127
|
- lib/rubyipmi/freeipmi/commands/power.rb
|
127
128
|
- lib/rubyipmi/freeipmi/commands/sensors.rb
|
@@ -131,6 +132,7 @@ files:
|
|
131
132
|
- lib/rubyipmi/ipmitool/commands/bmc.rb
|
132
133
|
- lib/rubyipmi/ipmitool/commands/chassis.rb
|
133
134
|
- lib/rubyipmi/ipmitool/commands/chassisconfig.rb
|
135
|
+
- lib/rubyipmi/ipmitool/commands/fru.rb
|
134
136
|
- lib/rubyipmi/ipmitool/commands/lan.rb
|
135
137
|
- lib/rubyipmi/ipmitool/commands/power.rb
|
136
138
|
- lib/rubyipmi/ipmitool/commands/sensors.rb
|
@@ -142,6 +144,7 @@ files:
|
|
142
144
|
- spec/chassis_config_spec.rb
|
143
145
|
- spec/chassis_spec.rb
|
144
146
|
- spec/connection_spec.rb
|
147
|
+
- spec/fru_spec.rb
|
145
148
|
- spec/lan_spec.rb
|
146
149
|
- spec/power_spec.rb
|
147
150
|
- spec/rubyipmi_spec.rb
|