Class: Racadm
- Inherits:
-
Object
- Object
- Racadm
- Defined in:
- lib/puppet_x/racadm/racadm.rb
Overview
Racadm specific Utilily class
Class Method Summary collapse
- .bool_to_s(value) ⇒ Object
- .parse_jobqueue(reply) ⇒ Object
- .parse_racadm(reply) ⇒ Object
- .password_changed?(new_password, sha256, salt) ⇒ Boolean
- .racadm_call(racadm_args, cmd_args, suppress_error = false) ⇒ Object
- .role_to_s(value) ⇒ Object
- .s_to_bool(value) ⇒ Object
- .s_to_role(value) ⇒ Object
Class Method Details
.bool_to_s(value) ⇒ Object
69 70 71 |
# File 'lib/puppet_x/racadm/racadm.rb', line 69 def self.bool_to_s(value) (value.to_s == 'true') ? 'Enabled' : 'Disabled' end |
.parse_jobqueue(reply) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/puppet_x/racadm/racadm.rb', line 57 def self.parse_jobqueue(reply) parsed = {} reply.each_line do |line| if line.start_with? 'Reboot JID' parsed['reboot_id'] = line.split(' ').last elsif line.start_with? 'Commit JID' parsed['commit_id'] = line.split(' ').last end end parsed end |
.parse_racadm(reply) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/puppet_x/racadm/racadm.rb', line 29 def self.parse_racadm(reply) parsed = {} reply.each_line do |line| sub_line_array = line.split('=') if sub_line_array.length > 1 if line.start_with? '[Key=' parsed[:Key] = sub_line_array[1].strip[0..-2] elsif sub_line_array[0].end_with? '[Key' subkey = sub_line_array.slice!(0).strip.chomp(' [Key') subvalue = '[Key=' + sub_line_array.join('=').strip parsed[subkey] = subvalue elsif !sub_line_array[0].start_with? '!!' subkey = sub_line_array.slice!(0).strip.gsub(%r{\s+}, '') subvalue = sub_line_array.join('=').strip parsed[subkey] = subvalue end end end parsed end |
.password_changed?(new_password, sha256, salt) ⇒ Boolean
50 51 52 53 54 55 |
# File 'lib/puppet_x/racadm/racadm.rb', line 50 def self.password_changed?(new_password, sha256, salt) new_password_sha = Digest::SHA256.hexdigest( new_password + salt.gsub(%r{..}) { |pair| pair.hex.chr }, ).upcase !new_password_sha.eql? sha256 end |
.racadm_call(racadm_args, cmd_args, suppress_error = false) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/puppet_x/racadm/racadm.rb', line 7 def self.racadm_call(racadm_args, cmd_args, suppress_error = false) cmd = ['/opt/dell/srvadmin/bin/idracadm7'] unless racadm_args[:bmc_server_host].nil? || racadm_args[:bmc_username].nil? || racadm_args[:bmc_password].nil? cmd.push('-u').push(racadm_args[:bmc_username]) if racadm_args[:bmc_username] cmd.push('-p').push(racadm_args[:bmc_password]) if racadm_args[:bmc_password] cmd.push('-r').push(racadm_args[:bmc_server_host]) if racadm_args[:bmc_server_host] end cmd += cmd_args stdout, stderr, status = Open3.capture3(cmd.join(' ')) nr = cmd.index('-p') cmd.fill('<secret>', nr + 1, 1) unless nr.nil? # password is not logged. Puppet.debug("#{cmd.join(' ')} executed with stdout: '#{stdout}' stderr: '#{stderr}' status: '#{status}'") if !status.success? && !suppress_error raise(Puppet::Error, "#{cmd.join(' ')} failed with #{stdout}") end stdout end |
.role_to_s(value) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/puppet_x/racadm/racadm.rb', line 94 def self.role_to_s(value) case value when 'none' '0' when 'callback' '1' when 'user' '2' when 'operator' '3' when 'administrator' '4' when 'oem_proprietary' '5' when 'no_access' '15' end end |
.s_to_bool(value) ⇒ Object
73 74 75 |
# File 'lib/puppet_x/racadm/racadm.rb', line 73 def self.s_to_bool(value) 'Enabled'.eql? value end |
.s_to_role(value) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/puppet_x/racadm/racadm.rb', line 77 def self.s_to_role(value) case value when '1' 'callback' when '2' 'user' when '3' 'operator' when '4' 'administrator' when '5' 'oem_proprietary' when '15' 'no_access' end end |