Skip to content

Commit 2c67abe

Browse files
author
Joshua Hoblitt
committed
Merge pull request jhoblitt#16 from elisiano/foreman_facts
IPMI facts (rebase only, original PR is jhoblitt#12)
2 parents 683e0c0 + 7d4ac2e commit 2c67abe

File tree

2 files changed

+128
-9
lines changed

2 files changed

+128
-9
lines changed

README.md

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ Puppet ipmi Module
1111
3. [Usage](#usage)
1212
* [Example](#example)
1313
* [Classes](#classes)
14-
4. [Limitations](#limitations)
14+
4. [Additional Facts](#additional-facts)
15+
5. [Limitations](#limitations)
1516
* [Tested Platforms](#tested-platforms)
1617
* [Puppet Version Compatibility](#puppet-version-compatibility)
17-
5. [Versioning](#versioning)
18-
6. [Support](#support)
19-
7. [Contributing](#contributing)
20-
8. [See Also](#see-also)
18+
6. [Versioning](#versioning)
19+
7. [Support](#support)
20+
8. [Contributing](#contributing)
21+
9. [See Also](#see-also)
2122

2223

2324
Overview
@@ -29,10 +30,12 @@ Manages the OpenIPMI package
2930
Description
3031
-----------
3132

32-
Installs the [OpemIPMI](http://openipmi.sourceforge.net/) package and enables
33-
the `ipmi` service. This loads the kernel drivers needed for communicating
34-
with the BMC from user space.
35-
33+
Installs the [OpemIPMI](http://openipmi.sourceforge.net/) package,
34+
provides IPMI facts in a format compatible with
35+
[The Foreman](www.theforeman.org)'s
36+
[BMC features](www.theforeman.org/manuals/latest/index.html#4.3.3BMC)
37+
and enables the `ipmi` service. The latter loads the kernel drivers
38+
needed for communicating with the BMC from user space.
3639

3740
Usage
3841
-----
@@ -78,6 +81,35 @@ Controls the state of the `ipmievd` service.
7881

7982
Controls whether the IPMI watchdog is enabled.
8083

84+
Additional Facts
85+
----------------
86+
87+
This module provides additional facts for Facter with the following
88+
format:
89+
90+
```
91+
ipmi1_gateway => 192.168.10.1
92+
ipmi1_ipaddress => 192.168.10.201
93+
ipmi1_ipaddress_source => Static Address
94+
ipmi1_macaddress => 00:30:48:c9:64:2a
95+
ipmi1_subnet_mask => 255.255.255.0
96+
```
97+
98+
where the 1 in `ipmi1` corresponds to the channel according to
99+
`ipmitool lan print`.
100+
101+
Additionally for compatibility with The Foreman, the first IPMI
102+
interface (i.e. the one from `ipmi lan print 1`) gets all facts
103+
repeated as just `ipmi_foo`:
104+
105+
```
106+
ipmi_gateway => 192.168.10.1
107+
ipmi_ipaddress => 192.168.10.201
108+
ipmi_ipaddress_source => Static Address
109+
ipmi_macaddress => 00:30:48:c9:64:2a
110+
ipmi_subnet_mask => 255.255.255.0
111+
```
112+
81113
Limitations
82114
-----------
83115

lib/facter/ipmi.rb

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env ruby
2+
#
3+
# IPMI facts, in a format compatible with The Foreman
4+
#
5+
# Sending these facts to a puppetmaster equipped with RedHat's Foreman
6+
# will cause the latter to create the BMC interfaces the next time the
7+
# Puppet agent runs. One then only has to manually add the access
8+
# credentials, and presto, you can run basic IPMI actions (e.g. reboot
9+
# to PXE) from The Foreman's web UI.
10+
#
11+
# === Fact Format
12+
#
13+
# ipmi1_ipaddress = 192.168.101.1
14+
# ipmi1_subnet_mask = 255.255.255.0
15+
# ...
16+
#
17+
# where the 1 in "ipmi1" corresponds to the ID of the BMC according to
18+
# ipmitool lan print.
19+
#
20+
# Additionally for compatibility with The Foreman, the first IPMI
21+
# interface (i.e. the one from ipmi lan print 1) gets all facts
22+
# repeated as just ipmi_foo:
23+
#
24+
# ipmi_ipaddress = 192.168.101.1
25+
# ipmi_subnet_mask = 255.255.255.0
26+
# ...
27+
#
28+
29+
class IPMIChannel
30+
public
31+
def initialize channel_nr
32+
@channel_nr = channel_nr
33+
@has_facts = false
34+
end
35+
36+
def load_facts
37+
ipmitool_output = `env - $(which ipmitool) lan print #{@channel_nr} 2>&1`
38+
parse_ipmitool_output ipmitool_output
39+
if ipmitool_output =~ /Invalid channel/ then
40+
return false
41+
elsif not @has_facts
42+
Facter.debug(ipmitool_output)
43+
return false
44+
else
45+
return true
46+
end
47+
end
48+
49+
private
50+
def parse_ipmitool_output ipmitool_output
51+
ipmitool_output.each_line do |line|
52+
case line.strip
53+
when /^IP Address\s*:\s+(\S.*)/
54+
add_ipmi_fact("ipaddress", $1)
55+
when /^IP Address Source\s*:\s+(\S.*)/
56+
add_ipmi_fact("ipaddress_source", $1)
57+
when /^Subnet Mask\s*:\s+(\S.*)/
58+
add_ipmi_fact("subnet_mask", $1)
59+
when /^MAC Address\s*:\s+(\S.*)/
60+
add_ipmi_fact("macaddress", $1)
61+
when /^Default Gateway IP\s*:\s+(\S.*)/
62+
add_ipmi_fact("gateway", $1)
63+
end
64+
end
65+
end
66+
67+
def add_ipmi_fact name, value
68+
fact_names = []
69+
if @channel_nr == 1 then fact_names.push("ipmi_#{name}") end
70+
fact_names.push("ipmi#{@channel_nr}_#{name}")
71+
fact_names.each do |name|
72+
Facter.add(name) do
73+
confine :kernel => "Linux"
74+
setcode do
75+
value
76+
end
77+
end
78+
end
79+
@has_facts = true
80+
end
81+
end
82+
83+
channel_nr = 1
84+
while true
85+
break unless IPMIChannel.new(channel_nr).load_facts
86+
channel_nr += 1
87+
end

0 commit comments

Comments
 (0)