derelict 0.2.3.travis.85 → 0.2.3.travis.89
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 +8 -8
- data/lib/derelict/virtual_machine.rb +46 -17
- data/spec/derelict/virtual_machine_spec.rb +20 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDNiNDkwZjE4NzM5NjZiNThlMjJiMTQ3NDhlZmUxMDY1YTc1OTNjYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YWM2Mzk4NWRjYWFmZWJjNWIxN2ExZjdkN2JkMDgxNmZlYWExZjhjNg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWFmMjE5ZmRiMDg1YmE4N2E2YWZlOGNlYzgyZWM1MDFjOWU3NjExNWRjNDVi
|
10
|
+
M2Q1MDY5Zjk2ZGMyZDA1YjI3ZGUyZTg5ODBmOWJiN2U2ZTNhNmNmOGU0Zjlm
|
11
|
+
ZWM5NjZiOWQ1NjdiMzc2ZWRmNWUwNTRiMGZmNzJiZmVmMTQ4Y2M=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTY0MmI5ZmU5ZjE0NTg0MjA2NzE0NjVhOGU3ZmE1ZDQyNzlmNTdkM2UxZTA0
|
14
|
+
NGUwOTE4MTg1ZmUwZWVhZDY2ZWU5NmZlMTU2NWU0M2RlNjM3YTEyYjFiODY2
|
15
|
+
ZWFjMjM0NTRlMDMzY2VlZjgwYjI0YTc0YTdkNzg1ODJlMDQwMTE=
|
@@ -86,27 +86,27 @@ module Derelict
|
|
86
86
|
#
|
87
87
|
# * log: Should the log output be printed? (defaults to false)
|
88
88
|
COMMANDS.each do |command|
|
89
|
-
define_method :"#{command}!" do |*
|
90
|
-
|
91
|
-
|
89
|
+
define_method :"#{command}!" do |*opts|
|
90
|
+
# Ideally this block would have one argument with a default
|
91
|
+
# value of an empty Hash. Unfortunately, setting a default
|
92
|
+
# value for the arguments to a block is only supported in Ruby
|
93
|
+
# 1.9+. The splatted arguments thing is a way to allow zero or
|
94
|
+
# one argument, but it actually allows any number of arguments.
|
95
|
+
# So we need to emulate the error Ruby would throw if you give
|
96
|
+
# the wrong number of arguments.
|
97
|
+
if opts.length > 1
|
98
|
+
message = "wrong number of arguments (#{opts.length} for 0-1)"
|
92
99
|
raise ArgumentError.new message
|
93
100
|
end
|
94
101
|
|
95
|
-
|
102
|
+
# Set defaults for the opts hash
|
103
|
+
opts = {:color => false, :log => false}.merge(opts.first || {})
|
96
104
|
|
97
105
|
# Log message if there's one for this command
|
98
|
-
|
99
|
-
logger.info message unless message.nil?
|
106
|
+
log_message_for(command).tap {|m| logger.info m unless m.nil? }
|
100
107
|
|
101
|
-
#
|
102
|
-
|
103
|
-
|
104
|
-
# Execute the command, optionally logging output
|
105
|
-
log_block = options[:log] ? shell_log_block : nil
|
106
|
-
|
107
|
-
args = [command, name, *arguments_for(command)]
|
108
|
-
args << "--color" if options[:color]
|
109
|
-
connection.execute! *args, &log_block
|
108
|
+
# Execute the command!
|
109
|
+
execute! command, opts
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
@@ -126,10 +126,39 @@ module Derelict
|
|
126
126
|
end
|
127
127
|
|
128
128
|
private
|
129
|
+
# Executes a command on the connection for this VM
|
130
|
+
#
|
131
|
+
# * command: The command to execute (as a symbol)
|
132
|
+
# * options: A Hash of options, with the following optional keys:
|
133
|
+
# * log: Logs the output of the command if true
|
134
|
+
# (defaults to false)
|
135
|
+
# * color: Uses color in the log output (defaults to
|
136
|
+
# false, only relevant if log is true)
|
137
|
+
# * provider: The Vagrant provider to use, one of
|
138
|
+
# "virtualbox" or "vmware_fusion" (defaults to
|
139
|
+
# "virtualbox")
|
140
|
+
def execute!(command, options)
|
141
|
+
# Build up the arguments to pass to connection.execute!
|
142
|
+
arguments = [command, name, *arguments_for(command)]
|
143
|
+
arguments << "--color" if options[:color]
|
144
|
+
if options[:provider]
|
145
|
+
arguments << "--provider"
|
146
|
+
arguments << options[:provider]
|
147
|
+
end
|
148
|
+
|
149
|
+
# Set up the block to use when executing -- if logging is
|
150
|
+
# enabled, use a block that logs the output; otherwise no block.
|
151
|
+
block = options[:log] ? shell_log_block : nil
|
152
|
+
|
153
|
+
# Execute the command
|
154
|
+
connection.execute! *arguments, &block
|
155
|
+
end
|
156
|
+
|
129
157
|
# A block that can be passed to #execute to log the output
|
130
158
|
def shell_log_block
|
131
|
-
Proc.new do |
|
132
|
-
|
159
|
+
Proc.new do |stdout, stderr|
|
160
|
+
# Only stdout or stderr is populated, the other will be nil
|
161
|
+
logger(:type => :external).info(stdout || stderr)
|
133
162
|
end
|
134
163
|
end
|
135
164
|
memoize :shell_log_block
|
@@ -125,19 +125,31 @@ describe Derelict::VirtualMachine do
|
|
125
125
|
|
126
126
|
context "with correct number of arguments" do
|
127
127
|
let(:args) { [:up, name] }
|
128
|
-
before do
|
129
|
-
expect(connection).to receive(:execute!).with(*args).and_yield("foo").and_return result
|
130
|
-
end
|
131
128
|
|
132
129
|
context "with external logging disabled" do
|
130
|
+
before do
|
131
|
+
expect(connection).to receive(:execute!).with(*args).and_return result
|
132
|
+
end
|
133
|
+
|
133
134
|
include_context "logged messages"
|
134
135
|
let(:expected_logs) {[
|
135
136
|
"DEBUG virtualmachine: Successfully initialized Derelict::VirtualMachine 'testvm' from test\n",
|
136
137
|
" INFO virtualmachine: Bringing up Derelict::VirtualMachine 'testvm' from test\n",
|
137
138
|
]}
|
139
|
+
|
140
|
+
context "with different provider" do
|
141
|
+
let(:options) { {:provider => "foobar"} }
|
142
|
+
let(:args) { [:up, name, "--provider", "foobar"] }
|
143
|
+
|
144
|
+
it { should be result }
|
145
|
+
end
|
138
146
|
end
|
139
147
|
|
140
148
|
context "with external logging enabled" do
|
149
|
+
before do
|
150
|
+
expect(connection).to receive(:execute!).with(*args).and_yield("foo", nil).and_return result
|
151
|
+
end
|
152
|
+
|
141
153
|
let(:options) { {:log => true} }
|
142
154
|
|
143
155
|
include_context "logged messages"
|
@@ -163,7 +175,7 @@ describe Derelict::VirtualMachine do
|
|
163
175
|
|
164
176
|
let(:args) { [:halt, name] }
|
165
177
|
before do
|
166
|
-
expect(connection).to receive(:execute!).with(*args).and_yield("foo").and_return result
|
178
|
+
expect(connection).to receive(:execute!).with(*args).and_yield("foo", nil).and_return result
|
167
179
|
end
|
168
180
|
|
169
181
|
context "with external logging disabled" do
|
@@ -199,7 +211,7 @@ describe Derelict::VirtualMachine do
|
|
199
211
|
|
200
212
|
let(:args) { [:destroy, name, '--force'] }
|
201
213
|
before do
|
202
|
-
expect(connection).to receive(:execute!).with(*args).and_yield("foo").and_return result
|
214
|
+
expect(connection).to receive(:execute!).with(*args).and_yield("foo", nil).and_return result
|
203
215
|
end
|
204
216
|
|
205
217
|
context "with external logging disabled" do
|
@@ -234,7 +246,7 @@ describe Derelict::VirtualMachine do
|
|
234
246
|
subject { vm.reload! options }
|
235
247
|
|
236
248
|
before do
|
237
|
-
expect(connection).to receive(:execute!).with(:reload, name).and_yield("foo").and_return result
|
249
|
+
expect(connection).to receive(:execute!).with(:reload, name).and_yield("foo", nil).and_return result
|
238
250
|
end
|
239
251
|
|
240
252
|
context "with external logging disabled" do
|
@@ -263,7 +275,7 @@ describe Derelict::VirtualMachine do
|
|
263
275
|
subject { vm.suspend! options }
|
264
276
|
|
265
277
|
before do
|
266
|
-
expect(connection).to receive(:execute!).with(:suspend, name).and_yield("foo").and_return result
|
278
|
+
expect(connection).to receive(:execute!).with(:suspend, name).and_yield("foo", nil).and_return result
|
267
279
|
end
|
268
280
|
|
269
281
|
context "with external logging disabled" do
|
@@ -292,7 +304,7 @@ describe Derelict::VirtualMachine do
|
|
292
304
|
subject { vm.resume! options }
|
293
305
|
|
294
306
|
before do
|
295
|
-
expect(connection).to receive(:execute!).with(:resume, name).and_yield("foo").and_return result
|
307
|
+
expect(connection).to receive(:execute!).with(:resume, name).and_yield("foo", nil).and_return result
|
296
308
|
end
|
297
309
|
|
298
310
|
context "with external logging disabled" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: derelict
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.3.travis.
|
4
|
+
version: 0.2.3.travis.89
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Feehan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: log4r
|