class Kitchen::Driver::Wpar
@author Alain Dejoux <adejoux@djouxtech.net> noinspection RubyDefParenthesesInspection,SpellCheckingInspection
Public Instance Methods
create(state)
click to toggle source
# File lib/kitchen/driver/wpar.rb, line 56 def create(state) if wpar_exists?(state) raise ActionFailed, 'wpar already exists !' end cmd = build_mkwpar_command() ssh_command(cmd, :stderr) unless wpar_exists?(state) raise ActionFailed, 'Cannot create wpar !' end state[:hostname]= config[:wpar_address] || config[:wpar_name] copy_key() # Ensure sshd is a defined service and is running so that # kitchen can connect to the host and do work. unless sshd_service_exists? create_sshd_service end unless sshd_service_running? start_sshd_service end unless pam_supports_sshd? configure_pam end end
destroy(state)
click to toggle source
section to destroy wpar
# File lib/kitchen/driver/wpar.rb, line 86 def destroy(state) ssh_command("#{config[:rmwpar]} -F #{config[:wpar_name]}", :stderr) if wpar_exists?(state) raise ActionFailed, "couldn't destroy wpar !" end end
Protected Instance Methods
build_mkwpar_command()
click to toggle source
# File lib/kitchen/driver/wpar.rb, line 94 def build_mkwpar_command() cmd = "#{config[:sudo]} #{config[:mkwpar]} -s -n #{config[:wpar_name]}" unless config[:wpar_address].nil? cmd += " -N address=#{config[:wpar_address]}" end if config[:share_network_resolution] cmd += " -r" end unless config[:wpar_vg].nil? cmd += " -g #{config[:wpar_vg]}" end unless config[:wpar_rootvg].nil? cmd += " -D rootvg=yes devname=#{config[:wpar_rootvg]}" end unless config[:wpar_mksysb].nil? if config[:isVersioned] cmd += " -C" end cmd += " -B #{config[:wpar_mksysb]}" end if config[:wpar_copy_rootvg] cmd += ' -t' end if config[:isWritable] cmd += ' -l' end cmd end
configure_pam()
click to toggle source
Configures PAM support for sshd in the WPAR.
# File lib/kitchen/driver/wpar.rb, line 206 def configure_pam pam_config_path = "/wpars/#{config[:wpar_name]}/etc/pam.conf" pam_sshd_rules = "#{config[:pam_sshd_account_rule]}\\n#{config[:pam_sshd_session_rule]}" header = "\\n\\n# sshd Rules\\n" cmd = "#{config[:sudo]} #{config[:echo]} \"#{header}#{pam_sshd_rules}\" >> #{pam_config_path}" ssh_command(cmd, :stderr) end
copy_key()
click to toggle source
# File lib/kitchen/driver/wpar.rb, line 132 def copy_key() cmd = "#{config[:sudo]} mkdir /wpars/#{config[:wpar_name]}/.ssh;" cmd += "#{config[:sudo]} chmod 700 /wpars/#{config[:wpar_name]}/.ssh" ssh_command(cmd, :stderr) cmd="#{config[:sudo]} cp ~/.ssh/authorized_keys /wpars/#{config[:wpar_name]}/.ssh" ssh_command(cmd, :stderr) end
create_sshd_service()
click to toggle source
Creates an sshd service.
# File lib/kitchen/driver/wpar.rb, line 159 def create_sshd_service # FIXME: We should probably check exit status rather than AIX-specific error codes. output=ssh_command("#{config[:sudo]} #{config[:clogin]} #{config[:wpar_name]} #{config[:mkssys]} -s sshd -p /usr/sbin/sshd -a '-D' -u 0 -S -n 15 -f 9 -R -G local", :stderr) if output.include?('0513-071') # 0513-071 The sshd Subsystem has been added. return true end false end
pam_supports_sshd?()
click to toggle source
Determines if PAM support for sshd exists in this WPAR. This includes account and session rules.
# File lib/kitchen/driver/wpar.rb, line 190 def pam_supports_sshd? pam_config_path = "/wpars/#{config[:wpar_name]}/etc/pam.conf" account_output=ssh_command("#{config[:sudo]} grep '#{config[:pam_sshd_account_rule]}' #{pam_config_path}", :stderr) session_output=ssh_command("#{config[:sudo]} grep '#{config[:pam_sshd_session_rule]}' #{pam_config_path}", :stderr) unless account_output.include?("#{config[:pam_sshd_account_rule]}") return false end unless session_output.include?("#{config[:pam_sshd_session_rule]}") return false end true end
ssh_command(cmd, stream)
click to toggle source
# File lib/kitchen/driver/wpar.rb, line 214 def ssh_command(cmd, stream) out = '' begin host = config[:aix_host] user = config[:aix_user] keys = config[:aix_key] Net::SSH.start(host, user, :keys => keys) do |ssh| ssh.exec!(cmd) do |channel, stream, data| out << data if stream == stream print data end out end rescue raise ActionFailed, 'ssh command failed !' end end
sshd_service_exists?()
click to toggle source
Determines if the sshd service is defined in the WPAR.
# File lib/kitchen/driver/wpar.rb, line 149 def sshd_service_exists? # FIXME: We should probably check exit status rather than AIX-specific error codes. output=ssh_command("#{config[:sudo]} #{config[:clogin]} #{config[:wpar_name]} #{config[:lssrc]} -s sshd", :stderr) if output.include?('0513-085') # 0513-085 The sshd Subsystem is not on file. return false end true end
sshd_service_running?()
click to toggle source
Determines if the sshd service is running.
# File lib/kitchen/driver/wpar.rb, line 169 def sshd_service_running? # FIXME: We should probably check exit status rather than AIX-specific error codes. output=ssh_command("#{config[:sudo]} #{config[:clogin]} #{config[:wpar_name]} #{config[:lssrc]} -s sshd", :stderr) if output.include?('active') return true end false # Status == inoperative end
start_sshd_service()
click to toggle source
Starts the sshd service.
# File lib/kitchen/driver/wpar.rb, line 179 def start_sshd_service # FIXME: We should probably check exit status rather than AIX-specific error codes. output=ssh_command("#{config[:sudo]} #{config[:clogin]} #{config[:wpar_name]} #{config[:startsrc]} -s sshd", :stderr) if output.include?('0513-059') # 0513-059 The sshd Subsystem has been started. Subsystem PID is 2688212. return true end false end
wpar_exists?(state)
click to toggle source
# File lib/kitchen/driver/wpar.rb, line 140 def wpar_exists?(state) output=ssh_command("#{config[:sudo]} #{config[:lswpar]} #{config[:wpar_name]}", :stderr) if output.include?('0960-419') return false end true end