lab 0.1.1 → 0.1.5
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.
- data/lab.gemspec +11 -3
- data/lib/lab/driver/remote_workstation_driver.rb +1 -2
- data/lib/lab/driver/vm_driver.rb +38 -16
- data/lib/lab/driver/workstation_driver.rb +80 -34
- data/lib/lab/version.rb +1 -1
- data/lib/lab/vm.rb +6 -6
- metadata +19 -8
data/lab.gemspec
CHANGED
@@ -21,7 +21,15 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
# specify any dependencies here; for example:
|
23
23
|
# s.add_development_dependency "rspec"
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
|
25
|
+
# ??
|
26
|
+
s.add_runtime_dependency "nokogiri"
|
27
|
+
|
28
|
+
# Multiple things - fallback execute / copy
|
29
|
+
s.add_runtime_dependency "net-ssh"
|
30
|
+
s.add_runtime_dependency "net-scp"
|
31
|
+
|
32
|
+
# Vmware ESX driver
|
33
|
+
s.add_runtime_dependency "rbvmomi"
|
34
|
+
|
27
35
|
end
|
@@ -125,11 +125,10 @@ class RemoteWorkstationDriver < VmDriver
|
|
125
125
|
system_command(remote_copy_command)
|
126
126
|
|
127
127
|
if @tools
|
128
|
-
|
129
128
|
remote_system_command("ssh #{@user}@#{@host} \"vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
|
130
129
|
"copyFileFromGuestToHost \'#{@location}\' \'#{from}\' \'#{to}\' nogui")
|
131
130
|
else
|
132
|
-
|
131
|
+
scp_from(to,from)
|
133
132
|
end
|
134
133
|
end
|
135
134
|
|
data/lib/lab/driver/vm_driver.rb
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
#
|
6
6
|
# !!WARNING!! - All drivers are expected to filter input before running
|
7
7
|
# anything based on it. This is particularly important in the case
|
8
|
-
# of the drivers which wrap a command line to provide functionality.
|
8
|
+
# of the drivers which wrap a command line to provide functionality.
|
9
9
|
#
|
10
10
|
|
11
11
|
module Lab
|
12
12
|
module Drivers
|
13
13
|
class VmDriver
|
14
|
-
|
14
|
+
|
15
15
|
attr_accessor :vmid
|
16
16
|
attr_accessor :location
|
17
17
|
attr_accessor :os
|
@@ -19,11 +19,12 @@ class VmDriver
|
|
19
19
|
attr_accessor :credentials
|
20
20
|
|
21
21
|
def initialize(config)
|
22
|
-
|
22
|
+
|
23
23
|
@vmid = filter_command(config["vmid"].to_s)
|
24
24
|
@location = filter_command(config["location"])
|
25
25
|
@credentials = config["credentials"] || []
|
26
26
|
@tools = filter_input(config["tools"])
|
27
|
+
@arch = filter_input(config["arch"])
|
27
28
|
@os = filter_input(config["os"])
|
28
29
|
@hostname = filter_input(config["hostname"]) || filter_input(config["vmid"].to_s)
|
29
30
|
|
@@ -125,24 +126,47 @@ private
|
|
125
126
|
end
|
126
127
|
|
127
128
|
def scp_to(local,remote)
|
128
|
-
|
129
|
-
|
130
|
-
|
129
|
+
if @vm_keyfile
|
130
|
+
#puts "DEBUG: authenticating to #{@hostname} as #{@vm_user} with key #{@vm_keyfile}"
|
131
|
+
Net::SCP.start(@hostname, @vm_user, :keys => [@vm_keyfile]) do |scp|
|
132
|
+
puts "DEBUG: uploading #{local} to #{remote}"
|
133
|
+
scp.upload!(local,remote)
|
134
|
+
end
|
135
|
+
else
|
136
|
+
Net::SCP.start(@hostname, @vm_user, :password => @vm_pass, :auth_methods => ["password"]) do |scp|
|
137
|
+
puts "DEBUG: uploading #{local} to #{remote}"
|
138
|
+
scp.upload!(local,remote)
|
139
|
+
end
|
131
140
|
end
|
132
141
|
end
|
133
142
|
|
134
|
-
def scp_from(local
|
143
|
+
def scp_from(remote, local)
|
135
144
|
# download a file from a remote server
|
136
|
-
|
137
|
-
|
138
|
-
|
145
|
+
if @vm_keyfile
|
146
|
+
#puts "DEBUG: authenticating to #{@hostname} as #{@vm_user} with key #{@vm_keyfile}"
|
147
|
+
Net::SCP.start(@hostname, @vm_user, :keys => [@vm_keyfile]) do |scp|
|
148
|
+
puts "DEBUG: downloading #{remote} to #{local}"
|
149
|
+
scp.download!(remote,local)
|
150
|
+
end
|
151
|
+
else
|
152
|
+
Net::SCP.start(@hostname, @vm_user, :password => @vm_pass, :auth_methods => ["password"]) do |scp|
|
153
|
+
puts "DEBUG: downloading #{remote} to #{local}"
|
154
|
+
scp.download!(remote,local)
|
155
|
+
end
|
139
156
|
end
|
140
157
|
end
|
141
158
|
|
142
159
|
def ssh_exec(command)
|
143
|
-
|
144
|
-
|
145
|
-
|
160
|
+
if @vm_keyfile
|
161
|
+
#puts "DEBUG: authenticating to #{@hostname} as #{@vm_user} with key #{@vm_keyfile}"
|
162
|
+
Net::SSH.start(@hostname, @vm_user, :keys => [@vm_keyfile]) do |ssh|
|
163
|
+
puts "DEBUG: running command: #{command}"
|
164
|
+
ssh.exec!(command)
|
165
|
+
end
|
166
|
+
else
|
167
|
+
Net::SSH.start(@hostname, @vm_user, :password => @vm_pass, :auth_methods => ["password"]) do |ssh|
|
168
|
+
result = ssh.exec!(command)
|
169
|
+
end
|
146
170
|
end
|
147
171
|
end
|
148
172
|
|
@@ -153,7 +177,6 @@ private
|
|
153
177
|
unless /^[\d\w\s\[\]\{\}\/\\\.\-\"\(\):!]*$/.match string
|
154
178
|
raise "WARNING! Invalid character in: #{string}"
|
155
179
|
end
|
156
|
-
|
157
180
|
string
|
158
181
|
end
|
159
182
|
|
@@ -164,10 +187,9 @@ private
|
|
164
187
|
unless /^[\d\w\s\[\]\{\}\/\\\.\-\"\(\)]*$/.match string
|
165
188
|
raise "WARNING! Invalid character in: #{string}"
|
166
189
|
end
|
167
|
-
|
168
190
|
string
|
169
191
|
end
|
170
|
-
end
|
171
192
|
|
172
193
|
end
|
173
194
|
end
|
195
|
+
end
|
@@ -54,65 +54,113 @@ class WorkstationDriver < VmDriver
|
|
54
54
|
|
55
55
|
def run_command(command)
|
56
56
|
|
57
|
-
|
58
|
-
|
57
|
+
#
|
58
|
+
# Generate a script name
|
59
|
+
#
|
60
|
+
script_rand_name = rand(1000000)
|
61
|
+
|
62
|
+
#
|
63
|
+
# Configure paths for each OS - We really can't filter command, so we're gonna
|
64
|
+
# stick it in a script
|
65
|
+
#
|
59
66
|
if @os == "windows"
|
60
67
|
local_tempfile_path = "/tmp/lab_script_#{script_rand_name}.bat"
|
61
68
|
remote_tempfile_path = "C:\\\\lab_script_#{script_rand_name}.bat"
|
69
|
+
remote_output_file = "C:\\\\lab_command_output_#{script_rand_name}"
|
62
70
|
remote_run_command = remote_tempfile_path
|
71
|
+
File.open(local_tempfile_path, 'w') {|f| f.write(command) }
|
63
72
|
else
|
73
|
+
|
64
74
|
local_tempfile_path = "/tmp/lab_script_#{script_rand_name}.sh"
|
65
75
|
remote_tempfile_path = "/tmp/lab_script_#{script_rand_name}.sh"
|
66
|
-
|
76
|
+
remote_output_file = "/tmp/lab_command_output_#{script_rand_name}"
|
77
|
+
local_output_file = "/tmp/lab_command_output_#{script_rand_name}"
|
78
|
+
|
79
|
+
remote_run_command = remote_tempfile_path
|
80
|
+
|
81
|
+
File.open(local_tempfile_path, 'w') {|f| f.write("#!/bin/sh\n#{command}\n")}
|
67
82
|
end
|
83
|
+
|
84
|
+
if @tools
|
68
85
|
|
69
|
-
|
70
|
-
File.open(local_tempfile_path, 'w') {|f| f.write(command) }
|
86
|
+
#puts "DEBUG: Running w/ tools"
|
71
87
|
|
72
|
-
|
73
|
-
|
74
|
-
#
|
88
|
+
#
|
89
|
+
# Copy our local tempfile to the guest
|
90
|
+
#
|
75
91
|
vmrunstr = "vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
|
76
92
|
"copyFileFromHostToGuest \'#{@location}\' \'#{local_tempfile_path}\'" +
|
77
|
-
" \'#{remote_tempfile_path}\'
|
78
|
-
system_command(vmrunstr)
|
79
|
-
|
80
|
-
# now run it on the guest
|
81
|
-
vmrunstr = "vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
|
82
|
-
"runProgramInGuest \'#{@location}\' -noWait -activeWindow \'#{remote_run_command}\'"
|
93
|
+
" \'#{remote_tempfile_path}\'"
|
83
94
|
system_command(vmrunstr)
|
84
95
|
|
85
|
-
|
86
|
-
|
96
|
+
if @os == "linux"
|
97
|
+
#
|
98
|
+
# Now run the command directly on the guest (linux - call w/ /bin/sh)
|
99
|
+
#
|
100
|
+
vmrunstr = "vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
|
101
|
+
"runProgramInGuest \'#{@location}\' /bin/sh #{remote_tempfile_path} > #{remote_output_file}"
|
102
|
+
system_command(vmrunstr)
|
103
|
+
else
|
104
|
+
#
|
105
|
+
# Now run the command directly on the guest (windows)
|
106
|
+
#
|
107
|
+
vmrunstr = "vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
|
108
|
+
"runProgramInGuest \'#{@location}\' #{remote_tempfile_path} > #{remote_output_file}"
|
109
|
+
system_command(vmrunstr)
|
110
|
+
end
|
111
|
+
|
112
|
+
#
|
113
|
+
# Cleanup. Delete it on the guest
|
114
|
+
#
|
87
115
|
vmrunstr = "vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
|
88
116
|
"deleteFileInGuest \'#{@location}\' \'#{remote_tempfile_path}\'"
|
89
117
|
system_command(vmrunstr)
|
90
118
|
|
91
|
-
#
|
119
|
+
#
|
120
|
+
# Delete it locally
|
121
|
+
#
|
92
122
|
local_delete_command = "rm #{local_tempfile_path}"
|
93
123
|
system_command(local_delete_command)
|
94
124
|
else
|
95
|
-
|
125
|
+
|
126
|
+
#
|
127
|
+
# Use SCP / SSH
|
128
|
+
#
|
129
|
+
|
96
130
|
if @os == "linux"
|
97
131
|
|
98
|
-
|
99
|
-
|
132
|
+
#
|
133
|
+
# Copy it over
|
134
|
+
#
|
100
135
|
scp_to(local_tempfile_path, remote_tempfile_path)
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
136
|
+
|
137
|
+
#
|
138
|
+
# And ... execute it
|
139
|
+
#
|
140
|
+
ssh_exec("/bin/sh #{remote_tempfile_path} > #{remote_output_file}")
|
141
|
+
|
142
|
+
#
|
143
|
+
# Now copy the output back to us
|
144
|
+
#
|
145
|
+
scp_from(remote_output_file, local_output_file)
|
146
|
+
|
147
|
+
# Now, let's look at the output of the command
|
148
|
+
output_string = File.open(local_output_file,"r").read
|
149
|
+
|
150
|
+
#
|
151
|
+
# And clean up
|
152
|
+
#
|
153
|
+
ssh_exec("rm #{remote_output_file}")
|
105
154
|
ssh_exec("rm #{remote_tempfile_path}")
|
106
155
|
|
107
|
-
#
|
108
|
-
|
109
|
-
`rm #{output_file}`
|
110
|
-
|
156
|
+
`rm #{local_output_file}`
|
157
|
+
|
111
158
|
else
|
112
|
-
raise "
|
113
|
-
end
|
159
|
+
raise "Hey, no tools, and windows? can't do nuttin for ya man."
|
160
|
+
end
|
161
|
+
|
114
162
|
end
|
115
|
-
|
163
|
+
output_string
|
116
164
|
end
|
117
165
|
|
118
166
|
def copy_from(from, to)
|
@@ -143,7 +191,7 @@ class WorkstationDriver < VmDriver
|
|
143
191
|
file = filter_input(file)
|
144
192
|
if @tools
|
145
193
|
vmrunstr = "vmrun -T ws -gu \'#{@vm_user}\' -gp \'#{@vm_pass}\' fileExistsInGuest " +
|
146
|
-
"\'#{@location}\' \'#{file}\'
|
194
|
+
"\'#{@location}\' \'#{file}\'"
|
147
195
|
system_command(vmrunstr)
|
148
196
|
else
|
149
197
|
raise "Unsupported"
|
@@ -159,8 +207,6 @@ class WorkstationDriver < VmDriver
|
|
159
207
|
else
|
160
208
|
raise "Unsupported"
|
161
209
|
end
|
162
|
-
|
163
|
-
|
164
210
|
end
|
165
211
|
|
166
212
|
def cleanup
|
data/lib/lab/version.rb
CHANGED
data/lib/lab/vm.rb
CHANGED
@@ -49,10 +49,10 @@ class Vm
|
|
49
49
|
|
50
50
|
@location = filter_input(config['location'])
|
51
51
|
#@name = config['name'] || ""
|
52
|
-
@description = config['description']
|
53
|
-
@tools = config['tools']
|
54
|
-
@os = config['os']
|
55
|
-
@arch = config['arch']
|
52
|
+
@description = config['description']
|
53
|
+
@tools = config['tools']
|
54
|
+
@os = config['os']
|
55
|
+
@arch = config['arch']
|
56
56
|
@type = filter_input(config['type']) || "unspecified"
|
57
57
|
@credentials = config['credentials'] || []
|
58
58
|
|
@@ -91,9 +91,9 @@ class Vm
|
|
91
91
|
elsif @driver_type == "remote_workstation"
|
92
92
|
@driver = Lab::Drivers::RemoteWorkstationDriver.new(config)
|
93
93
|
#elsif @driver_type == "qemu"
|
94
|
-
# @driver = Lab::Drivers::QemuDriver.new
|
94
|
+
# @driver = Lab::Drivers::QemuDriver.new
|
95
95
|
#elsif @driver_type == "qemudo"
|
96
|
-
# @driver = Lab::Drivers::QemudoDriver.new
|
96
|
+
# @driver = Lab::Drivers::QemudoDriver.new
|
97
97
|
else
|
98
98
|
raise "Unknown Driver Type"
|
99
99
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lab
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
|
-
requirement: &
|
16
|
+
requirement: &20127300 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *20127300
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: net-ssh
|
27
|
-
requirement: &
|
27
|
+
requirement: &20126880 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *20126880
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: net-scp
|
38
|
-
requirement: &
|
38
|
+
requirement: &20126460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,18 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *20126460
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rbvmomi
|
49
|
+
requirement: &20126040 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *20126040
|
47
58
|
description: ! 'Start/Stop/Revert and do other cool stuff w/ Vmware, Virtualbox, and
|
48
59
|
ESXi vms. This gem wraps common CLI utilities and other gems to create a common
|
49
60
|
inteface for vms. '
|