Class: HmcDir
- Inherits:
-
Object
- Object
- HmcDir
- Defined in:
- lib/Framework/hmcDir.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#sys ⇒ Object
readonly
Returns the value of attribute sys.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
- #create_list_of_frames ⇒ Object
- #file_content(frame, type) ⇒ Object
- #file_exist?(file_type, filename) ⇒ Boolean
-
#initialize(dir) ⇒ HmcDir
constructor
A new instance of HmcDir.
- #lpar_hash(sys_name, lpar_id) ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(dir) ⇒ HmcDir
Returns a new instance of HmcDir.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/Framework/hmcDir.rb', line 12 def initialize(dir) @errors = [] @warnings = [] @verbose = 0 @sys = [] @dir = dir @hmc_dir_map = { 'frame_list' => 'lssysscfg_r_frame_F_name_serial_num_state.txt', 'sys_list' => 'lssyscfg_r_sys_F_name_serial_num_state.txt', 'lssysconn' => 'lssysconn_r_all.txt', 'ldap' => 'ldap.txt', 'lssvcevents_hardware' => 'lssvcevents_hardware.txt', 'resurceroles' => 'resourceroles.txt' } @frame_files_map = { 'frame_memory' => '_mem.txt', 'frame_proc' => '_proc.txt', } @frame_lpar_map = { 'lpar_info' => '_lpar_real.txt', 'io_slot' => '_io_slot.txt', 'memory' => '_mem_lpar.txt', 'proc' => '_proc_lpar.txt', 'virtual_eth' => '_virtual_eth.txt', 'virtual_fc' => '_virtual_fc.txt', 'virtual_scsi' => '_virtual_scsi.txt', 'virtual_serial' => '_virtual_serial.txt', 'virtual_slot' => '_virtual_slot.txt', 'prof' => '_prof.txt', } end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/Framework/hmcDir.rb', line 6 def errors @errors end |
#sys ⇒ Object (readonly)
Returns the value of attribute sys.
10 11 12 |
# File 'lib/Framework/hmcDir.rb', line 10 def sys @sys end |
#verbose ⇒ Object
Returns the value of attribute verbose.
8 9 10 |
# File 'lib/Framework/hmcDir.rb', line 8 def verbose @verbose end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
7 8 9 |
# File 'lib/Framework/hmcDir.rb', line 7 def warnings @warnings end |
Instance Method Details
#create_list_of_frames ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/Framework/hmcDir.rb', line 88 def create_list_of_frames filename = @dir + '/' + @hmc_dir_map['sys_list'] unless File.exist?(filename) raise Exception, "Missing file with list of frames (#{filename}" end unless File.readable?(filename) raise Exception, "Missing or not readable file with list of frames (#{filename}" end File.read(@dir + '/' + @hmc_dir_map['sys_list']).split("\n").each do |string| sys = Sys.new sys.parse_f(string, 'name,serial_num,state') @sys.push(sys.name) end @sys.uniq! end |
#file_content(frame, type) ⇒ Object
118 119 120 |
# File 'lib/Framework/hmcDir.rb', line 118 def file_content(frame, type) File.read(@dir + '/' + frame + @frame_lpar_map[type]) end |
#file_exist?(file_type, filename) ⇒ Boolean
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/Framework/hmcDir.rb', line 107 def file_exist?(file_type, filename) if File.exist?(filename) puts "checking #{file_type}: #{filename} exist [OK]" if @verbose > 0 else @errors.push("File >#{filename}< doesn't exist!") puts "checking #{file_type}: #{filename} doesn't exist! [Error]" if @verbose > 0 return false end true end |
#lpar_hash(sys_name, lpar_id) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/Framework/hmcDir.rb', line 122 def lpar_hash(sys_name, lpar_id) result = {} @frame_lpar_map.each_pair do |file_type,filename| next unless File.readable?(@dir + '/' + sys_name + filename) file = File.new(@dir + '/' + sys_name + filename, 'r') while (line = file.gets) hmc_data = HmcString.parse(line) if hmc_data['lpar_id'] == lpar_id.to_s result[file_type].nil? ? result[file_type] = line : result[file_type] += line end end end result end |
#validate ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/Framework/hmcDir.rb', line 47 def validate errors = 0 puts "Checking HMC directory #{@dir}" if @verbose > 0 puts 'HMC files:' if @verbose > 0 if File.directory?(@dir) puts "checking if directory #{@dir} exist [OK]" if @verbose > 0 else @errors.push("The directory #{@dir} doesn't exist!") return false end if File.exist?(@dir + '/' + @hmc_dir_map['sys_list']) puts "checking if list of systems exist #{@dir + '/' + @hmc_dir_map['sys_list']} exist [OK]" if @verbose > 0 else @errors.push("File with list of systems >#{@dir}/#{@hmc_dir_map['sys_list']}< doesn't exist!") return false end @hmc_dir_map.each_pair do |file_type,filename| errors += 1 unless file_exist?(file_type, @dir + '/' + filename) end create_list_of_frames @sys.each do |sys_name| puts "Frame: #{sys_name}" if @verbose > 0 @frame_files_map.each_pair do |file_type,filename| errors += 1 unless file_exist?(file_type, @dir + '/' + sys_name + filename) end @frame_lpar_map.each_pair do |file_type,filename| errors += 1 unless file_exist?(file_type, @dir + '/' + sys_name + filename) end end return false if errors > 0 true end |