Module: Windows::Exec
Constant Summary collapse
- ABS_CMD =
'c:\\\\windows\\\\system32\\\\cmd.exe'
- CMD =
'cmd.exe'
Instance Attribute Summary
Attributes included from Beaker::CommandFactory
Instance Method Summary collapse
- #echo(msg, abs = true) ⇒ Object
- #get_ip ⇒ Object
- #path ⇒ Object
-
#ping(target, attempts = 5) ⇒ Boolean
Attempt to ping the provided target hostname.
-
#prepend_commands(command = '', user_pc = nil, opts = {}) ⇒ String
Gets the specific prepend commands as needed for this host.
- #reboot ⇒ Object
-
#ssh_permit_user_environment ⇒ Result
private
Sets the PermitUserEnvironment setting & restarts the SSH service.
-
#ssh_service_restart ⇒ Result
Restarts the SSH service.
- #touch(file, abs = true) ⇒ Object
Methods included from Beaker::CommandFactory
Instance Method Details
#echo(msg, abs = true) ⇒ Object
14 15 16 |
# File 'lib/beaker/host/windows/exec.rb', line 14 def echo(msg, abs=true) (abs ? ABS_CMD : CMD) + " /c echo #{msg}" end |
#get_ip ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/beaker/host/windows/exec.rb', line 26 def get_ip ip = execute("ipconfig | grep -i 'IP Address' | cut -d: -f2 | head -1").strip if ip == '' ip = execute("ipconfig | grep -i 'IPv4 Address' | cut -d: -f2 | head -1").strip end if ip == '' ip = execute("ipconfig | grep -i 'IPv6 Address' | cut -d: -f2 | head -1").strip end ip end |
#path ⇒ Object
22 23 24 |
# File 'lib/beaker/host/windows/exec.rb', line 22 def path 'c:/windows/system32;c:/windows' end |
#ping(target, attempts = 5) ⇒ Boolean
Attempt to ping the provided target hostname
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/beaker/host/windows/exec.rb', line 41 def ping target, attempts=5 try = 0 while try < attempts do result = exec(Beaker::Command.new("ping -n 1 #{target}"), :accept_all_exit_codes => true) if result.exit_code == 0 return true end try+=1 end result.exit_code == 0 end |
#prepend_commands(command = '', user_pc = nil, opts = {}) ⇒ String
Gets the specific prepend commands as needed for this host
87 88 89 90 91 |
# File 'lib/beaker/host/windows/exec.rb', line 87 def prepend_commands(command = '', user_pc = nil, opts = {}) cygwin_prefix = (self.is_cygwin? and opts[:cmd_exe]) ? 'cmd.exe /c' : '' spacing = (user_pc && !cygwin_prefix.empty?) ? ' ' : '' "#{cygwin_prefix}#{spacing}#{user_pc}" end |
#reboot ⇒ Object
4 5 6 7 8 9 |
# File 'lib/beaker/host/windows/exec.rb', line 4 def reboot exec(Beaker::Command.new('shutdown /f /r /t 0 /d p:4:1 /c "Beaker::Host reboot command issued"'), :expect_connection_failure => true) # rebooting on windows is sloooooow # give it some breathing room before attempting a reconnect sleep(40) end |
#ssh_permit_user_environment ⇒ Result
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets the PermitUserEnvironment setting & restarts the SSH service
74 75 76 77 |
# File 'lib/beaker/host/windows/exec.rb', line 74 def ssh_permit_user_environment exec(Beaker::Command.new("echo '\nPermitUserEnvironment yes' >> /etc/sshd_config")) ssh_service_restart() end |
#ssh_service_restart ⇒ Result
Restarts the SSH service.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/beaker/host/windows/exec.rb', line 56 def ssh_service_restart command_result = nil # we get periodic failures to restart the service, so looping these with re-attempts repeat_fibonacci_style_for(5) do 0 == exec(Beaker::Command.new("cygrunsrv -E sshd"), :acceptable_exit_codes => [0, 1] ).exit_code end repeat_fibonacci_style_for(5) do command_result = exec(Beaker::Command.new("cygrunsrv -S sshd"), :acceptable_exit_codes => [0, 1] ) 0 == command_result.exit_code end command_result end |