rubyipmi 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +33 -0
- data/LICENSE.txt +20 -0
- data/README.md +267 -0
- data/README.rdoc +18 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/rubyipmi.rb +80 -0
- data/lib/rubyipmi/commands/basecommand.rb +171 -0
- data/lib/rubyipmi/freeipmi/commands/basecommand.rb +60 -0
- data/lib/rubyipmi/freeipmi/commands/bmc.rb +37 -0
- data/lib/rubyipmi/freeipmi/commands/bmcconfig.rb +57 -0
- data/lib/rubyipmi/freeipmi/commands/bmcinfo.rb +76 -0
- data/lib/rubyipmi/freeipmi/commands/chassis.rb +123 -0
- data/lib/rubyipmi/freeipmi/commands/chassisconfig.rb +100 -0
- data/lib/rubyipmi/freeipmi/commands/lan.rb +111 -0
- data/lib/rubyipmi/freeipmi/commands/power.rb +72 -0
- data/lib/rubyipmi/freeipmi/connection.rb +43 -0
- data/lib/rubyipmi/freeipmi/errorcodes.rb +15 -0
- data/lib/rubyipmi/ipmitool/commands/basecommand.rb +60 -0
- data/lib/rubyipmi/ipmitool/commands/bmc.rb +95 -0
- data/lib/rubyipmi/ipmitool/commands/chassis.rb +106 -0
- data/lib/rubyipmi/ipmitool/commands/chassisconfig.rb +52 -0
- data/lib/rubyipmi/ipmitool/commands/lan.rb +162 -0
- data/lib/rubyipmi/ipmitool/commands/power.rb +74 -0
- data/lib/rubyipmi/ipmitool/connection.rb +46 -0
- data/lib/rubyipmi/ipmitool/errorcodes.rb +18 -0
- data/lib/rubyipmi/observablehash.rb +20 -0
- data/rubyipmi.gemspec +91 -0
- data/spec/bmc_spec.rb +35 -0
- data/spec/chassis_config_spec.rb +38 -0
- data/spec/chassis_spec.rb +24 -0
- data/spec/connection_spec.rb +31 -0
- data/spec/lan_spec.rb +61 -0
- data/spec/power_spec.rb +40 -0
- data/spec/rubyipmi_spec.rb +59 -0
- data/spec/spec_helper.rb +12 -0
- metadata +181 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.8.0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.1.5"
|
12
|
+
gem "jeweler", "~> 1.8.4"
|
13
|
+
gem "rcov", ">= 0"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.8.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rdoc
|
11
|
+
json (1.7.4)
|
12
|
+
rake (0.9.2.2)
|
13
|
+
rcov (1.0.0)
|
14
|
+
rdoc (3.12)
|
15
|
+
json (~> 1.4)
|
16
|
+
rspec (2.8.0)
|
17
|
+
rspec-core (~> 2.8.0)
|
18
|
+
rspec-expectations (~> 2.8.0)
|
19
|
+
rspec-mocks (~> 2.8.0)
|
20
|
+
rspec-core (2.8.0)
|
21
|
+
rspec-expectations (2.8.0)
|
22
|
+
diff-lcs (~> 1.1.2)
|
23
|
+
rspec-mocks (2.8.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.1.5)
|
30
|
+
jeweler (~> 1.8.4)
|
31
|
+
rcov
|
32
|
+
rdoc (~> 3.12)
|
33
|
+
rspec (~> 2.8.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Corey Osman
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,267 @@
|
|
1
|
+
# rubyipmi
|
2
|
+
This gem is a ruby wrapper for the freeipmi and ipmitool command line tools.
|
3
|
+
It provides a ruby implementation of ipmi commands that will make it simple to connect to BMC devices from ruby.
|
4
|
+
|
5
|
+
## Using the library in your code
|
6
|
+
|
7
|
+
### Install
|
8
|
+
|
9
|
+
|
10
|
+
1. Install the freeipmi from source (http://www.gnu.org/software/freeipmi/) or ipmitool
|
11
|
+
2. gem install rubyipmi
|
12
|
+
|
13
|
+
### General Usage
|
14
|
+
|
15
|
+
` require 'rubyipmi' `
|
16
|
+
|
17
|
+
#### Create a connection object
|
18
|
+
`conn = Rubyipmi.connect("username", "password", "hostname", "providertype) `
|
19
|
+
|
20
|
+
Providertype: optional (ipmitool or freeipmi)
|
21
|
+
|
22
|
+
If you don't specify the provider type, Rubyipmi will detect if freeipmi or ipmitool
|
23
|
+
is installed and load the first tool found. If you specify the provider type rubyipmi will only use that specific
|
24
|
+
provider.
|
25
|
+
|
26
|
+
|
27
|
+
#### Use power functions (not all listed)
|
28
|
+
<pre>
|
29
|
+
conn.chassis.power.on
|
30
|
+
conn.chassis.power.off
|
31
|
+
conn.chassis.power.on?
|
32
|
+
conn.chassis.power.off?
|
33
|
+
conn.chassis.power.cycle
|
34
|
+
</pre>
|
35
|
+
|
36
|
+
#### Boot to specific device
|
37
|
+
<pre>
|
38
|
+
conn.chassis.bootpxe(true, false) # reboot after setting, one time boot only - non persistent
|
39
|
+
conn.chassis.bootdisk(false, false) # boot to disk on next reboot, don't reboot automatically
|
40
|
+
|
41
|
+
</pre>
|
42
|
+
|
43
|
+
## Testing
|
44
|
+
There are a series of automated rspec tests that test the functionality of this library with the ipmi device.
|
45
|
+
In order to perform use the following steps.
|
46
|
+
|
47
|
+
DO NOT PERFORM THESE TEST ON ANY PRODUCTION SYSTEM. THESE TESTS WILL TURN OFF THE DEVICE!
|
48
|
+
|
49
|
+
|
50
|
+
1. Install gem via source
|
51
|
+
2. bundle install
|
52
|
+
3. rake ipmiuser=ipmiuser ipmipass=ipmiuserpass ipmihost=192.168.1.22 ipmiprovider=freeipmi (fill in your your details)
|
53
|
+
4. report any failures with your make/model/firmware revision to corey@logicminds.biz
|
54
|
+
|
55
|
+
## Security
|
56
|
+
Currently security is not enforced in the development process. Furthermore, the rubyipmi library uses the same methods
|
57
|
+
currently provided by the C based freeipmi command line tools. This includes the use of freeipmi.conf file. You can easily
|
58
|
+
store credentials in this file which will be included automatically via the command line.
|
59
|
+
|
60
|
+
|
61
|
+
## How the library works
|
62
|
+
Since this library is based off of running a suite of command line tools I have created a base class called baseCommand
|
63
|
+
that performs the actual execution of the command. The baseCommand only executes the command with the supplied
|
64
|
+
arguments and options and returns the exit status. Additionally the result of the executed command is stored in
|
65
|
+
the result variable should we need to retrieve the output of the command. To further extend the baseCommand class.
|
66
|
+
|
67
|
+
|
68
|
+
### Creating a new command
|
69
|
+
Creating a new command is actually quite simple. Follow these steps to wrap a freeipmi or ipmitool command.
|
70
|
+
|
71
|
+
1. Create a new subclass of BaseCommand
|
72
|
+
2. define the initialize function like so, and pass in the name of the command line tool to the super constructor.
|
73
|
+
|
74
|
+
```
|
75
|
+
def initialize(opts = {})
|
76
|
+
@options = opts
|
77
|
+
super("bmc-info", opts)
|
78
|
+
end
|
79
|
+
|
80
|
+
```
|
81
|
+
|
82
|
+
```
|
83
|
+
def initialize(opts = {})
|
84
|
+
@options = opts
|
85
|
+
super("ipmitool", opts)
|
86
|
+
end
|
87
|
+
|
88
|
+
```
|
89
|
+
3. Thats it. The rest of the class is related to running the command and interperting the results
|
90
|
+
|
91
|
+
### Writing a function for running a command
|
92
|
+
The freeipmi command line tools have two different ways to run the commands.
|
93
|
+
|
94
|
+
1. ``` ipmipower --hostname=host --password=pass --username=user --off ``` (single action, multiple arguments)
|
95
|
+
2. ``` ipmi-chassis --hostname=host --password=pass --username=user --chassis-identify=FORCE ``` (multiple arguments, one main action with different qualifers)
|
96
|
+
|
97
|
+
Because of the varying ways to run a command I have simplified them so it makes it easy to call the command line tools.
|
98
|
+
|
99
|
+
1. Each subclassed baseCommand class inherits runcmd, result, cmd, and runcmd_with_args.
|
100
|
+
2. The cmd executable gets set when instantiating a baseCommand class, where the class also finds the path of the executable.
|
101
|
+
3. The options variable gets set when instantiating a subclass of the baseCommand class.
|
102
|
+
|
103
|
+
### Running the cmd
|
104
|
+
|
105
|
+
1. To run the cmd, just call ``` runcmd ``` (which will automatically set all the options specified in the options hash)
|
106
|
+
2. To run the cmd, with arguments and options call ``` runcmd([]) ``` and pass in a array of the arguments. (Arguments are actions only and look like --off, --on, --action)
|
107
|
+
3. To run the cmd, with just arguments ``` runcmd_with_args([]) ``` and pass in a array of the arguments. (Example: 192.168.1.1)
|
108
|
+
|
109
|
+
### The Options hash
|
110
|
+
The options hash can be considered a global hash that is passed in through the connection object.
|
111
|
+
Most of the options will be set at the connection level. However, most commands require additional options
|
112
|
+
that should be set at the subclassed BaseCommand level. You must not forget to unset the option after calling
|
113
|
+
the runcmd command. Failure to do so will add previous options to subsequent run options.
|
114
|
+
|
115
|
+
Example:
|
116
|
+
|
117
|
+
```
|
118
|
+
def ledlight(status=false, delay=300)
|
119
|
+
if status
|
120
|
+
if delay <= 0
|
121
|
+
options["chassis-identify"] = "FORCE"
|
122
|
+
else
|
123
|
+
options["chassis-identify"] = delay
|
124
|
+
end
|
125
|
+
else
|
126
|
+
options["chassis-identify"] = "TURN-OFF"
|
127
|
+
end
|
128
|
+
# Run the command
|
129
|
+
run
|
130
|
+
# unset the option by deleting from hash
|
131
|
+
options.delete("chassis-identify")
|
132
|
+
end
|
133
|
+
|
134
|
+
```
|
135
|
+
|
136
|
+
### How to get the results of the command
|
137
|
+
After running a command it may be desirable to get the results for further processing. To get the results, follow the example below:
|
138
|
+
|
139
|
+
Example:
|
140
|
+
|
141
|
+
```
|
142
|
+
def status
|
143
|
+
command("--stat")
|
144
|
+
@result.split(":").last.chomp.trim
|
145
|
+
end
|
146
|
+
|
147
|
+
def command(opt)
|
148
|
+
status = run([opt])
|
149
|
+
return status
|
150
|
+
end
|
151
|
+
|
152
|
+
def on?
|
153
|
+
status == "on"
|
154
|
+
end
|
155
|
+
|
156
|
+
```
|
157
|
+
|
158
|
+
### The command function
|
159
|
+
Although its not necessary to implement the command function it may be desirable if your code starts to repeat itself.
|
160
|
+
In this example the command function is just a wrapper command that calls run. Your implementation will vary,
|
161
|
+
but be sure to always call it the "command" function, so its easily identified.
|
162
|
+
Additionally, should this gem ever become out of date one could call the command function and pass in any
|
163
|
+
arguments that have not already been implemented in the rest of the class.
|
164
|
+
|
165
|
+
```
|
166
|
+
def command(opt)
|
167
|
+
status = runcmd([opt])
|
168
|
+
return status
|
169
|
+
end
|
170
|
+
|
171
|
+
def on
|
172
|
+
command("--on")
|
173
|
+
end
|
174
|
+
|
175
|
+
```
|
176
|
+
|
177
|
+
## The following are tools bundled with freeipmi
|
178
|
+
|
179
|
+
* ipmi-chassis
|
180
|
+
* ipmi-oem
|
181
|
+
* ipmi-chassis-config
|
182
|
+
* ipmiping
|
183
|
+
* ipmiconsole
|
184
|
+
* ipmipower
|
185
|
+
* ipmidetect
|
186
|
+
* ipmi-raw
|
187
|
+
* ipmi-fru
|
188
|
+
* ipmi-sel
|
189
|
+
* ipmi-locate
|
190
|
+
* ipmi-sensors
|
191
|
+
* ipmimonitoring
|
192
|
+
* ipmi-sensors-config
|
193
|
+
* bmc-config
|
194
|
+
* bmc-device
|
195
|
+
* bmc-info
|
196
|
+
|
197
|
+
## To contrast ipmitool has one command with many options
|
198
|
+
* ipmitool
|
199
|
+
|
200
|
+
|
201
|
+
|
202
|
+
## Auto Detect workarounds
|
203
|
+
IPMI is great for a vendor neutral management interface. However, not all servers are 100% compatible with the specifications.
|
204
|
+
In order to overcome ipmi non-compliance there will be some workarounds built into this library
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
## Contributing to rubyipmi
|
209
|
+
|
210
|
+
* Check out the latest code to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
211
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
212
|
+
* Fork the project.
|
213
|
+
* Start a feature/bugfix branch.
|
214
|
+
* Commit and push until you are happy with your contribution.
|
215
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
216
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
217
|
+
|
218
|
+
## Copyright
|
219
|
+
|
220
|
+
Copyright (c) 2012 Corey Osman. See LICENSE.txt for
|
221
|
+
further details.
|
222
|
+
|
223
|
+
|
224
|
+
## Freeipmi Documented Workarounds
|
225
|
+
|
226
|
+
|
227
|
+
One of my design goals is to raise exceptions and have the library try workarounds before ultimately failing since there is a whole list of workarounds that can be attempted.However, it would be nice to know the make and model of the server up front to decrease workaround attempts.
|
228
|
+
|
229
|
+
So essentially I need to figure out how to save a command call and then retry if it doesn't work.
|
230
|
+
|
231
|
+
With so many different vendors implementing their own IPMI solutions, different vendors may implement their IPMI protocols incorrectly. The following describes a number of workarounds currently available to handle discovered compliance issues. When possible, workarounds have been implemented so they will be transparent to the user. However, some will require the user to specify a workaround be used via the -W option.
|
232
|
+
The hardware listed below may only indicate the hardware that a problem was discovered on. Newer versions of hardware may fix the problems indicated below. Similar machines from vendors may or may not exhibit the same problems. Different vendors may license their firmware from the same IPMI firmware developer, so it may be worthwhile to try workarounds listed below even if your motherboard is not listed.
|
233
|
+
|
234
|
+
If you believe your hardware has an additional compliance issue that needs a workaround to be implemented, please contact the FreeIPMI maintainers on <freeipmi-users@gnu.org> or <freeipmi-devel@gnu.org>.
|
235
|
+
|
236
|
+
assumeio - This workaround flag will assume inband interfaces communicate with system I/O rather than being memory-mapped. This will work around systems that report invalid base addresses. Those hitting this issue may see "device not supported" or "could not find inband device" errors. Issue observed on HP ProLiant DL145 G1.
|
237
|
+
|
238
|
+
spinpoll - This workaround flag will inform some inband drivers (most notably the KCS driver) to spin while polling rather than putting the process to sleep. This may significantly improve the wall clock running time of tools because an operating system scheduler's granularity may be much larger than the time it takes to perform a single IPMI message transaction. However, by spinning, your system may be performing less useful work by not contexting out the tool for a more useful task.
|
239
|
+
|
240
|
+
authcap - This workaround flag will skip early checks for username capabilities, authentication capabilities, and K_g support and allow IPMI authentication to succeed. It works around multiple issues in which the remote system does not properly report username capabilities, authentication capabilities, or K_g status. Those hitting this issue may see "username invalid", "authentication type unavailable for attempted privilege level", or "k_g invalid" errors. Issue observed on Asus P5M2/P5MT-R/RS162-E4/RX4, Intel SR1520ML/X38ML, and Sun Fire 2200/4150/4450 with ELOM.
|
241
|
+
|
242
|
+
idzero - This workaround flag will allow empty session IDs to be accepted by the client. It works around IPMI sessions that report empty session IDs to the client. Those hitting this issue may see "session timeout" errors. Issue observed on Tyan S2882 with M3289 BMC.
|
243
|
+
|
244
|
+
unexpectedauth - This workaround flag will allow unexpected non-null authcodes to be checked as though they were expected. It works around an issue when packets contain non-null authentication data when they should be null due to disabled per-message authentication. Those hitting this issue may see "session timeout" errors. Issue observed on Dell PowerEdge 2850,SC1425. Confirmed fixed on newer firmware.
|
245
|
+
|
246
|
+
forcepermsg - This workaround flag will force per-message authentication to be used no matter what is advertised by the remote system. It works around an issue when per-message authentication is advertised as disabled on the remote system, but it is actually required for the protocol. Those hitting this issue may see "session timeout" errors. Issue observed on IBM eServer 325.
|
247
|
+
|
248
|
+
endianseq - This workaround flag will flip the endian of the session sequence numbers to allow the session to continue properly. It works around IPMI 1.5 session sequence numbers that are the wrong endian. Those hitting this issue may see "session timeout" errors. Issue observed on some Sun ILOM 1.0/2.0 (depends on service processor endian).
|
249
|
+
|
250
|
+
intel20 - This workaround flag will work around several Intel IPMI 2.0 authentication issues. The issues covered include padding of usernames, and password truncation if the authentication algorithm is HMAC-MD5-128. Those hitting this issue may see "username invalid", "password invalid", or "k_g invalid" errors. Issue observed on Intel SE7520AF2 with Intel Server Management Module (Professional Edition).
|
251
|
+
|
252
|
+
supermicro20 - This workaround flag will work around several Supermicro IPMI 2.0 authentication issues on motherboards w/ Peppercon IPMI firmware. The issues covered include handling invalid length authentication codes. Those hitting this issue may see "password invalid" errors. Issue observed on Supermicro H8QME with SIMSO daughter card. Confirmed fixed on newerver firmware.
|
253
|
+
|
254
|
+
sun20 - This workaround flag will work work around several Sun IPMI 2.0 authentication issues. The issues covered include invalid lengthed hash keys, improperly hashed keys, and invalid cipher suite records. Those hitting this issue may see "password invalid" or "bmc error" errors. Issue observed on Sun Fire 4100/4200/4500 with ILOM. This workaround automatically includes the "opensesspriv" workaround.
|
255
|
+
|
256
|
+
opensesspriv - This workaround flag will slightly alter FreeIPMI's IPMI 2.0 connection protocol to workaround an invalid hashing algorithm used by the remote system. The privilege level sent during the Open Session stage of an IPMI 2.0 connection is used for hashing keys instead of the privilege level sent during the RAKP1 connection stage. Those hitting this issue may see "password invalid", "k_g invalid", or "bad rmcpplus status code" errors. Issue observed on Sun Fire 4100/4200/4500 with ILOM, Inventec 5441/Dell Xanadu II, Supermicro X8DTH, Supermicro X8DTG, Intel S5500WBV/Penguin Relion 700, Intel S2600JF/Appro 512X, and Quanta QSSC-S4R//Appro GB812X-CN. This workaround is automatically triggered with the "sun20" workaround.
|
257
|
+
|
258
|
+
integritycheckvalue - This workaround flag will work around an invalid integrity check value during an IPMI 2.0 session establishment when using Cipher Suite ID 0. The integrity check value should be 0 length, however the remote motherboard responds with a non-empty field. Those hitting this issue may see "k_g invalid" errors. Issue observed on Supermicro X8DTG, Supermicro X8DTU, and Intel S5500WBV/Penguin Relion 700, and Intel S2600JF/Appro 512X.
|
259
|
+
|
260
|
+
No IPMI 1.5 Support - Some motherboards that support IPMI 2.0 have been found to not support IPMI 1.5. Those hitting this issue may see "ipmi 2.0 unavailable" or "connection timeout" errors. This issue can be worked around by using IPMI 2.0 instead of IPMI 1.5 by specifying --driver-address=LAN_2_0. Issue observed on HP Proliant DL 145.
|
261
|
+
|
262
|
+
slowcommit - This workaround will slow down commits to the BMC by sleeping one second between the commit of sections. It works around motherboards that have BMCs that can be overwhelmed by commits. Those hitting this issue may see commit errors or commits not being written to the BMC. Issue observed on Supermicro H8QME.
|
263
|
+
|
264
|
+
veryslowcommit - This workaround will slow down commits to the BMC by sleeping one second between the commit of every key. It works around motherboards that have BMCs that can be overwhelmed by commits. Those hitting this issue may see commit errors or commits not being written to the BMC. Issue observed on Quanta S99Q/Dell FS12-TY.
|
265
|
+
|
266
|
+
|
267
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= rubyipmi
|
2
|
+
|
3
|
+
|
4
|
+
== Contributing to rubyipmi
|
5
|
+
|
6
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
7
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
8
|
+
* Fork the project.
|
9
|
+
* Start a feature/bugfix branch.
|
10
|
+
* Commit and push until you are happy with your contribution.
|
11
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
12
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
13
|
+
|
14
|
+
== Copyright
|
15
|
+
|
16
|
+
Copyright (c) 2012 Corey Osman. See LICENSE.txt for
|
17
|
+
further details.
|
18
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "rubyipmi"
|
18
|
+
gem.homepage = "http://github.com/logicminds/rubyipmi"
|
19
|
+
gem.license = "GPLv3"
|
20
|
+
gem.summary = %Q{A ruby wrapper for ipmi command line tools that supports ipmitool and freeipmi}
|
21
|
+
gem.description = %Q{A ruby wrapper for ipmi command line tools that supports ipmitool and freeipmi}
|
22
|
+
gem.email = "corey@logicminds.biz"
|
23
|
+
gem.authors = ["Corey Osman"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "rubyipmi #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.0
|
data/lib/rubyipmi.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'rubyipmi/ipmitool/connection'
|
2
|
+
require 'rubyipmi/freeipmi/connection'
|
3
|
+
|
4
|
+
module Rubyipmi
|
5
|
+
|
6
|
+
|
7
|
+
# The connect method will create a connection object based the provider type passed in
|
8
|
+
# If provider is left blank the function will use the first available provider
|
9
|
+
|
10
|
+
def self.connect(user, pass, host, provider="any")
|
11
|
+
|
12
|
+
# use this variable to reduce cmd calls
|
13
|
+
installed = false
|
14
|
+
|
15
|
+
# use the first available provider
|
16
|
+
if provider == "any"
|
17
|
+
if is_provider_installed?("freeipmi")
|
18
|
+
provider = "freeipmi"
|
19
|
+
installed = true
|
20
|
+
elsif is_provider_installed?("ipmitool")
|
21
|
+
provider = "ipmitool"
|
22
|
+
installed = true
|
23
|
+
else
|
24
|
+
raise "No IPMI provider is installed, please install freeipmi or ipmitool"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# If the provider is available create a connection object
|
29
|
+
if installed or is_provider_installed?(provider)
|
30
|
+
if provider == "freeipmi"
|
31
|
+
@conn = Rubyipmi::Freeipmi::Connection.new(user, pass, host)
|
32
|
+
elsif provider == "ipmitool"
|
33
|
+
@conn = Rubyipmi::Ipmitool::Connection.new(user,pass,host)
|
34
|
+
else
|
35
|
+
raise "Incorrect provider given, must use freeipmi or ipmitool"
|
36
|
+
end
|
37
|
+
else
|
38
|
+
# Can't find the provider command line tool, maybe try other provider?
|
39
|
+
raise "The IPMI provider: #{provider} is not installed"
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.connection
|
45
|
+
return @conn if @conn
|
46
|
+
raise "No Connection available, please use the connect method"
|
47
|
+
end
|
48
|
+
|
49
|
+
# Return true or false if the provider is available
|
50
|
+
def self.is_provider_installed?(provider)
|
51
|
+
case provider
|
52
|
+
when "freeipmi"
|
53
|
+
cmdpath = `which ipmipower`.strip
|
54
|
+
when "ipmitool"
|
55
|
+
cmdpath = `which ipmitool`.strip
|
56
|
+
else
|
57
|
+
raise "Invalid BMC provider type"
|
58
|
+
end
|
59
|
+
return $?.success?
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.providers
|
63
|
+
["freeipmi", "ipmitool"]
|
64
|
+
end
|
65
|
+
|
66
|
+
# returns true if any of the providers are installed
|
67
|
+
def self.provider_installed?
|
68
|
+
providers_installed?.length > 0
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.providers_installed?
|
72
|
+
available = []
|
73
|
+
providers.each do |prov|
|
74
|
+
if is_provider_installed?(prov)
|
75
|
+
available << prov
|
76
|
+
end
|
77
|
+
end
|
78
|
+
return available
|
79
|
+
end
|
80
|
+
end
|