ievms-ruby 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +84 -17
- data/bin/ievmsrb +23 -0
- data/ievms-ruby.gemspec +1 -0
- data/lib/ievms/version.rb +1 -1
- data/lib/ievms/windows_guest.rb +60 -35
- data/test/test_ievms_win7.rb +26 -2
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05be8b5a8afb70d2e593f3b8a2d760ea8e25ebd9
|
4
|
+
data.tar.gz: 6a8acce20fd1eeaeb9e141ab1285da86f4d1adf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a21fd4b8f5229eff45578a52ad4f1c281a0c9566e51f71cc30b42382b0ddf292b618a72cd4416f07194fe5fad9e875a3a7af0194ec84d439f5f860008dd02c8
|
7
|
+
data.tar.gz: a845e9089277fb1d8a773702fbf46a781f7968e822397dbdf8cc659347d35854df38cbd39d468f8eb08dbabb8856bcbd7280a28938a70049e5eadf426db7a57e
|
data/README.md
CHANGED
@@ -1,33 +1,30 @@
|
|
1
1
|
# ievms-ruby
|
2
2
|
|
3
|
-
|
4
|
-
(
|
3
|
+
[](https://badge.fury.io/rb/ievms-ruby)
|
4
|
+
[](https://codeclimate.com/github/mipmip/ievms-ruby)
|
5
|
+
[](https://gemnasium.com/mipmip/ievms-ruby)
|
6
|
+
|
7
|
+
|
8
|
+
Ruby interface for boxes made by ievms.sh. Use this Library to provision your
|
5
9
|
IE boxes from https://modern.ie.
|
6
10
|
|
11
|
+
Next ievms.sh ievms-ruby also works great in combination with iectrl.
|
12
|
+
|
7
13
|
## Requirements
|
8
14
|
|
9
15
|
* VirtualBox >= 5.0.4
|
10
16
|
* VirtualBox Extension Pack and Guest Additions >= 5.0.4
|
11
17
|
* Host Machine: OSX or Linux (only tested on OSX 10.9 & 10.10)
|
12
|
-
* Virtual Machines created by .ievms (only tested with
|
13
|
-
Win7" machine
|
18
|
+
* Virtual Machines created by .ievms (only tested with vanilla Win7 machines)
|
14
19
|
|
15
|
-
##
|
20
|
+
## Features
|
16
21
|
|
17
22
|
* Works with Windows 7
|
18
23
|
* Upload files to guest machine
|
24
|
+
* Download file from guest machine
|
19
25
|
* Execute batch file on guest machine
|
20
26
|
* Execute batch file as admin on guest machine
|
21
|
-
|
22
|
-
## TODO 0.1
|
23
|
-
|
24
|
-
* upload files as admin to guest machine
|
25
|
-
* more IE platforms
|
26
|
-
* more Win platforms
|
27
|
-
* Use as CLI
|
28
|
-
* Documentation
|
29
|
-
* provisioning example
|
30
|
-
* Rubycop
|
27
|
+
* Cat file guest machine from cli
|
31
28
|
|
32
29
|
## Installation
|
33
30
|
|
@@ -43,11 +40,81 @@ Or install it yourself as:
|
|
43
40
|
$ gem install ievms-ruby
|
44
41
|
|
45
42
|
## Usage
|
46
|
-
Here's an example provising script using the Gem:
|
47
43
|
|
44
|
+
### From CLI
|
45
|
+
After gem install you can call:
|
46
|
+
|
47
|
+
```bash
|
48
|
+
ievmsrb help
|
49
|
+
```
|
50
|
+
|
51
|
+
to cat a guest file:
|
52
|
+
|
53
|
+
```bash
|
54
|
+
ievmsrb cat "IE9 - Win7" 'C:\Windows\System32\Drivers\Etc\hosts'
|
55
|
+
```
|
56
|
+
|
57
|
+
### As library
|
58
|
+
Ievms-ruby very usable as provision tool for windows. E.g. for CI. Here's an example
|
59
|
+
provisioning script using the Gem:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
#!/usr/bin/env ruby
|
63
|
+
require 'rubygems'
|
64
|
+
require 'bundler/setup'
|
65
|
+
require 'ievms/windows_guest'
|
66
|
+
|
67
|
+
class ProvisionIE
|
68
|
+
|
69
|
+
# Create interface for the 'IE9 - Win7' virtual box
|
70
|
+
def init
|
71
|
+
@machine = Ievms::WindowsGuest.new 'IE9 - Win7'
|
72
|
+
end
|
73
|
+
|
74
|
+
# Install the choco package manager (APT for Windows)
|
75
|
+
def install_chocolatey
|
76
|
+
print "Installing Chocolatey\n"
|
77
|
+
choco_install_cmd = '@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString(\'https://chocolatey.org/install.ps1\'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin '
|
78
|
+
@machine.run_command_as_admin(choco_install_cmd)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Install ruby and git stuff, the reason why we wrote ievms-ruby
|
82
|
+
def install_ruby_and_git
|
83
|
+
%w( ruby msysgit ).each do |pkg|
|
84
|
+
@machine.run_command_as_admin "c:\\ProgramData\\chocolatey\\bin\\choco install -y #{pkg}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
provision = ProvisionIE.new
|
90
|
+
provision.init
|
91
|
+
provision.install_chocolatey
|
92
|
+
provision.install_ruby_and_git
|
48
93
|
```
|
49
|
-
|
94
|
+
|
95
|
+
## TODO 0.1.x first loud release
|
96
|
+
|
97
|
+
* Upload files as admin to guest machine
|
98
|
+
* Test More Win platforms
|
99
|
+
* Execution time out for exec
|
100
|
+
* Rubocop refactoring
|
101
|
+
|
102
|
+
## Testing
|
103
|
+
|
104
|
+
To run the tests you need top fullfil the testing requirements first:
|
105
|
+
|
106
|
+
* VirtualBox >= 5.0.4
|
107
|
+
* "IE9 - Win7" installed by ievms.sh
|
108
|
+
* Create an new virtual machine called `standbymachine`. Keep the disk size as
|
109
|
+
small as possible. It should be turned off.
|
110
|
+
|
50
111
|
```
|
112
|
+
git clone https://github.com/mipmip/ievms-ruby.git
|
113
|
+
cd ievms-ruby
|
114
|
+
bundle install
|
115
|
+
rake
|
116
|
+
```
|
117
|
+
|
51
118
|
|
52
119
|
## Contributing
|
53
120
|
|
data/bin/ievmsrb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'ievms/windows_guest'
|
4
|
+
require 'thor'
|
5
|
+
|
6
|
+
class IevmsRb < Thor
|
7
|
+
|
8
|
+
desc "cat [vbox name] [filename]", "cat file in VBox guest"
|
9
|
+
def cat(vbox_name,guest_path)
|
10
|
+
init vbox_name
|
11
|
+
|
12
|
+
print @machine.download_string_from_file_to_guest guest_path, true
|
13
|
+
print "\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def init vbox_name
|
19
|
+
@machine = Ievms::WindowsGuest.new vbox_name
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
IevmsRb.start(ARGV)
|
data/ievms-ruby.gemspec
CHANGED
data/lib/ievms/version.rb
CHANGED
data/lib/ievms/windows_guest.rb
CHANGED
@@ -4,14 +4,14 @@ require 'fileutils'
|
|
4
4
|
require 'tempfile'
|
5
5
|
|
6
6
|
# VM admin username
|
7
|
-
USERNAME='IEUser'
|
7
|
+
USERNAME = 'IEUser'
|
8
8
|
# VM admin user password
|
9
|
-
PASSWD='Passw0rd!'
|
9
|
+
PASSWD = 'Passw0rd!'
|
10
10
|
|
11
11
|
# IEVMS directory
|
12
12
|
IEVMS_HOME = ENV['HOME']+'/.ievms'
|
13
13
|
|
14
|
-
|
14
|
+
# ievms interface
|
15
15
|
module Ievms
|
16
16
|
class WindowsGuest
|
17
17
|
attr_accessor :verbose
|
@@ -25,79 +25,104 @@ module Ievms
|
|
25
25
|
end
|
26
26
|
|
27
27
|
# Copy a file to the virtual machine from the ievms home folder.
|
28
|
-
def copy_to_vm
|
29
|
-
print "Copying #{src} to #{dest}\n"
|
28
|
+
def copy_to_vm(src ,dest, quiet=false)
|
29
|
+
print "Copying #{src} to #{dest}\n" unless quiet
|
30
30
|
guestcontrol_exec "cmd.exe", "cmd.exe /c copy \"E:\\#{src}\" \"#{dest}\""
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
# Copy a file to the virtual machine from the ievms home folder.
|
34
|
+
def copy_from_vm(src ,dest, quiet=false)
|
35
|
+
print "Copying #{src} to #{dest}\n" unless quiet
|
36
|
+
guestcontrol_exec "cmd.exe", "cmd.exe /c copy \"#{src}\" \"E:\\#{dest}\""
|
37
|
+
end
|
34
38
|
|
35
|
-
|
36
|
-
FileUtils.cp local_path, File.join(IEVMS_HOME,File.basename(local_path))
|
39
|
+
def download_file_from_guest(guest_path, local_path, quiet=false)
|
37
40
|
|
38
|
-
#
|
39
|
-
|
41
|
+
# 1 run cp command in machine
|
42
|
+
copy_from_vm guest_path, File.basename(local_path), quiet
|
43
|
+
|
44
|
+
# 2 copy to tmp location in .ievms
|
45
|
+
FileUtils.cp File.join(IEVMS_HOME,File.basename(local_path)), local_path
|
40
46
|
|
41
47
|
# 3 remove tmp file in .ievms
|
42
48
|
FileUtils.rm File.join(IEVMS_HOME,File.basename(local_path))
|
43
49
|
end
|
44
50
|
|
45
|
-
#
|
46
|
-
def
|
47
|
-
print "Executing batch file as administrator: #{guest_path}\n"
|
51
|
+
# Upload a local file to the windows guest
|
52
|
+
def upload_file_to_guest(local_path, guest_path, quiet=false)
|
48
53
|
|
49
|
-
|
50
|
-
|
54
|
+
# 1 copy to tmp location in .ievms
|
55
|
+
FileUtils.cp local_path, File.join(IEVMS_HOME,File.basename(local_path))
|
56
|
+
|
57
|
+
# 2 run cp command in machine
|
58
|
+
copy_to_vm File.basename(local_path), guest_path, quiet
|
51
59
|
|
60
|
+
# 3 remove tmp file in .ievms
|
61
|
+
FileUtils.rm File.join(IEVMS_HOME,File.basename(local_path))
|
52
62
|
end
|
53
63
|
|
54
|
-
|
55
|
-
|
56
|
-
|
64
|
+
def download_string_from_file_to_guest( guest_path, quiet=false)
|
65
|
+
copy_from_vm guest_path, 'tmpfile.txt', quiet
|
66
|
+
string = IO.read(File.join(IEVMS_HOME,'tmpfile.txt'))
|
67
|
+
FileUtils.rm File.join(IEVMS_HOME,'tmpfile.txt')
|
68
|
+
string
|
69
|
+
end
|
57
70
|
|
58
|
-
|
71
|
+
def upload_string_as_file_to_guest(string, guest_path, quiet=false)
|
59
72
|
|
60
|
-
|
61
|
-
tmp
|
62
|
-
tmp.write "#{command}\n"
|
73
|
+
tmp = Tempfile.new('txtfile')
|
74
|
+
tmp.write "#{string}\n"
|
63
75
|
path = tmp.path
|
64
76
|
tmp.rewind
|
65
77
|
tmp.close
|
66
|
-
|
78
|
+
|
79
|
+
upload_file_to_guest(path, guest_path, true)
|
67
80
|
FileUtils.rm path
|
81
|
+
end
|
82
|
+
|
83
|
+
# execute existibg batch file in Windows guest as Administrator
|
84
|
+
def run_command_as_admin(command,quiet=false)
|
85
|
+
print "Executing command as administrator: #{command}\n" unless quiet
|
86
|
+
|
87
|
+
run_command 'if exist C:\Users\IEUser\ievms.bat del C:\Users\IEUser\ievms.bat && Exit', true
|
88
|
+
|
89
|
+
upload_string_as_file_to_guest(command, 'C:\Users\IEUser\ievms.bat', true)
|
68
90
|
|
69
91
|
guestcontrol_exec "schtasks.exe", "schtasks.exe /run /tn ievms"
|
70
92
|
|
93
|
+
while schtasks_query_ievms.include? 'Running'
|
94
|
+
print "."
|
95
|
+
sleep 2
|
96
|
+
end
|
97
|
+
print "\n"
|
71
98
|
end
|
72
99
|
|
73
100
|
# execute existing batch file in Windows guest
|
74
|
-
def run_command
|
75
|
-
print "Executing command: #{command}\n"
|
101
|
+
def run_command(command, quiet=false)
|
102
|
+
print "Executing command: #{command}\n" unless quiet
|
76
103
|
out, _, _ = guestcontrol_exec "cmd.exe", "cmd.exe /c \"#{command}\""
|
77
|
-
|
104
|
+
out
|
78
105
|
end
|
79
106
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
out, _, _ = guestcontrol_exec "cmd.exe", "cmd.exe /c \"#{guest_path}\""
|
84
|
-
return out
|
107
|
+
def schtasks_query_ievms
|
108
|
+
out, _, _ = guestcontrol_exec "schtasks.exe", "schtasks.exe /query /tn ievms"
|
109
|
+
out
|
85
110
|
end
|
86
111
|
|
87
112
|
private
|
88
113
|
|
89
114
|
# execute final guest control shell cmd
|
90
115
|
# returns [stdout,stderr,status] from capture3
|
91
|
-
def guestcontrol_exec
|
116
|
+
def guestcontrol_exec(image, cmd)
|
92
117
|
wait_for_guestcontrol(@vbox_name)
|
93
118
|
cmd = "VBoxManage guestcontrol \"#{@vbox_name}\" run --username \"#{USERNAME}\" --password '#{PASSWD}' --exe \"#{image}\" -- #{cmd}"
|
94
|
-
|
119
|
+
# print cmd + "\n"
|
95
120
|
return Open3.capture3(cmd)
|
96
121
|
end
|
97
122
|
|
98
123
|
# function taken from ievms
|
99
124
|
# Pause execution until guest control is available for a virtual machine
|
100
|
-
def wait_for_guestcontrol
|
125
|
+
def wait_for_guestcontrol(vboxname)
|
101
126
|
run_level = 0
|
102
127
|
while run_level < 3 do
|
103
128
|
print "Waiting for #{vboxname} to be available for guestcontrol...\n" if @verbose
|
@@ -110,7 +135,7 @@ module Ievms
|
|
110
135
|
end
|
111
136
|
|
112
137
|
# Is it a virtual machine in VirtualBox?
|
113
|
-
def is_vm
|
138
|
+
def is_vm(vboxname)
|
114
139
|
cmd = "VBoxManage showvminfo \"#{vboxname}\""
|
115
140
|
|
116
141
|
_, stderr, _ = Open3.capture3(cmd)
|
data/test/test_ievms_win7.rb
CHANGED
@@ -25,13 +25,36 @@ class TestWin7 < Minitest::Test
|
|
25
25
|
|
26
26
|
end
|
27
27
|
|
28
|
+
def test_long_admin_cmd
|
29
|
+
@machine.run_command_as_admin 'ping 127.0.0.1 -n 6 > nul'
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_upload_string_as_file
|
33
|
+
@machine.run_command 'if exist C:\Users\IEUser\testfile.txt del C:\Users\IEUser\testfile.txt && Exit'
|
34
|
+
|
35
|
+
content = <<eos
|
36
|
+
String is uploaded with ievms-ruby
|
37
|
+
|
38
|
+
ohhh yeah....
|
39
|
+
eos
|
40
|
+
@machine.upload_string_as_file_to_guest(content, 'C:\Users\IEUser\testfile.txt')
|
41
|
+
assert_equal true, @machine.download_string_from_file_to_guest('C:\Users\IEUser\testfile.txt').include?('ohhh yeah')
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_download_file_from_guest
|
45
|
+
FileUtils.rm '/tmp/testdlfile.txt' if File.exists? '/tmp/testdlfile.txt'
|
46
|
+
@machine.download_file_from_guest('C:\ievms.xml', '/tmp/testdlfile.txt')
|
47
|
+
assert_equal true, File.exists?('/tmp/testdlfile.txt')
|
48
|
+
end
|
49
|
+
|
28
50
|
def test_execute_batch_file
|
29
51
|
|
30
52
|
@machine.run_command 'if exist C:\Users\IEUser\test.bat del C:\Users\IEUser\test.bat && Exit'
|
31
53
|
@machine.run_command 'if exist C:\Users\IEUser\EmptyFile.txt del C:\Users\IEUser\EmptyFile.txt && Exit'
|
32
54
|
|
33
55
|
@machine.upload_file_to_guest(File.join(File.dirname(__FILE__), '_test.bat'), 'C:\Users\IEUser\test.bat')
|
34
|
-
@machine.
|
56
|
+
@machine.run_command('C:\Users\IEUser\test.bat')
|
57
|
+
#@machine.run_bat('C:\Users\IEUser\test.bat')
|
35
58
|
output_file_exists = @machine.run_command 'if exist C:\Users\IEUser\EmptyFile.txt echo EmptyFileExist && Exit'
|
36
59
|
|
37
60
|
assert_equal true, output_file_exists.include?('EmptyFileExist')
|
@@ -48,7 +71,8 @@ class TestWin7 < Minitest::Test
|
|
48
71
|
@machine.run_command_as_admin 'if exist C:\EmptyFile2.txt del C:\EmptyFile2.txt && Exit'
|
49
72
|
|
50
73
|
@machine.upload_file_to_guest(File.join(File.dirname(__FILE__), '_test_as_admin.bat'), 'C:\Users\IEUser\test_as_admin.bat')
|
51
|
-
@machine.
|
74
|
+
@machine.run_command_as_admin('C:\Users\IEUser\test_as_admin.bat')
|
75
|
+
# @machine.run_bat_as_admin('C:\Users\IEUser\test_as_admin.bat')
|
52
76
|
output_file_exists = @machine.run_command 'if exist C:\EmptyFile2.txt echo EmptyFile2Exist && Exit'
|
53
77
|
|
54
78
|
assert_equal true, output_file_exists.include?('EmptyFile2Exist')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ievms-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pim Snel
|
@@ -66,10 +66,25 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '5.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: thor
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.19'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.19'
|
69
83
|
description: Ruby interface for boxes made by ievms.sh (http://xdissent.github.com/ievms)
|
70
84
|
email:
|
71
85
|
- pim@lingewoud.nl
|
72
|
-
executables:
|
86
|
+
executables:
|
87
|
+
- ievmsrb
|
73
88
|
extensions: []
|
74
89
|
extra_rdoc_files: []
|
75
90
|
files:
|
@@ -78,6 +93,7 @@ files:
|
|
78
93
|
- LICENSE.txt
|
79
94
|
- README.md
|
80
95
|
- Rakefile
|
96
|
+
- bin/ievmsrb
|
81
97
|
- ievms-ruby.gemspec
|
82
98
|
- lib/ievms/version.rb
|
83
99
|
- lib/ievms/windows_guest.rb
|