File: swift_df_report.rb

package info (click to toggle)
openstack-cluster-installer 43.0.22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,544 kB
  • sloc: php: 19,169; sh: 18,137; ruby: 75; makefile: 31; xml: 8
file content (29 lines) | stat: -rw-r--r-- 6,668 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
27
28
29
# module_name/lib/facter/swift_df_report                                                                                                                                                                                                     
require 'open3'                                                                                                                                                                                                                              
Facter.add(:swift_df_report) 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?                                                                                                                                                                                                        
        cmd = "df  " + devpath + "| tail -n1 | awk '{print $4}'"                                                                                                                                                                             
        output, exit_code = Open3.capture2(cmd)                                                                                                                                                                                              
        outputclean = output.gsub( /\n/m, "" )                                                                                                                                                                                               
        c = { devname => outputclean }                                                                                                                                                                                                       
        myhash = myhash.merge(c)                                                                                                                                                                                                             
      end                                                                                                                                                                                                                                    
    }                                                                                                                                                                                                                                        
    myhash                                                                                                                                                                                                                                   
  end                                                                                                                                                                                                                                        
end