Skip to content

Instantly share code, notes, and snippets.

@lukebigum
Created May 24, 2018 07:54
Show Gist options
  • Save lukebigum/da7183246ed02495c18cf0f26b0a0236 to your computer and use it in GitHub Desktop.
Save lukebigum/da7183246ed02495c18cf0f26b0a0236 to your computer and use it in GitHub Desktop.
def process_zpool_data(pool_array)
if pool_array == []
return Hash.new(:absent)
end
#get the name and get rid of it
pool = Hash.new
pool[:pool] = pool_array[0]
pool_array.shift
tmp = []
#order matters here :(
pool_array.reverse_each do |value|
sym = nil
case value
when "spares";
sym = :spare
when "logs";
sym = :log
when /^mirror|^raidz1|^raidz2/;
sym = value =~ /^mirror/ ? :mirror : :raidz
pool[:raid_parity] = "raidz2" if value =~ /^raidz2/
else
#handle cases where we strip off the partition number/name from various /dev/...
#full paths.
if /(\/dev\/[a-z]{3}(1))$/ =~ value
tmp << value.chomp($2)
elsif /(\/dev\/disk\/by-id\/.+)-part1/ =~ value
tmp << $1
else
tmp << value
end
sym = :disk if value == pool_array.first
end
if sym
pool[sym] = pool[sym] ? pool[sym].unshift(tmp.reverse.join(' ')) : [tmp.reverse.join(' ')]
tmp.clear
end
end
pool
end
def get_pool_data
# https://docs.oracle.com/cd/E19082-01/817-2271/gbcve/index.html
# we could also use zpool iostat -v mypool for a (little bit) cleaner output
out = execute("zpool status -P #{@resource[:pool]}", :failonfail => false, :combine => false)
zpool_data = out.lines.select { |line| line.index("\t") == 0 }.collect { |l| l.strip.split("\s")[0] }
zpool_data.shift
zpool_data
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment