vagrant-skytap 0.1.7 → 0.1.8

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/eng-10269.diff.1 DELETED
@@ -1,455 +0,0 @@
1
- # HG changeset patch
2
- # Parent 586410d23ff4907e87ce5ee2c7eee574f0749ab0
3
- ENG-10269 add parallelization support for `vagrant up`. This appears to work for the no-parallel case.
4
-
5
- diff -r 586410d23ff4 lib/vagrant-skytap/action.rb
6
- --- a/lib/vagrant-skytap/action.rb Thu Nov 19 21:24:21 2015 -0800
7
- +++ b/lib/vagrant-skytap/action.rb Thu Nov 19 21:24:32 2015 -0800
8
- @@ -187,6 +187,30 @@
9
- # This action is called to bring the box up from nothing.
10
- def self.action_up
11
- Vagrant::Action::Builder.new.tap do |b|
12
- + b.use action_create
13
- +
14
- + b.use Call, IsStopped do |env, b1|
15
- + if env[:result]
16
- + # this has some kind of hook that executes
17
- + # when #action returns
18
- + b1.use action_prepare_boot
19
- + end
20
- + end
21
- +
22
- + b.use Call, IsRunning do |env, b1|
23
- + if env[:result]
24
- + b1.use MessageAlreadyRunning
25
- + next
26
- + end
27
- + b1.use RunVm
28
- + b1.use WaitForCommunicator
29
- + end
30
- + end
31
- + end
32
- +
33
- + # Pulled out of action_up to allow
34
- + def self.action_create
35
- + Vagrant::Action::Builder.new.tap do |b|
36
- b.use HandleBox
37
- b.use ConfigValidate
38
- b.use InitializeAPIClient
39
- @@ -204,26 +228,23 @@
40
- b1.use StoreExtraData
41
- b1.use SetUpVm
42
- end
43
- - b.use Call, IsRunning do |env, b1|
44
- + b.use Call, IsStopped do |env, b1|
45
- if env[:result]
46
- - b1.use MessageAlreadyRunning
47
- - next
48
- - end
49
- -
50
- - b1.use Call, IsStopped do |env2, b2|
51
- - if env2[:result]
52
- - b2.use UpdateHardware
53
- - b2.use SetHostname
54
- - b2.use action_prepare_boot
55
- - end
56
- -
57
- - b2.use RunVm
58
- - b2.use WaitForCommunicator
59
- + b1.use UpdateHardware
60
- + b1.use SetHostname
61
- end
62
- end
63
- end
64
- end
65
-
66
- + def self.action_run_environment
67
- + Vagrant::Action::Builder.new.tap do |b|
68
- + b.use InitializeAPIClient
69
- + b.use FetchEnvironment
70
- + b.use RunEnvironment
71
- + end
72
- + end
73
- +
74
- def self.action_reload
75
- Vagrant::Action::Builder.new.tap do |b|
76
- b.use ConfigValidate
77
- diff -r 586410d23ff4 lib/vagrant-skytap/action/initialize_api_client.rb
78
- --- a/lib/vagrant-skytap/action/initialize_api_client.rb Thu Nov 19 21:24:21 2015 -0800
79
- +++ b/lib/vagrant-skytap/action/initialize_api_client.rb Thu Nov 19 21:24:32 2015 -0800
80
- @@ -15,7 +15,14 @@
81
- def call(env)
82
- @logger.info("Connecting to Skytap...")
83
-
84
- - client = API::Client.new(env[:machine].provider_config)
85
- + # This can be called outside the context of a machine
86
- + config = env[:machine].try(:provider_config) || {
87
- + base_url: env[:base_url],
88
- + username: env[:username],
89
- + api_token: env[:api_token],
90
- + }
91
- +
92
- + client = API::Client.new(config)
93
- if client.get('/configurations').code == '200'
94
- env[:api_client] = client
95
- end
96
- diff -r 586410d23ff4 lib/vagrant-skytap/action/run_environment.rb
97
- --- a/lib/vagrant-skytap/action/run_environment.rb Thu Nov 19 21:24:21 2015 -0800
98
- +++ b/lib/vagrant-skytap/action/run_environment.rb Thu Nov 19 21:24:32 2015 -0800
99
- @@ -16,8 +16,10 @@
100
- end
101
-
102
- def call(env)
103
- - env[:ui].info(I18n.t("vagrant_skytap.launching_instance"))
104
- - environment.run!
105
- + env[:ui].info(I18n.t("vagrant_skytap.running_environment"))
106
- + vm_ids = env[:machines].try(:collect, &:id)
107
- + @logger.info("Running VMs: #{vm_ids}")
108
- + env[:environment].run!(vm_ids)
109
-
110
- @app.call(env)
111
- end
112
- diff -r 586410d23ff4 lib/vagrant-skytap/api/environment.rb
113
- --- a/lib/vagrant-skytap/api/environment.rb Thu Nov 19 21:24:21 2015 -0800
114
- +++ b/lib/vagrant-skytap/api/environment.rb Thu Nov 19 21:24:32 2015 -0800
115
- @@ -28,7 +28,9 @@
116
- end
117
-
118
- def properties(env)
119
- - EnvironmentProperties.read(env[:machine].env.local_data_path)
120
- + # This can be called outside the context of a particular machine
121
- + path = env[:local_data_path] || env[:machine].env.local_data_path
122
- + EnvironmentProperties.read(path)
123
- end
124
-
125
- def check_vm_before_adding(env, vm)
126
- @@ -78,6 +80,10 @@
127
- super
128
- end
129
-
130
- + def run!(vm_ids = nil)
131
- + set_runstate :running, vm_ids: vm_ids
132
- + end
133
- +
134
- def delete
135
- retry_while_resource_busy do
136
- api_client.delete(url)
137
- diff -r 586410d23ff4 lib/vagrant-skytap/api/runstate_operations.rb
138
- --- a/lib/vagrant-skytap/api/runstate_operations.rb Thu Nov 19 21:24:21 2015 -0800
139
- +++ b/lib/vagrant-skytap/api/runstate_operations.rb Thu Nov 19 21:24:32 2015 -0800
140
- @@ -20,12 +20,17 @@
141
- end
142
-
143
- def poweroff!
144
- - set_runstate :halted, :stopped
145
- + set_runstate :halted, completed_runstate: :stopped
146
- end
147
-
148
- - def set_runstate(new_runstate, completed_runstate = nil)
149
- - completed_runstate ||= new_runstate
150
- - update_with_retry(runstate: new_runstate)
151
- + def set_runstate(new_runstate, opts = {})
152
- + completed_runstate = opts.delete(:completed_runstate) || new_runstate
153
- +
154
- + params = {runstate: new_runstate}.tap do |ret|
155
- + ret[:multiselect] = opts[:vm_ids] if opts[:vm_ids]
156
- + end
157
- + update_with_retry(params)
158
- +
159
- wait_for_runstate(completed_runstate) unless runstate == completed_runstate
160
- end
161
-
162
- diff -r 586410d23ff4 lib/vagrant-skytap/command/start_mixins.rb
163
- --- /dev/null Thu Jan 01 00:00:00 1970 +0000
164
- +++ b/lib/vagrant-skytap/command/start_mixins.rb Thu Nov 19 21:24:32 2015 -0800
165
- @@ -0,0 +1,47 @@
166
- +module VagrantPlugins
167
- + module Skytap
168
- + module Command
169
- + module StartMixins
170
- +
171
- + # Would be nice to just extend this, then alias #build_start_options
172
- + # and add default options flag.
173
- + #include VagrantPlugins::CommandUp::StartMixins
174
- +
175
- + # This adds the standard `start` command line flags to the given
176
- + # OptionParser, storing the result in the `options` dictionary.
177
- + #
178
- + # @param [OptionParser] parser
179
- + # @param [Hash] options
180
- + def build_start_options(parser, options)
181
- + # Setup the defaults
182
- + options[:provision_types] = nil
183
- +
184
- + # Add the options
185
- + parser.on("--[no-]provision", "Enable or disable provisioning") do |p|
186
- + options[:provision_enabled] = p
187
- + options[:provision_ignore_sentinel] = true
188
- + end
189
- +
190
- + parser.on("--provision-with x,y,z", Array,
191
- + "Enable only certain provisioners, by type.") do |list|
192
- + options[:provision_types] = list.map { |type| type.to_sym }
193
- + options[:provision_enabled] = true
194
- + options[:provision_ignore_sentinel] = true
195
- + end
196
- + end
197
- +
198
- + # This validates the provisioner flags and raises an exception
199
- + # if there are invalid ones.
200
- + def validate_provisioner_flags!(options)
201
- + (options[:provision_types] || []).each do |type|
202
- + klass = Vagrant.plugin("2").manager.provisioners[type]
203
- + if !klass
204
- + raise Vagrant::Errors::ProvisionerFlagInvalid,
205
- + name: type.to_s
206
- + end
207
- + end
208
- + end
209
- + end
210
- + end
211
- + end
212
- +end
213
- diff -r 586410d23ff4 lib/vagrant-skytap/command/up.rb
214
- --- /dev/null Thu Jan 01 00:00:00 1970 +0000
215
- +++ b/lib/vagrant-skytap/command/up.rb Thu Nov 19 21:24:32 2015 -0800
216
- @@ -0,0 +1,139 @@
217
- +require 'optparse'
218
- +
219
- +require "vagrant"
220
- +require 'byebug'
221
- +
222
- +require_relative 'start_mixins'
223
- +
224
- +# This is a copy of Vagrant's built-in "up" command which handles
225
- +# parallel runstate changes by invoking the run_environment action
226
- +# once for all machines: runstate operations lock the environment,
227
- +# and are therefore not thread-safe.
228
- +
229
- +module VagrantPlugins
230
- + module Skytap
231
- + module Command
232
- + #class Up < VagrantPlugins::CommandUp::Command
233
- + class Up < Vagrant.plugin("2", :command)
234
- + include StartMixins
235
- +
236
- + def self.synopsis
237
- + "starts and provisions the vagrant environment (with parallel runstate support)"
238
- + end
239
- +
240
- + def execute
241
- + options = {}
242
- + options[:destroy_on_error] = true
243
- + options[:parallel] = true
244
- + options[:provision_ignore_sentinel] = false
245
- +
246
- + opts = OptionParser.new do |o|
247
- + o.banner = "Usage: vagrant up [options] [name]"
248
- + o.separator ""
249
- + o.separator "Options:"
250
- + o.separator ""
251
- +
252
- + build_start_options(o, options)
253
- +
254
- + o.on("--[no-]destroy-on-error",
255
- + "Destroy machine if any fatal error happens (default to true)") do |destroy|
256
- + options[:destroy_on_error] = destroy
257
- + end
258
- +
259
- + o.on("--[no-]parallel",
260
- + "Enable or disable parallelism if provider supports it") do |parallel|
261
- + options[:parallel] = parallel
262
- + end
263
- +
264
- + o.on("--provider PROVIDER", String,
265
- + "Back the machine with a specific provider") do |provider|
266
- + options[:provider] = provider
267
- + end
268
- + end
269
- +
270
- + # Parse the options
271
- + argv = parse_options(opts)
272
- + return if !argv
273
- +
274
- + # Validate the provisioners
275
- + validate_provisioner_flags!(options)
276
- +
277
- + # Go over each VM and bring it up
278
- + @logger.debug("'Up' each target VM...")
279
- +
280
- +
281
- + # Begin modified section
282
- +
283
- + machines = []
284
- + names = argv
285
- + if names.empty?
286
- + autostart = false
287
- + @env.vagrantfile.machine_names_and_options.each do |n, o|
288
- + autostart = true if o.key?(:autostart)
289
- + o[:autostart] = true if !o.key?(:autostart)
290
- + names << n.to_s if o[:autostart]
291
- + end
292
- +
293
- + # If we have an autostart key but no names, it means that
294
- + # all machines are autostart: false and we don't start anything.
295
- + names = nil if autostart && names.empty?
296
- + end
297
- +
298
- + with_target_vms(names, provider: options[:provider]) do |machine|
299
- + @env.ui.info(I18n.t(
300
- + "vagrant.commands.up.upping",
301
- + name: machine.name,
302
- + provider: machine.provider_name))
303
- +
304
- + machines << machine
305
- +
306
- + if options[:parallel]
307
- + machine.action(:create, options)
308
- + else
309
- + machine.action(:up, options)
310
- + end
311
- + end
312
- +
313
- + if options[:parallel]
314
- + @env.action_runner.run(VagrantPlugins::Skytap::Action.action_run_environment,
315
- + local_data_path: @env.local_data_path,
316
- + machines: machines,
317
- + machine: machines.first,
318
- + base_url: nil,
319
- + username: nil,
320
- + api_token: nil,
321
- + ui: @env.ui
322
- + )
323
- + end
324
- +
325
- + # End modified section
326
- +
327
- +
328
- + if machines.empty?
329
- + @env.ui.info(I18n.t("vagrant.up_no_machines"))
330
- + return 0
331
- + else
332
- +
333
- + end
334
- +
335
- + # Output the post-up messages that we have, if any
336
- + machines.each do |m|
337
- + next if !m.config.vm.post_up_message
338
- + next if m.config.vm.post_up_message == ""
339
- +
340
- + # Add a newline to separate things.
341
- + @env.ui.info("", prefix: false)
342
- +
343
- + m.ui.success(I18n.t(
344
- + "vagrant.post_up_message",
345
- + name: m.name.to_s,
346
- + message: m.config.vm.post_up_message))
347
- + end
348
- +
349
- + # Success, exit status 0
350
- + 0
351
- + end
352
- + end
353
- + end
354
- + end
355
- +end
356
- diff -r 586410d23ff4 lib/vagrant-skytap/plugin.rb
357
- --- a/lib/vagrant-skytap/plugin.rb Thu Nov 19 21:24:21 2015 -0800
358
- +++ b/lib/vagrant-skytap/plugin.rb Thu Nov 19 21:24:32 2015 -0800
359
- @@ -24,7 +24,7 @@
360
- Config
361
- end
362
-
363
- - provider(:skytap, parallel: false) do
364
- + provider(:skytap, parallel: true) do
365
- # Setup logging and i18n
366
- setup_logging
367
- setup_i18n
368
- @@ -34,6 +34,11 @@
369
- Provider
370
- end
371
-
372
- + command("up", primary: true) do
373
- + require_relative "command/up"
374
- + Command::Up
375
- + end
376
- +
377
- # This initializes the internationalization strings.
378
- def self.setup_i18n
379
- I18n.load_path << File.expand_path("locales/en.yml", Skytap.source_root)
380
- diff -r 586410d23ff4 locales/en.yml
381
- --- a/locales/en.yml Thu Nov 19 21:24:21 2015 -0800
382
- +++ b/locales/en.yml Thu Nov 19 21:24:32 2015 -0800
383
- @@ -3,8 +3,8 @@
384
- already_status: |-
385
- The machine is already %{status}.
386
-
387
- - launching_instance: |-
388
- - Launching an instance with the following settings...
389
- + running_environment: |-
390
- + Starting VMs ...
391
- launching_vm: |-
392
- Launching a VM with the following settings...
393
- not_created: |-
394
- diff -r 586410d23ff4 spec/acceptance/provider/up_spec.rb
395
- --- /dev/null Thu Jan 01 00:00:00 1970 +0000
396
- +++ b/spec/acceptance/provider/up_spec.rb Thu Nov 19 21:24:32 2015 -0800
397
- @@ -0,0 +1,33 @@
398
- +# This tests that an instance can be halted correctly
399
- +shared_examples 'provider/up' do |provider, options|
400
- + if !options[:box]
401
- + raise ArgumentError,
402
- + "box option must be specified for provider: #{provider}"
403
- + end
404
- +
405
- + include_context 'acceptance'
406
- +
407
- + before do
408
- + environment.skeleton('generic')
409
- + #assert_execute('vagrant', 'box', 'add', 'basic', options[:box])
410
- + end
411
- +
412
- + after do
413
- + assert_execute('vagrant', 'destroy', '--force')
414
- + end
415
- +
416
- + it 'should bring up the machine and halt it' do
417
- + status("Test: machine can be brought up")
418
- + up_result = execute("vagrant", "up")
419
- + expect(up_result).to exit_with(0)
420
- +
421
- + status("Test: machine is running after up")
422
- + echo_result = execute("vagrant", "ssh", "-c", "echo foo")
423
- + expect(echo_result).to exit_with(0)
424
- + expect(echo_result.stdout).to match(/foo\n$/)
425
- +
426
- + status("Test: machine can be halted")
427
- + halt_result = execute("vagrant", "halt")
428
- + expect(halt_result).to exit_with(0)
429
- + end
430
- +end
431
- diff -r 586410d23ff4 spec/acceptance/skeletons/generic/Vagrantfile
432
- --- a/spec/acceptance/skeletons/generic/Vagrantfile Thu Nov 19 21:24:21 2015 -0800
433
- +++ b/spec/acceptance/skeletons/generic/Vagrantfile Thu Nov 19 21:24:32 2015 -0800
434
- @@ -1,15 +1,14 @@
435
- Vagrant.configure("2") do |config|
436
- - config.vm.box = "skytap-dummy"
437
- + config.vm.box = "skytap/empty"
438
-
439
- config.vm.provider :skytap do |skytap, override|
440
- - skytap.username = "user"
441
- - skytap.api_token = "9999999999999999999999"
442
- - skytap.base_url = "https://example.com/"
443
- + skytap.vm_url = "/vms/7285844"
444
- + skytap.vpn_url = "/vpns/vpn-711360"
445
- +# skytap.vpn_url = "/vpns/vpn-3195669"
446
- end
447
-
448
- config.vm.define "vm1" do |ubuntu|
449
- - ubuntu.vm.provider :skytap do |box|
450
- - box.vm_url = "https://example.com/vms/1"
451
- - end
452
- + ubuntu.ssh.username = "skytap"
453
- + ubuntu.ssh.password = "ChangeMe!"
454
- end
455
- end