rubyipmi 0.10.0 → 0.11.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.
- checksums.yaml +5 -5
- data/.document +5 -0
- data/.gitignore +50 -0
- data/.rspec +1 -0
- data/.rubocop.yml +66 -0
- data/.travis.yml +13 -0
- data/Gemfile +3 -3
- data/README.md +9 -3
- data/RELEASE_NOTES.md +33 -0
- data/Rakefile +15 -42
- data/lib/rubyipmi/commands/basecommand.rb +17 -23
- data/lib/rubyipmi/commands/mixins/power_mixin.rb +50 -0
- data/lib/rubyipmi/commands/mixins/sensors_mixin.rb +54 -0
- data/lib/rubyipmi/freeipmi/commands/basecommand.rb +26 -35
- data/lib/rubyipmi/freeipmi/commands/bmc.rb +4 -7
- data/lib/rubyipmi/freeipmi/commands/bmcconfig.rb +7 -17
- data/lib/rubyipmi/freeipmi/commands/bmcdevice.rb +2 -9
- data/lib/rubyipmi/freeipmi/commands/bmcinfo.rb +4 -10
- data/lib/rubyipmi/freeipmi/commands/chassis.rb +27 -45
- data/lib/rubyipmi/freeipmi/commands/chassisconfig.rb +23 -38
- data/lib/rubyipmi/freeipmi/commands/fru.rb +23 -42
- data/lib/rubyipmi/freeipmi/commands/lan.rb +4 -6
- data/lib/rubyipmi/freeipmi/commands/power.rb +8 -51
- data/lib/rubyipmi/freeipmi/commands/sensors.rb +10 -67
- data/lib/rubyipmi/freeipmi/connection.rb +14 -17
- data/lib/rubyipmi/freeipmi/errorcodes.rb +11 -17
- data/lib/rubyipmi/ipmitool/commands/basecommand.rb +12 -16
- data/lib/rubyipmi/ipmitool/commands/bmc.rb +13 -22
- data/lib/rubyipmi/ipmitool/commands/chassis.rb +26 -44
- data/lib/rubyipmi/ipmitool/commands/chassisconfig.rb +11 -21
- data/lib/rubyipmi/ipmitool/commands/fru.rb +35 -48
- data/lib/rubyipmi/ipmitool/commands/lan.rb +25 -28
- data/lib/rubyipmi/ipmitool/commands/power.rb +7 -58
- data/lib/rubyipmi/ipmitool/commands/sensors.rb +10 -68
- data/lib/rubyipmi/ipmitool/connection.rb +10 -19
- data/lib/rubyipmi/ipmitool/errorcodes.rb +11 -45
- data/lib/rubyipmi/observablehash.rb +1 -2
- data/lib/rubyipmi/version.rb +5 -0
- data/lib/rubyipmi.rb +23 -28
- data/rubyipmi.gemspec +17 -128
- metadata +18 -101
- data/spec/Vagrantfile +0 -45
- data/spec/fixtures/freeipmi/bmc_config.txt +0 -317
- data/spec/fixtures/freeipmi/bmc_config_lan_conf.txt +0 -19
- data/spec/fixtures/freeipmi/bmc_info.txt +0 -32
- data/spec/fixtures/freeipmi/errors.txt +0 -3
- data/spec/fixtures/freeipmi/fru.txt +0 -13
- data/spec/fixtures/freeipmi/sensors.txt +0 -29
- data/spec/fixtures/ipmitool/bmc_info.txt +0 -20
- data/spec/fixtures/ipmitool/errors.txt +0 -10
- data/spec/fixtures/ipmitool/fru.txt +0 -96
- data/spec/fixtures/ipmitool/lan.txt +0 -17
- data/spec/fixtures/ipmitool/sensors.txt +0 -105
- data/spec/integration/bmc_spec.rb +0 -48
- data/spec/integration/chassis_config_spec.rb +0 -38
- data/spec/integration/chassis_spec.rb +0 -26
- data/spec/integration/connection_spec.rb +0 -45
- data/spec/integration/fru_spec.rb +0 -38
- data/spec/integration/lan_spec.rb +0 -50
- data/spec/integration/power_spec.rb +0 -40
- data/spec/integration/rubyipmi_spec.rb +0 -114
- data/spec/integration/sensor_spec.rb +0 -43
- data/spec/manifests/default.pp +0 -50
- data/spec/puppetmodules/archive/LICENSE-2.0.txt +0 -202
- data/spec/puppetmodules/archive/Modulefile +0 -8
- data/spec/puppetmodules/archive/README.md +0 -40
- data/spec/puppetmodules/archive/manifests/download.pp +0 -157
- data/spec/puppetmodules/archive/manifests/extract.pp +0 -81
- data/spec/puppetmodules/archive/manifests/init.pp +0 -70
- data/spec/puppetmodules/archive/manifests/tar-gz.pp +0 -7
- data/spec/puppetmodules/archive/manifests/zip.pp +0 -7
- data/spec/puppetmodules/archive/metadata.json +0 -26
- data/spec/spec_helper.rb +0 -47
- data/spec/unit/freeipmi/bmc-info_spec.rb +0 -38
- data/spec/unit/freeipmi/bmc_spec.rb +0 -43
- data/spec/unit/freeipmi/connection_spec.rb +0 -121
- data/spec/unit/freeipmi/errorcodes_spec.rb +0 -28
- data/spec/unit/freeipmi/fru_spec.rb +0 -76
- data/spec/unit/freeipmi/lan_spec.rb +0 -0
- data/spec/unit/freeipmi/sensors_spec.rb +0 -85
- data/spec/unit/ipmitool/bmc_spec.rb +0 -77
- data/spec/unit/ipmitool/connection_spec.rb +0 -122
- data/spec/unit/ipmitool/errorcodes_spec.rb +0 -35
- data/spec/unit/ipmitool/fru_spec.rb +0 -77
- data/spec/unit/ipmitool/lan_spec.rb +0 -94
- data/spec/unit/ipmitool/sensors_spec.rb +0 -96
- data/spec/unit/rubyipmi_spec.rb +0 -50
- data/spec/vagrant +0 -27
- data/spec/vagrant.pub +0 -1
@@ -1,7 +1,5 @@
|
|
1
1
|
module Rubyipmi::Ipmitool
|
2
|
-
|
3
2
|
class Fru < Rubyipmi::Ipmitool::BaseCommand
|
4
|
-
|
5
3
|
attr_accessor :list
|
6
4
|
|
7
5
|
DEFAULT_FRU = 'builtin_fru_device'
|
@@ -29,22 +27,20 @@ module Rubyipmi::Ipmitool
|
|
29
27
|
|
30
28
|
# return the list of fru information in a hash
|
31
29
|
def list
|
32
|
-
if @list.count < 1
|
33
|
-
parse(getfrus)
|
34
|
-
end
|
30
|
+
parse(getfrus) if @list.count < 1
|
35
31
|
@list
|
36
32
|
end
|
37
33
|
|
38
|
-
|
34
|
+
# method to retrieve the raw fru data
|
39
35
|
def getfrus
|
40
36
|
command
|
41
37
|
end
|
42
38
|
|
43
|
-
|
39
|
+
private
|
44
40
|
|
45
41
|
# I use method missing to allow the user to say Fru.<name> which returns a frudata object unless the user
|
46
42
|
# passes a keyname from the default fru device
|
47
|
-
def method_missing(method, *
|
43
|
+
def method_missing(method, *_args, &_block)
|
48
44
|
name = method.to_s
|
49
45
|
fru = list.fetch(name, nil)
|
50
46
|
# if the user wanted some data from the default fru, lets show the data for the fru. Otherwise
|
@@ -63,29 +59,27 @@ module Rubyipmi::Ipmitool
|
|
63
59
|
|
64
60
|
# parse the fru information
|
65
61
|
def parse(data)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
77
|
-
|
62
|
+
return unless data
|
63
|
+
parsed_data = []
|
64
|
+
data.lines.each do |line|
|
65
|
+
if line =~ /^FRU.*/
|
66
|
+
# this is the either the first line of of the fru or another fru
|
67
|
+
if parsed_data.count != 0
|
68
|
+
# we have reached a new fru device so lets record the previous fru
|
69
|
+
new_fru = FruData.new(parsed_data)
|
70
|
+
parsed_data = []
|
71
|
+
@list[new_fru[:name]] = new_fru
|
78
72
|
end
|
79
|
-
|
80
|
-
end
|
81
|
-
# process the last fru
|
82
|
-
if parsed_data.count != 0
|
83
|
-
# we have reached a new fru device so lets record the previous fru
|
84
|
-
new_fru = FruData.new(parsed_data)
|
85
|
-
parsed_data = []
|
86
|
-
@list[new_fru[:name]] = new_fru
|
73
|
+
|
87
74
|
end
|
75
|
+
parsed_data << line
|
88
76
|
end
|
77
|
+
# process the last fru
|
78
|
+
return if parsed_data.count == 0
|
79
|
+
# we have reached a new fru device so lets record the previous fru
|
80
|
+
new_fru = FruData.new(parsed_data)
|
81
|
+
parsed_data = []
|
82
|
+
@list[new_fru[:name]] = new_fru
|
89
83
|
end
|
90
84
|
|
91
85
|
# run the command and return result
|
@@ -93,15 +87,11 @@ module Rubyipmi::Ipmitool
|
|
93
87
|
@options["cmdargs"] = "fru"
|
94
88
|
value = runcmd
|
95
89
|
@options.delete_notify("cmdargs")
|
96
|
-
if value
|
97
|
-
return @result
|
98
|
-
end
|
90
|
+
return @result if value
|
99
91
|
end
|
100
|
-
|
101
92
|
end
|
102
93
|
|
103
94
|
class FruData < Hash
|
104
|
-
|
105
95
|
def name
|
106
96
|
self[:name]
|
107
97
|
end
|
@@ -112,27 +102,24 @@ module Rubyipmi::Ipmitool
|
|
112
102
|
|
113
103
|
# parse the fru information that should be an array of lines
|
114
104
|
def parse(data)
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
end
|
122
|
-
else
|
123
|
-
key = key.strip.gsub(/\ /, '_').downcase
|
124
|
-
if ! value.nil?
|
125
|
-
self[key] = value.strip
|
126
|
-
end
|
105
|
+
return unless data
|
106
|
+
data.each do |line|
|
107
|
+
key, value = line.split(':', 2)
|
108
|
+
if key =~ /^FRU\s+Device.*/
|
109
|
+
if value =~ /([\w\s]*)\(.*\)/
|
110
|
+
self[:name] = $~[1].strip.gsub(/\ /, '_').downcase
|
127
111
|
end
|
112
|
+
else
|
113
|
+
key = key.strip.gsub(/\ /, '_').downcase
|
114
|
+
self[key] = value.strip unless value.nil?
|
128
115
|
end
|
129
116
|
end
|
130
117
|
end
|
131
118
|
|
132
119
|
private
|
133
120
|
|
134
|
-
def method_missing(method, *
|
135
|
-
|
121
|
+
def method_missing(method, *_args, &_block)
|
122
|
+
fetch(method.to_s, nil)
|
136
123
|
end
|
137
124
|
end
|
138
|
-
end
|
125
|
+
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
module Rubyipmi::Ipmitool
|
2
|
-
|
3
2
|
class Lan < Rubyipmi::Ipmitool::BaseCommand
|
4
|
-
|
5
3
|
attr_accessor :info
|
6
4
|
attr_accessor :channel
|
7
5
|
MAX_RETRY = 1
|
@@ -10,7 +8,6 @@ module Rubyipmi::Ipmitool
|
|
10
8
|
super("ipmitool", opts)
|
11
9
|
@info = {}
|
12
10
|
@channel = 2
|
13
|
-
|
14
11
|
end
|
15
12
|
|
16
13
|
# sets the info var to be empty causing the variable to repopulate upon the next call to info
|
@@ -33,7 +30,11 @@ module Rubyipmi::Ipmitool
|
|
33
30
|
# wait for error to occur then retry using channel 1
|
34
31
|
if retrycount < MAX_RETRY
|
35
32
|
@channel = 1
|
33
|
+
retrycount = retrycount.next
|
36
34
|
retry
|
35
|
+
else
|
36
|
+
# failed to fetch info, return cached info
|
37
|
+
@info
|
37
38
|
end
|
38
39
|
end
|
39
40
|
else
|
@@ -43,81 +44,79 @@ module Rubyipmi::Ipmitool
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def snmp
|
46
|
-
info.fetch("snmp_community_string",nil)
|
47
|
+
info.fetch("snmp_community_string", nil)
|
47
48
|
end
|
48
49
|
|
49
50
|
def ip
|
50
|
-
info.fetch("ip_address",nil)
|
51
|
+
info.fetch("ip_address", nil)
|
51
52
|
end
|
52
53
|
|
53
54
|
def mac
|
54
|
-
info.fetch("mac_address",nil)
|
55
|
+
info.fetch("mac_address", nil)
|
55
56
|
end
|
56
57
|
|
57
58
|
def netmask
|
58
|
-
info.fetch("subnet_mask",nil)
|
59
|
+
info.fetch("subnet_mask", nil)
|
59
60
|
end
|
60
61
|
|
61
62
|
def gateway
|
62
|
-
info.fetch("default_gateway_ip",nil)
|
63
|
+
info.fetch("default_gateway_ip", nil)
|
63
64
|
end
|
64
65
|
|
65
66
|
def vlanid
|
66
|
-
info.fetch("802.1q_vlan_id",nil)
|
67
|
+
info.fetch("802.1q_vlan_id", nil)
|
67
68
|
end
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
70
|
+
# def snmp=(community)
|
71
|
+
# @options["cmdargs"] = "lan set #{channel} snmp #{community}"
|
72
|
+
# value = runcmd
|
73
|
+
# @options.delete_notify("cmdargs")
|
74
|
+
# return value
|
75
|
+
# end
|
75
76
|
|
76
77
|
def ip=(address)
|
77
78
|
@options["cmdargs"] = "lan set #{channel} ipaddr #{address}"
|
78
79
|
value = runcmd
|
79
80
|
@options.delete_notify("cmdargs")
|
80
|
-
|
81
|
+
value
|
81
82
|
end
|
82
83
|
|
83
84
|
def netmask=(mask)
|
84
85
|
@options["cmdargs"] = "lan set #{channel} netmask #{mask}"
|
85
86
|
value = runcmd
|
86
87
|
@options.delete_notify("cmdargs")
|
87
|
-
|
88
|
+
value
|
88
89
|
end
|
89
90
|
|
90
91
|
def gateway=(address)
|
91
92
|
@options["cmdargs"] = "lan set #{channel} defgw ipaddr #{address}"
|
92
93
|
value = runcmd
|
93
94
|
@options.delete_notify("cmdargs")
|
94
|
-
|
95
|
+
value
|
95
96
|
end
|
96
97
|
|
97
98
|
def dhcp?
|
98
|
-
info.fetch("ip_address_source",nil).match(/dhcp/i) != nil
|
99
|
+
info.fetch("ip_address_source", nil).match(/dhcp/i) != nil
|
99
100
|
end
|
100
101
|
|
101
102
|
def static?
|
102
|
-
info.fetch("ip_address_source",nil).match(/static/i) != nil
|
103
|
+
info.fetch("ip_address_source", nil).match(/static/i) != nil
|
103
104
|
end
|
104
105
|
|
105
106
|
def vlanid=(vlan)
|
106
107
|
@options["cmdargs"] = "lan set #{channel} vlan id #{vlan}"
|
107
108
|
value = runcmd
|
108
109
|
@options.delete_notify("cmdargs")
|
109
|
-
|
110
|
+
value
|
110
111
|
end
|
111
112
|
|
112
|
-
|
113
|
+
private
|
113
114
|
|
114
115
|
def print
|
115
116
|
@options["cmdargs"] = "lan print"
|
116
117
|
value = runcmd
|
117
118
|
@options.delete_notify("cmdargs")
|
118
|
-
if value
|
119
|
-
@result
|
120
|
-
end
|
119
|
+
@result if value
|
121
120
|
end
|
122
121
|
|
123
122
|
def parse(landata)
|
@@ -127,14 +126,12 @@ module Rubyipmi::Ipmitool
|
|
127
126
|
key = normalize(item.first.strip)
|
128
127
|
value = item.last.strip
|
129
128
|
@info[key] = value
|
130
|
-
|
131
129
|
end
|
132
|
-
|
130
|
+
@info
|
133
131
|
end
|
134
132
|
|
135
133
|
def normalize(text)
|
136
134
|
text.gsub(/\ /, '_').gsub(/\./, '').downcase
|
137
135
|
end
|
138
|
-
|
139
136
|
end
|
140
137
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
require 'rubyipmi/commands/mixins/power_mixin'
|
2
2
|
|
3
|
+
module Rubyipmi::Ipmitool
|
3
4
|
class Power < Rubyipmi::Ipmitool::BaseCommand
|
5
|
+
include Rubyipmi::PowerMixin
|
4
6
|
|
5
7
|
def initialize(opts = ObservableHash.new)
|
6
8
|
super("ipmitool", opts)
|
@@ -11,70 +13,17 @@ module Rubyipmi::Ipmitool
|
|
11
13
|
@options["cmdargs"] = "power #{opt}"
|
12
14
|
value = runcmd
|
13
15
|
@options.delete_notify("cmdargs")
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
# Turn on the system
|
18
|
-
def on
|
19
|
-
if on?
|
20
|
-
return true
|
21
|
-
else
|
22
|
-
command("on")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Turn off the system
|
27
|
-
def off
|
28
|
-
if off?
|
29
|
-
return true
|
30
|
-
else
|
31
|
-
command("off")
|
32
|
-
end
|
16
|
+
value
|
33
17
|
end
|
34
18
|
|
35
|
-
|
36
|
-
def cycle
|
37
|
-
# if the system is off turn it on
|
38
|
-
if off?
|
39
|
-
on
|
40
|
-
else
|
41
|
-
command("cycle")
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
# Perform a power reset on the system
|
47
|
-
def reset
|
48
|
-
command("reset")
|
49
|
-
end
|
50
|
-
|
51
|
-
# Perform a soft shutdown, like briefly pushing the power button
|
52
|
-
def softShutdown
|
53
|
-
command("soft")
|
54
|
-
end
|
55
|
-
|
56
|
-
def powerInterrupt
|
19
|
+
def power_interrupt
|
57
20
|
command("diag")
|
58
21
|
end
|
59
22
|
|
60
23
|
# Get the power status of the system, will show either on or off
|
61
24
|
def status
|
62
25
|
value = command("status")
|
63
|
-
if value
|
64
|
-
@result.match(/(off|on)/).to_s
|
65
|
-
end
|
26
|
+
@result.match(/(off|on)/).to_s if value
|
66
27
|
end
|
67
|
-
|
68
|
-
# Test to see if the power is on
|
69
|
-
def on?
|
70
|
-
status == "on"
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
# Test to see if the power is off
|
75
|
-
def off?
|
76
|
-
status == "off"
|
77
|
-
end
|
78
|
-
|
79
28
|
end
|
80
|
-
end
|
29
|
+
end
|
@@ -1,83 +1,25 @@
|
|
1
|
-
|
1
|
+
require 'rubyipmi/commands/mixins/sensors_mixin'
|
2
2
|
|
3
|
+
module Rubyipmi::Ipmitool
|
3
4
|
class Sensors < Rubyipmi::Ipmitool::BaseCommand
|
5
|
+
include Rubyipmi::SensorsMixin
|
4
6
|
|
5
7
|
def initialize(opts = ObservableHash.new)
|
6
8
|
super("ipmitool", opts)
|
7
9
|
end
|
8
10
|
|
9
|
-
def refresh
|
10
|
-
@sensors = nil
|
11
|
-
list
|
12
|
-
end
|
13
|
-
|
14
|
-
def list
|
15
|
-
@sensors ||= parse(getsensors)
|
16
|
-
end
|
17
|
-
|
18
|
-
def count
|
19
|
-
list.count
|
20
|
-
end
|
21
|
-
|
22
|
-
def names
|
23
|
-
list.keys
|
24
|
-
end
|
25
|
-
|
26
|
-
# returns a hash of fan sensors where the key is fan name and value is the sensor
|
27
|
-
def fanlist(refreshdata=false)
|
28
|
-
refresh if refreshdata
|
29
|
-
flist = {}
|
30
|
-
list.each do | name,sensor |
|
31
|
-
if name =~ /.*fan.*/
|
32
|
-
flist[name] = sensor
|
33
|
-
end
|
34
|
-
end
|
35
|
-
return flist
|
36
|
-
end
|
37
|
-
|
38
|
-
# returns a hash of sensors where each key is the name of the sensor and the value is the sensor
|
39
|
-
def templist(refreshdata=false)
|
40
|
-
refresh if refreshdata
|
41
|
-
tlist = {}
|
42
|
-
list.each do | name , sensor |
|
43
|
-
if sensor[:unit] =~ /.*degree.*/ || name =~ /.*temp.*/
|
44
|
-
tlist[name] = sensor
|
45
|
-
end
|
46
|
-
end
|
47
|
-
return tlist
|
48
|
-
end
|
49
|
-
|
50
11
|
def getsensors
|
51
12
|
options["cmdargs"] = "sensor"
|
52
|
-
|
13
|
+
runcmd
|
53
14
|
options.delete_notify("cmdargs")
|
54
15
|
@result
|
55
16
|
end
|
56
17
|
|
57
|
-
|
58
|
-
|
59
|
-
def method_missing(method, *args, &block)
|
60
|
-
if not list.has_key?(method.to_s)
|
61
|
-
raise NoMethodError
|
62
|
-
else
|
63
|
-
list[method.to_s]
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def parse(data)
|
68
|
-
sensorlist = {}
|
69
|
-
if ! data.nil?
|
70
|
-
data.lines.each do | line|
|
71
|
-
# skip the header
|
72
|
-
sensor = Sensor.new(line)
|
73
|
-
sensorlist[sensor[:name]] = sensor
|
74
|
-
end
|
75
|
-
end
|
76
|
-
return sensorlist
|
18
|
+
def sensor_class
|
19
|
+
Sensor
|
77
20
|
end
|
78
21
|
end
|
79
22
|
|
80
|
-
|
81
23
|
class Sensor < Hash
|
82
24
|
def initialize(line)
|
83
25
|
parse(line)
|
@@ -85,6 +27,7 @@ module Rubyipmi::Ipmitool
|
|
85
27
|
end
|
86
28
|
|
87
29
|
private
|
30
|
+
|
88
31
|
def normalize(text)
|
89
32
|
text.gsub(/\ /, '_').gsub(/\./, '').downcase
|
90
33
|
end
|
@@ -93,17 +36,16 @@ module Rubyipmi::Ipmitool
|
|
93
36
|
# Note: not all fields will exist on every server
|
94
37
|
def parse(line)
|
95
38
|
fields = [:name, :value, :unit, :status, :type, :state, :lower_nonrec,
|
96
|
-
:lower_crit
|
39
|
+
:lower_crit, :lower_noncrit, :upper_crit, :upper_nonrec, :asserts_enabled, :deasserts_enabled]
|
97
40
|
# skip the header
|
98
41
|
data = line.split(/\|/)
|
99
42
|
# should we ever encounter a field not in the fields list, just use a counter based fieldname
|
100
43
|
i = 0
|
101
|
-
data.each do |
|
44
|
+
data.each do |value|
|
102
45
|
field ||= fields.shift || "field#{i}"
|
103
46
|
self[field] = value.strip
|
104
47
|
i = i.next
|
105
48
|
end
|
106
49
|
end
|
107
50
|
end
|
108
|
-
|
109
|
-
end
|
51
|
+
end
|
@@ -9,11 +9,14 @@ end
|
|
9
9
|
|
10
10
|
module Rubyipmi
|
11
11
|
module Ipmitool
|
12
|
-
|
13
12
|
class Connection
|
14
|
-
|
15
13
|
attr_accessor :options
|
16
14
|
|
15
|
+
DRIVERS_MAP = {
|
16
|
+
'lan15' => 'lan',
|
17
|
+
'lan20' => 'lanplus',
|
18
|
+
'open' => 'open'
|
19
|
+
}
|
17
20
|
|
18
21
|
def initialize(user, pass, host, opts)
|
19
22
|
@options = Rubyipmi::ObservableHash.new
|
@@ -23,29 +26,17 @@ module Rubyipmi
|
|
23
26
|
# So they are not required
|
24
27
|
@options["U"] = user if user
|
25
28
|
@options["P"] = pass if pass
|
26
|
-
if opts.
|
27
|
-
@options["L"] = opts[:privilege]
|
28
|
-
end
|
29
|
+
@options["L"] = opts[:privilege] if opts.key?(:privilege)
|
29
30
|
# Note: rubyipmi should auto detect which driver to use so its unnecessary to specify the driver unless
|
30
31
|
# the user really wants to.
|
31
|
-
@options['I'] =
|
32
|
+
@options['I'] = DRIVERS_MAP[opts[:driver]] unless DRIVERS_MAP[opts[:driver]].nil?
|
32
33
|
end
|
33
34
|
|
34
35
|
# test the connection to ensure we can at least make a single call
|
35
36
|
def connection_works?
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
false
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def drivers_map
|
44
|
-
{
|
45
|
-
'lan15' => 'lan',
|
46
|
-
'lan20' => 'lanplus',
|
47
|
-
'open' => 'open'
|
48
|
-
}
|
37
|
+
! (bmc.info.nil? || bmc.info.empty?)
|
38
|
+
rescue
|
39
|
+
false
|
49
40
|
end
|
50
41
|
|
51
42
|
def fru
|
@@ -1,67 +1,33 @@
|
|
1
1
|
module Rubyipmi
|
2
2
|
module Ipmitool
|
3
3
|
class ErrorCodes
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
"Error: Unable to establish LAN session\nGet Device ID command failed\n" => {"I" => "lanplus"}
|
10
|
-
|
11
|
-
|
4
|
+
CODES = {
|
5
|
+
"Authentication type NONE not supported\nAuthentication type NONE not supported\n" \
|
6
|
+
"Error: Unable to establish LAN session\nGet Device ID command failed\n" => {"I" => "lanplus"},
|
7
|
+
"Authentication type NONE not supported" => {"I" => "lanplus"},
|
8
|
+
"Error: Unable to establish LAN session\nGet Device ID command failed\n" => {"I" => "lanplus"}
|
12
9
|
}
|
10
|
+
|
13
11
|
def self.length
|
14
|
-
|
12
|
+
CODES.length
|
15
13
|
end
|
16
14
|
|
17
15
|
def self.code
|
18
|
-
|
16
|
+
CODES
|
19
17
|
end
|
20
18
|
|
21
19
|
def self.search(code)
|
22
|
-
fix =
|
20
|
+
fix = CODES.fetch(code, nil)
|
23
21
|
if fix.nil?
|
24
|
-
|
22
|
+
CODES.each do |error, result|
|
25
23
|
# the error should be a subset of the actual erorr
|
26
|
-
if code =~ /.*#{error}.*/i
|
27
|
-
return result
|
28
|
-
end
|
24
|
+
return result if code =~ /.*#{error}.*/i
|
29
25
|
end
|
30
26
|
else
|
31
27
|
return fix
|
32
28
|
end
|
33
29
|
raise "No Fix found" if fix.nil?
|
34
30
|
end
|
35
|
-
|
36
|
-
|
37
|
-
def throwError
|
38
|
-
# Find out what kind of error is happening, parse results
|
39
|
-
# Check for authentication or connection issue
|
40
|
-
|
41
|
-
if @result =~ /timeout|timed\ out/
|
42
|
-
code = "ipmi call: #{@lastcall} timed out"
|
43
|
-
raise code
|
44
|
-
else
|
45
|
-
code = @result.split(":").last.chomp.strip if not @result.empty?
|
46
|
-
end
|
47
|
-
case code
|
48
|
-
when "invalid hostname"
|
49
|
-
raise code
|
50
|
-
when "password invalid"
|
51
|
-
raise code
|
52
|
-
when "username invalid"
|
53
|
-
raise code
|
54
|
-
else
|
55
|
-
raise :ipmierror, code
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
31
|
end
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
32
|
end
|
66
33
|
end
|
67
|
-
|