Skip to content

Commit

Permalink
Merge pull request jhoblitt#16 from elisiano/foreman_facts
Browse files Browse the repository at this point in the history
IPMI facts (rebase only, original PR is jhoblitt#12)
  • Loading branch information
Joshua Hoblitt committed Oct 14, 2015
2 parents 683e0c0 + 7d4ac2e commit 2c67abe
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 9 deletions.
50 changes: 41 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ Puppet ipmi Module
3. [Usage](#usage)
* [Example](#example)
* [Classes](#classes)
4. [Limitations](#limitations)
4. [Additional Facts](#additional-facts)
5. [Limitations](#limitations)
* [Tested Platforms](#tested-platforms)
* [Puppet Version Compatibility](#puppet-version-compatibility)
5. [Versioning](#versioning)
6. [Support](#support)
7. [Contributing](#contributing)
8. [See Also](#see-also)
6. [Versioning](#versioning)
7. [Support](#support)
8. [Contributing](#contributing)
9. [See Also](#see-also)


Overview
Expand All @@ -29,10 +30,12 @@ Manages the OpenIPMI package
Description
-----------

Installs the [OpemIPMI](http://openipmi.sourceforge.net/) package and enables
the `ipmi` service. This loads the kernel drivers needed for communicating
with the BMC from user space.

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

Usage
-----
Expand Down Expand Up @@ -78,6 +81,35 @@ Controls the state of the `ipmievd` service.

Controls whether the IPMI watchdog is enabled.

Additional Facts
----------------

This module provides additional facts for Facter with the following
format:

```
ipmi1_gateway => 192.168.10.1
ipmi1_ipaddress => 192.168.10.201
ipmi1_ipaddress_source => Static Address
ipmi1_macaddress => 00:30:48:c9:64:2a
ipmi1_subnet_mask => 255.255.255.0
```

where the 1 in `ipmi1` corresponds to the channel according to
`ipmitool lan print`.

Additionally for compatibility with The Foreman, the first IPMI
interface (i.e. the one from `ipmi lan print 1`) gets all facts
repeated as just `ipmi_foo`:

```
ipmi_gateway => 192.168.10.1
ipmi_ipaddress => 192.168.10.201
ipmi_ipaddress_source => Static Address
ipmi_macaddress => 00:30:48:c9:64:2a
ipmi_subnet_mask => 255.255.255.0
```

Limitations
-----------

Expand Down
87 changes: 87 additions & 0 deletions lib/facter/ipmi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env ruby
#
# IPMI facts, in a format compatible with The Foreman
#
# Sending these facts to a puppetmaster equipped with RedHat's Foreman
# will cause the latter to create the BMC interfaces the next time the
# Puppet agent runs. One then only has to manually add the access
# credentials, and presto, you can run basic IPMI actions (e.g. reboot
# to PXE) from The Foreman's web UI.
#
# === Fact Format
#
# ipmi1_ipaddress = 192.168.101.1
# ipmi1_subnet_mask = 255.255.255.0
# ...
#
# where the 1 in "ipmi1" corresponds to the ID of the BMC according to
# ipmitool lan print.
#
# Additionally for compatibility with The Foreman, the first IPMI
# interface (i.e. the one from ipmi lan print 1) gets all facts
# repeated as just ipmi_foo:
#
# ipmi_ipaddress = 192.168.101.1
# ipmi_subnet_mask = 255.255.255.0
# ...
#

class IPMIChannel
public
def initialize channel_nr
@channel_nr = channel_nr
@has_facts = false
end

def load_facts
ipmitool_output = `env - $(which ipmitool) lan print #{@channel_nr} 2>&1`
parse_ipmitool_output ipmitool_output
if ipmitool_output =~ /Invalid channel/ then
return false
elsif not @has_facts
Facter.debug(ipmitool_output)
return false
else
return true
end
end

private
def parse_ipmitool_output ipmitool_output
ipmitool_output.each_line do |line|
case line.strip
when /^IP Address\s*:\s+(\S.*)/
add_ipmi_fact("ipaddress", $1)
when /^IP Address Source\s*:\s+(\S.*)/
add_ipmi_fact("ipaddress_source", $1)
when /^Subnet Mask\s*:\s+(\S.*)/
add_ipmi_fact("subnet_mask", $1)
when /^MAC Address\s*:\s+(\S.*)/
add_ipmi_fact("macaddress", $1)
when /^Default Gateway IP\s*:\s+(\S.*)/
add_ipmi_fact("gateway", $1)
end
end
end

def add_ipmi_fact name, value
fact_names = []
if @channel_nr == 1 then fact_names.push("ipmi_#{name}") end
fact_names.push("ipmi#{@channel_nr}_#{name}")
fact_names.each do |name|
Facter.add(name) do
confine :kernel => "Linux"
setcode do
value
end
end
end
@has_facts = true
end
end

channel_nr = 1
while true
break unless IPMIChannel.new(channel_nr).load_facts
channel_nr += 1
end

0 comments on commit 2c67abe

Please sign in to comment.