Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
68921f8
Facter module for gathering system bus facts
Mar 31, 2016
cc39d27
Facter modlue for gathering cpu facts
Mar 31, 2016
90212a1
Facter modlue for gathering disk facts
Mar 31, 2016
de501bc
Enhancements and comments for cpu fact generation
Mar 31, 2016
0a22340
Facter modlue for gathering disk volume facts
Mar 31, 2016
8c4917e
Facter modlue for gathering network facts
Mar 31, 2016
6927e44
Original facter script moved to facter and broken up into modules
Mar 31, 2016
4fa1e66
Facter modlue for gathering memory/firmware facts
Mar 31, 2016
7abc5ec
Updated Dockerfile to install facter modules
Mar 31, 2016
b0847ed
Removed references to hardware facter in registration controller
Mar 31, 2016
185aa9a
Added exception handling to memory factor module for debugging
Mar 31, 2016
c0ef09e
Fixed the canonizagtion of results keys when processing lshw output
Apr 1, 2016
01ae9e5
Updated to check for fact before trying to publish it
Apr 1, 2016
90c990b
Added counting facts to cpu, disk and nic modules
Apr 1, 2016
b125c38
Added counting facts to vol module
Apr 1, 2016
537c8a8
Fixed facts derrived from data structures that are reaped
Apr 1, 2016
3a4c3a6
Fixes to bus and mem facter modules
Apr 2, 2016
078fee9
Removed slot_info from mem facter module
Apr 2, 2016
b5f8a55
Fixed cpu facter module when cpu entries are disabled
Apr 3, 2016
684406f
Fixed mem facter module when memory size is in lshw output
Apr 3, 2016
2c10a31
Added mk_hw_core_count
Apr 8, 2016
247ce00
Added sys Facter module
Apr 8, 2016
f3a1811
Removed unnecessary load path change
Apr 8, 2016
eafb0e2
Added exception handling to squelch fatal errors
Apr 9, 2016
c4ebf23
Exception processing added to all Facter modules
Apr 9, 2016
78130b3
Fixed syntax error in hnl_mk_nic.rb
hickey Jul 28, 2016
53cfc4a
Created Docker entry point to give access to IPMI devices
hickey Oct 5, 2016
76c6410
Added Facter IPMI module
hickey Oct 5, 2016
8c4cecf
Added extras dir with content to create ipmitool APK
hickey Oct 6, 2016
a433bfb
Including ipmitool package and fix downloading rubygems
hickey Oct 6, 2016
ab1d210
Fixed IPMI module where some facts had periods
hickey Oct 7, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ FROM gliderlabs/alpine
ENV FACTER_VERSION 2.4.6

# Install any dependencies needed
ADD ipmitool-*.apk /tmp
RUN apk update && \
apk add bash sed dmidecode ruby ruby-irb open-lldp util-linux open-vm-tools sudo && \
apk add lshw ipmitool --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted && \
apk add lshw --update-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ --allow-untrusted && \
apk add --allow-untrusted /tmp/ipmitool-*.apk && \
echo "install: --no-rdoc --no-ri" > /etc/gemrc && \
curl -o $(dirname $(gem which rubygems))/rubygems/ssl_certs/AddTrustExternalCARoot-2048.pem https://curl.haxx.se/ca/cacert.pem && \
gem install json_pure daemons && \
gem install facter -v ${FACTER_VERSION} && \
find /usr/lib/ruby/gems/2.2.0/gems/facter-${FACTER_VERSION} -type f -exec sed -i 's:/proc/:/host-proc/:g' {} + && \
Expand All @@ -15,3 +18,8 @@ RUN apk update && \
find /usr/lib/ruby/gems/2.2.0/gems/facter-${FACTER_VERSION} -type f -exec sed -i 's:/sys/:/host-sys/:g' {} +
ADD hnl_mk*.rb /usr/local/bin/
ADD hanlon_microkernel/*.rb /usr/local/lib/ruby/hanlon_microkernel/
ADD hanlon_microkernel/facter/ /usr/local/lib/site_ruby/facter/
ADD entrypoint.sh /
ADD README.md /

ENTRYPOINT ["/entrypoint.sh"]
31 changes: 31 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# ----------------------------------------------------------------------------
# Docker entrypoint script for Hanlon microkernel
# ----------------------------------------------------------------------------
set -e

declare -rx SCRIPT=${0##*/}

# Setup to allow access to BMC from within container
modprobe ipmi_si
ln -s /host-dev/ipmi* /dev

# Default application if nothing is specified
if [ -z "${1:0:1}" ]; then
set -- start_mk
fi

case $1 in
start_mk)
set -- /bin/bash -c '/usr/local/bin/hnl_mk_init.rb && read -p "waiting..."'
;;
help|info)
set -- cat /README.md
;;
version|ver)
set -- cat /container-tmp-files/mk-version.yml | grep mk_version
esac

#echo "Executing: $@"
exec "$@"
32 changes: 32 additions & 0 deletions extras/ipmitool/APKBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Contributor:
# Maintainer:
pkgname=ipmitool
pkgver=1.8.17
pkgrel=0
pkgdesc="IPMItool provides a simple command-line interface to IPMI-enabled devices."
url="https://sourceforge.net/projects/ipmitool"
arch="all"
license="BSD"
depends=""
depends_dev="libc-dev make automake autoconf libtool"
makedepends="$depends_dev"
install=""
subpackages=""
source="http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.bz2"

builddir="$srcdir/$pkgname-$pkgver"
build() {
cd "$builddir"
LDFLAGS='-static' ./configure --prefix=/usr
make || return 1
}

package() {
cd "$builddir"
make DESTDIR="$pkgdir" install || return 1
rm -rf $pkgdir/usr/share/doc $pkgdir/usr/share/man
}

md5sums="f7408aa2b40333db0413d4aab6bbe978 ipmitool-1.8.17.tar.bz2"
sha256sums="97fa20efd9c87111455b174858544becae7fcc03a3cb7bf5c19b09065c842d02 ipmitool-1.8.17.tar.bz2"
sha512sums="b1fa95247c8b496ae1a4c01da032514849330297f2e28209ff211a7e61ed8226ef96fd330a7b79ff8b8bf04aef3cab06ec6765a985e5b51915dda28fb9f3c826 ipmitool-1.8.17.tar.bz2"
16 changes: 16 additions & 0 deletions extras/ipmitool/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM alpine:latest

RUN apk --no-cache add alpine-sdk coreutils \
&& adduser -G abuild -g "Alpine Package Builder" -s /bin/ash -D builder \
&& echo "builder ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
COPY README.md /
COPY entrypoint.sh /

WORKDIR /home/builder/
USER builder

ENTRYPOINT ["/entrypoint.sh"]


ENV RSA_PRIVATE_KEY_NAME ssh.rsa
ENV PACKAGER_PRIVKEY /home/builder/${RSA_PRIVATE_KEY_NAME}
26 changes: 26 additions & 0 deletions extras/ipmitool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Alpine Linux ipmitool build
===========================

The latest repos for Alpine Linux has dropped the ipmitool package. As
as result it is necessary to build ipmitool from scratch to get the APK
package file.

Simple Build
------------

From a host that has Docker installed simply execute the build.sh script.
This script will create an Alpine Linux container to create a build of
ipmitool, fetch the distribution, build and create the APK package. At
the end of the script, the APK file will be copied to the parent directory
to be included in the Hanlon-Microkernel container.

Manual Build
------------

If you really have a special case, then you can build manually by creating
the Docker container and then executing a shell to manually build ipmitool.
The following commands will get you to the command prompt in the container:

docker build -t ipmibuild .
docker run -it -v $(pwd):/home/builder ipmibuild ash

11 changes: 11 additions & 0 deletions extras/ipmitool/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -e

rm -rf packages pkg src

docker build -t ipmibuild .

docker run -it --rm -v $(pwd):/home/builder ipmibuild

cp packages/home/x86_64/ipmitool-*.apk ../..
23 changes: 23 additions & 0 deletions extras/ipmitool/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/ash

# ----------------------------------------------------------------------------
# Docker entrypoint script for building Alpine packages
# ----------------------------------------------------------------------------
set -e

# Default application if nothing is specified
if [ -z "${1:0:1}" ]; then
set -- start_apk_build
fi

case $1 in
start_apk_build)
set -- abuild-keygen -a -n; abuild unpack; abuild build; abuild rootpkg
;;
help|info)
set -- cat /README.md
;;
esac

#echo "Executing: $@"
exec "$@"
52 changes: 52 additions & 0 deletions hanlon_microkernel/facter/hnl_mk_bus.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Gathers hardware-related facts from the underlying system pertaining
# to the system buses. Information gathered here is exposed directly as
# Facter facts for the purpose of node registration.
#

require 'facter'



virtual_type = Facter.value('virtual')
lshw_cmd = (virtual_type && virtual_type == 'kvm') ? 'lshw -disable dmi' : 'lshw'
lshw_c_bus_str = %x[sudo #{lshw_cmd} -c bus 2> /dev/null]

# build the results into a Hash
results = {}
lshw_c_bus_str.split(/\s\s\*-/).each do |definition|
unless definition.empty?
lines = definition.split(/\n/)
item = lines.shift.tr(':', '')
attribs = Hash[ lines.collect do |l|
begin
l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v]
rescue NoMethodError
if Facter.debugging?
puts "Error: (bus class) unable to parse #{l}"
end
end
end ]
results[item] = attribs
end
end


# report out the core values
%w{description product vendor version serial physical_id}.each do |fact|
if results['core'].has_key? fact
val = results['core'][fact]
Facter.add("mk_hw_bus_#{fact}") do
setcode { val }
end
end
end

# now report the rest of the bus information
results.delete('core')
results.keys.each do |bus|
results[bus].each do |attrib, val|
Facter.add("mk_hw_bus_#{bus}_#{attrib}") do
setcode { val }
end
end
end
70 changes: 70 additions & 0 deletions hanlon_microkernel/facter/hnl_mk_cpu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Gathers hardware-related facts from the underlying system pertaining
# to the processors. Information gathered here is exposed directly as
# Facter facts for the purpose of node registration.
#

require 'facter'


virtual_type = Facter.value('virtual')
lshw_cmd = (virtual_type && virtual_type == 'kvm') ? 'lshw -disable dmi' : 'lshw'
lshw_c_cpu_str = %x[sudo #{lshw_cmd} -c cpu 2> /dev/null]

# process the results from lshw -c cpu
cpus = 0
lshw_c_cpu_str.split(/\s\s\*-/).each do |definition|
unless definition.empty?
lines = definition.split(/\n/)
# section title is on the first line
cpu = lines.shift.tr(':', '')
unless cpu =~ /disabled/i
cpus += 1
# Create a hash of attributes for each section (i.e. cpu)
attribs = Hash[ lines.collect do |l|
begin
l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v]
rescue NoMethodError
if Facter.debugging?
puts "Error: (cpu class) unable to parse #{l}"
end
end
end ]
attribs.each_pair do |attrib, val|
Facter.add("mk_hw_#{cpu}_#{attrib}") do
setcode { val }
end
end
end
end
end

# report on the number of CPUs
Facter.add("mk_hw_cpu_count") do
setcode { cpus }
end

# process the results from lscpu
facts_to_report = %w{Architecture BogoMIPS Byte_Order CPU_MHz CPU_family CPU_op-modes
L1d_cache L1i_cache L2_cache L3_cache Model Stepping Vendor_ID
Virtualization Virtualization_type Hypervisor_vendor
Threads_per_core Cores_per_socket Sockets
NUMA_nodes}
%x[lscpu].split(/\n/).each do |line|
line =~ /^([^:]+):\s*(.*)\s*$/
if $1
# map out chars that should not be part of the key
key = $1.tr(' ', '_').tr('()', '')
val = $2
if facts_to_report.include? key
Facter.add("mk_hw_lscpu_#{key}") do
setcode { val }
end
end
end
end

# report on the number of cores available
Facter.add("mk_hw_core_count") do
setcode { Facter.value('mk_hw_lscpu_cores_per_socket').to_i *
Facter.value('mk_hw_lscpu_sockets').to_i }
end
41 changes: 41 additions & 0 deletions hanlon_microkernel/facter/hnl_mk_disk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Gathers hardware-related facts from the underlying system pertaining
# to the physical disks. Information gathered here is exposed directly as
# Facter facts for the purpose of node registration.
#

require 'facter'


virtual_type = Facter.value('virtual')
lshw_cmd = (virtual_type && virtual_type == 'kvm') ? 'lshw -disable dmi' : 'lshw'
lshw_c_disk_str = %x[sudo #{lshw_cmd} -c disk 2> /dev/null]

# process the results from lshw -c disk
disks = 0
lshw_c_disk_str.split(/\s\s\*-/).each do |definition|
unless definition.empty?
lines = definition.split(/\n/)
# section title is on the first line
disk = lines.shift.tr(':', '')
disks += 1
# Create a hash of attributes for each section (i.e. cpu)
attribs = Hash[ lines.collect do |l|
begin
l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v]
rescue NoMethodError
if Facter.debugging?
puts "Error: (disk class) unable to parse #{l}"
end
end
end ]
attribs.each_pair do |attrib, val|
Facter.add("mk_hw_#{disk}_#{attrib}") do
setcode { val }
end
end
end
end

Facter.add("mk_hw_disk_count") do
setcode { disks }
end
Loading