Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to filesystem and wpar detection on AIX #654

Merged
merged 1 commit into from
Dec 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
62 changes: 34 additions & 28 deletions lib/ohai/plugins/aix/cpu.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#
# Author:: Joshua Timberman <joshua@opscode.com>
# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
# Copyright:: Copyright (c) 2013, Opscode, Inc.
# Author:: Isa Farnik (<isa@chef.io>)
# Copyright:: Copyright (c) 2013-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -22,36 +23,41 @@

collect_data(:aix) do
cpu Mash.new

cpu[:total] = shell_out("pmcycles -m").stdout.lines.length
# At least one CPU will be available, but we'll wait to increment this later.
cpu[:available] = 0

cpudevs = shell_out("lsdev -Cc processor").stdout.lines
#from http://www-01.ibm.com/software/passportadvantage/pvu_terminology_for_customers.html
#on AIX number of cores and processors are considered same
cpu[:real] = cpu[:cores] = cpudevs.length
cpudevs.each.with_index do |c,i|
name, status, location = c.split
index = i.to_s
cpu[index] = Mash.new
cpu[index][:status] = status
cpu[index][:location] = location
if status =~ /Available/
cpu[:available] += 1
lsattr = shell_out("lsattr -El #{name}").stdout.lines
lsattr.each do |attribute|
attrib, value = attribute.split
if attrib == "type"
cpu[index][:model_name] = value
elsif attrib == "frequency"
cpu[index][:mhz] = value.to_i / (1000 * 1000) #convert from hz to MHz
else
cpu[index][attrib] = value
# The below is only relevent on an LPAR
if shell_out('uname -W').stdout.strip == "0"

# At least one CPU will be available, but we'll wait to increment this later.
cpu[:available] = 0

cpudevs = shell_out("lsdev -Cc processor").stdout.lines
#from http://www-01.ibm.com/software/passportadvantage/pvu_terminology_for_customers.html
#on AIX number of cores and processors are considered same
cpu[:real] = cpu[:cores] = cpudevs.length
cpudevs.each.with_index do |c,i|
name, status, location = c.split
index = i.to_s
cpu[index] = Mash.new
cpu[index][:status] = status
cpu[index][:location] = location
if status =~ /Available/
cpu[:available] += 1
lsattr = shell_out("lsattr -El #{name}").stdout.lines
lsattr.each do |attribute|
attrib, value = attribute.split
if attrib == "type"
cpu[index][:model_name] = value
elsif attrib == "frequency"
cpu[index][:mhz] = value.to_i / (1000 * 1000) #convert from hz to MHz
else
cpu[index][attrib] = value
end
end
end
# IBM is the only maker of CPUs for AIX systems.
cpu[index][:vendor_id] = "IBM"
# IBM is the only maker of CPUs for AIX systems.
cpu[index][:vendor_id] = "IBM"
end
end
end
end
Expand Down
98 changes: 58 additions & 40 deletions lib/ohai/plugins/aix/filesystem.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#
# Author:: Deepali Jagtap (<deepali.jagtap@clogeny.com>)
# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
# Copyright:: Copyright (c) 2013 Opscode, Inc.
# Author:: Isa Farnik (<isa@chef.io>)
# Copyright:: Copyright (c) 2013-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -21,52 +22,69 @@
Ohai.plugin(:Filesystem) do
provides "filesystem"

collect_data(:aix) do
fs = Mash.new
def parse_df_or_mount(shell_out)
oldie = Mash.new

# Grab filesystem data from df
so = shell_out("df -P")
so.stdout.lines.each do |line|
shell_out.lines.each do |line|
fields = line.split
case line
when /^Filesystem\s+1024-blocks/
# headers and horizontal rules to skip
when /^\s*(node|---|^Filesystem\s+1024-blocks)/
next
when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
filesystem = $1
fs[filesystem] = Mash.new
fs[filesystem][:kb_size] = $2
fs[filesystem][:kb_used] = $3
fs[filesystem][:kb_available] = $4
fs[filesystem][:percent_used] = $5
fs[filesystem][:mount] = $6
# strictly a df entry
when /^(.+?)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+\%*)\s+(.+)$/
if $1 == "Global"
key = "#{$1}:#{$6}"
else
key = $1
end
oldie[key] ||= Mash.new
oldie[key][:kb_size] = $2
oldie[key][:kb_used] = $3
oldie[key][:kb_available] = $4
oldie[key][:percent_used] = $5
oldie[key][:mount] = $6
# an entry starting with 'G' or / (E.G. /tmp or /var)
when /^\s*(G.*?|\/\w)/
if fields[0] == "Global"
key = fields[0] + ":" + fields[1]
else
key = fields[0]
end
oldie[key] ||= Mash.new
oldie[key][:mount] = fields[1]
oldie[key][:fs_type] = fields[2]
oldie[key][:mount_options] = fields[6].split(',')
# entries occupying the 'Node' column parsed here
else
key = fields[0] + ":" + fields[1]
oldie[key] ||= Mash.new
oldie[key][:mount] = fields[1]
oldie[key][:fs_type] = fields[3]
oldie[key][:mount_options] = fields[7].split(',')
end
end
oldie
end

# Grab mount information from /bin/mount
so = shell_out("mount")
so.stdout.lines.each do |line|
case line
when /^\s*node/
next
when /^\s*---/
next
when /^\s*\/\w/
fields = line.split
filesystem = fields[0]
fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
fs[filesystem][:mount] = fields[1]
fs[filesystem][:fs_type] = fields[2]
fs[filesystem][:mount_options] = fields[6]
else
fields = line.split
filesystem = fields[0] + ":" + fields[1]
fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
fs[filesystem][:mount] = fields[2]
fs[filesystem][:fs_type] = fields[3]
fs[filesystem][:mount_options] = fields[7]
end
def collect_old_version(shell_outs)
mount_hash = parse_df_or_mount shell_outs[:mount]
df_hash = parse_df_or_mount shell_outs[:df_Pk]

mount_hash.each do |key, hash|
df_hash[key].merge!(hash) if df_hash.has_key?(key)
end

# Set the filesystem data
filesystem fs
mount_hash.merge(df_hash)
end

collect_data(:aix) do

# Cache the command output
shell_outs = Mash.new
shell_outs[:mount] = shell_out("mount").stdout
shell_outs[:df_Pk] = shell_out("df -Pk").stdout

filesystem collect_old_version(shell_outs)
end
end
3 changes: 2 additions & 1 deletion lib/ohai/plugins/aix/kernel.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Author:: Joshua Timberman <joshua@opscode.com>
# Copyright:: Copyright (c) 2013 Opscode, Inc.
# Author:: Isa Farnik (<isa@chef.io>)
# Copyright:: Copyright (c) 2013-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
5 changes: 3 additions & 2 deletions lib/ohai/plugins/aix/memory.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Author:: Joshua Timberman <joshua@opscode.com>
# Copyright:: Copyright (c) 2013, Opscode, Inc.
# Author:: Isa Farnik (<isa@chef.io>)
# Copyright:: Copyright (c) 2013-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -27,7 +28,7 @@
total_in_mb, u, free_in_mb = meminfo.split
memory[:total] = "#{total_in_mb.to_i * 1024}kB"
memory[:free] = "#{free_in_mb.to_i * 1024}kB"

swapinfo = shell_out("swap -s").stdout.split #returns swap info in 4K blocks
memory[:swap]['total'] = "#{(swapinfo[2].to_i) * 4}kB"
memory[:swap]['free'] = "#{(swapinfo[10].to_i) * 4}kB"
Expand Down
10 changes: 6 additions & 4 deletions lib/ohai/plugins/aix/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>)
# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
# Author:: Isa Farnik (<isa@chef.io>)
# Copyright:: Copyright (c) 2015 Chef, Inc.
# Copyright:: Copyright (c) 2013-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -21,7 +21,7 @@
Ohai.plugin(:Network) do
require 'ipaddr'

provides "network", "counters/network"
provides "network", "counters/network", "macaddress"

# Helpers
def hex_to_dec_netmask(netmask)
Expand Down Expand Up @@ -115,7 +115,10 @@ def hex_to_dec_netmask(netmask)
e_so = shell_out("entstat -d #{interface} | grep \"Hardware Address\"")
iface[interface][:addresses] = Mash.new unless iface[interface][:addresses]
e_so.stdout.lines.each do |line|
iface[interface][:addresses][$1.upcase] = { "family" => "lladdr" } if line =~ /Hardware Address: (\S+)/
if line =~ /Hardware Address: (\S+)/
iface[interface][:addresses][$1.upcase] = { "family" => "lladdr" }
macaddress $1.upcase unless shell_out("uname -W").stdout.to_i > 0
end
end
end #ifconfig stdout

Expand Down Expand Up @@ -145,7 +148,6 @@ def hex_to_dec_netmask(netmask)
count += 1
end
end

network["interfaces"] = iface
end
end
Expand Down
30 changes: 30 additions & 0 deletions lib/ohai/plugins/aix/os.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
# Author:: Isa Farnik (<isa@chef.io>)
# Copyright:: Copyright (c) 2013-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'ohai/mixin/os'

Ohai.plugin(:OS) do
provides "os", "os_version"
depends 'kernel'

collect_data(:aix) do
os collect_os
os_version kernel[:version]
end
end
3 changes: 2 additions & 1 deletion lib/ohai/plugins/aix/platform.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Author:: Joshua Timberman <joshua@opscode.com>
# Copyright:: Copyright (c) 2013, Opscode, Inc.
# Author:: Isa Farnik (<isa@chef.io>)
# Copyright:: Copyright (c) 2013-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
5 changes: 3 additions & 2 deletions lib/ohai/plugins/aix/uptime.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Author:: Kurt Yoder (<ktyopscode@yoderhome.com>)
# Copyright:: Copyright (c) 2013 Opscode, Inc.
# Author:: Isa Farnik (<isa@chef.io>)
# Copyright:: Copyright (c) 2013-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -33,4 +34,4 @@
end
end
end
end
end
Loading