File: swift-device-uuids.rb

package info (click to toggle)
puppet-module-swift 25.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,400 kB
  • sloc: ruby: 9,593; python: 38; sh: 10; makefile: 10
file content (26 lines) | stat: -rw-r--r-- 722 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# module_name/lib/facter/swift_device_uuids
require 'open3'
Facter.add(:swift_device_uuids) do
  setcode do
    if Dir.exists?('/dev/disk/oci-sort')
      dir_for_list = '/dev/disk/oci-sort/'
    else
      dir_for_list = '/dev/'
    end

    myhash = {}

    Dir[dir_for_list + '[vs]d*'].map { |f|
      devname = File.basename(f)
      devpath = File.realpath(f)
      cmd = "blkid  " + devpath + '| grep xfs | sed \'s/.*[ ]UUID=\"\([^\"]*\)[a-zA-Z|0-9|\-]*\".*/\1/p\' | head -n 1'
      output, exit_code = Open3.capture2(cmd)
      outputclean = output.gsub( /\n/m, "" )
      unless output.to_s.strip.empty?
        c = { devname => outputclean }
        myhash = myhash.merge(c)
      end
    }
    myhash
  end
end