vagrant-unbundled 2.2.6.0 → 2.2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.hashibot.hcl +14 -0
- data/CHANGELOG.md +93 -2
- data/README.md +1 -3
- data/bin/vagrant +23 -0
- data/contrib/bash/completion.sh +13 -1
- data/lib/vagrant.rb +25 -0
- data/lib/vagrant/action.rb +5 -0
- data/lib/vagrant/action/builder.rb +145 -24
- data/lib/vagrant/action/builtin/box_add.rb +11 -4
- data/lib/vagrant/action/builtin/box_check_outdated.rb +12 -15
- data/lib/vagrant/action/builtin/cleanup_disks.rb +56 -0
- data/lib/vagrant/action/builtin/delayed.rb +26 -0
- data/lib/vagrant/action/builtin/disk.rb +52 -0
- data/lib/vagrant/action/builtin/handle_box.rb +2 -0
- data/lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb +28 -9
- data/lib/vagrant/action/builtin/mixin_provisioners.rb +19 -1
- data/lib/vagrant/action/builtin/ssh_run.rb +21 -3
- data/lib/vagrant/action/builtin/trigger.rb +36 -0
- data/lib/vagrant/action/hook.rb +20 -2
- data/lib/vagrant/action/runner.rb +11 -26
- data/lib/vagrant/action/warden.rb +4 -18
- data/lib/vagrant/box_metadata.rb +17 -3
- data/lib/vagrant/bundler.rb +260 -53
- data/lib/vagrant/cli.rb +4 -2
- data/lib/vagrant/errors.rb +24 -0
- data/lib/vagrant/machine.rb +9 -6
- data/lib/vagrant/plugin/manager.rb +25 -14
- data/lib/vagrant/plugin/v2/command.rb +1 -1
- data/lib/vagrant/plugin/v2/manager.rb +53 -0
- data/lib/vagrant/plugin/v2/plugin.rb +1 -0
- data/lib/vagrant/plugin/v2/trigger.rb +64 -26
- data/lib/vagrant/shared_helpers.rb +28 -0
- data/lib/vagrant/ui.rb +50 -4
- data/lib/vagrant/util.rb +1 -0
- data/lib/vagrant/util/curl_helper.rb +8 -5
- data/lib/vagrant/util/downloader.rb +5 -1
- data/lib/vagrant/util/file_checksum.rb +6 -2
- data/lib/vagrant/util/guest_inspection.rb +9 -1
- data/lib/vagrant/util/io.rb +7 -27
- data/lib/vagrant/util/is_port_open.rb +1 -2
- data/lib/vagrant/util/map_command_options.rb +33 -0
- data/lib/vagrant/util/numeric.rb +69 -0
- data/lib/vagrant/util/platform.rb +8 -1
- data/plugins/commands/box/command/outdated.rb +14 -2
- data/plugins/commands/cloud/locales/en.yml +1 -1
- data/plugins/commands/cloud/publish.rb +1 -1
- data/plugins/commands/snapshot/command/save.rb +13 -8
- data/plugins/commands/ssh_config/command.rb +1 -1
- data/plugins/communicators/ssh/communicator.rb +18 -23
- data/plugins/communicators/winrm/config.rb +1 -1
- data/plugins/communicators/winrm/shell.rb +1 -1
- data/plugins/communicators/winssh/communicator.rb +126 -38
- data/plugins/communicators/winssh/config.rb +3 -7
- data/plugins/guests/alpine/cap/rsync.rb +1 -1
- data/plugins/guests/alpine/plugin.rb +16 -0
- data/plugins/guests/centos/cap/flavor.rb +24 -0
- data/plugins/guests/centos/guest.rb +9 -0
- data/plugins/guests/centos/plugin.rb +20 -0
- data/plugins/guests/darwin/cap/mount_vmware_shared_folder.rb +99 -13
- data/plugins/guests/darwin/plugin.rb +5 -0
- data/plugins/guests/debian/cap/configure_networks.rb +14 -6
- data/plugins/guests/linux/cap/halt.rb +9 -1
- data/plugins/guests/linux/cap/mount_smb_shared_folder.rb +16 -0
- data/plugins/guests/linux/cap/reboot.rb +48 -0
- data/plugins/guests/linux/plugin.rb +10 -0
- data/plugins/guests/redhat/cap/flavor.rb +3 -1
- data/plugins/guests/redhat/cap/nfs_client.rb +2 -2
- data/plugins/guests/redhat/cap/smb.rb +20 -0
- data/plugins/guests/redhat/plugin.rb +5 -0
- data/plugins/guests/suse/cap/change_host_name.rb +2 -2
- data/plugins/guests/windows/cap/public_key.rb +3 -3
- data/plugins/guests/windows/cap/reboot.rb +2 -1
- data/plugins/hosts/darwin/cap/nfs.rb +11 -0
- data/plugins/hosts/darwin/plugin.rb +5 -0
- data/plugins/hosts/linux/cap/nfs.rb +21 -2
- data/plugins/kernel_v2/config/disk.rb +199 -0
- data/plugins/kernel_v2/config/ssh_connect.rb +24 -0
- data/plugins/kernel_v2/config/vm.rb +109 -4
- data/plugins/kernel_v2/config/vm_provisioner.rb +4 -1
- data/plugins/kernel_v2/config/vm_trigger.rb +2 -5
- data/plugins/providers/docker/driver.rb +38 -10
- data/plugins/providers/docker/errors.rb +4 -0
- data/plugins/providers/docker/executor/local.rb +7 -1
- data/plugins/providers/hyperv/action/export.rb +4 -2
- data/plugins/providers/hyperv/driver.rb +10 -9
- data/plugins/providers/hyperv/scripts/set_vm_integration_services.ps1 +3 -3
- data/plugins/providers/hyperv/scripts/utils/VagrantVM/VagrantVM.psm1 +6 -6
- data/plugins/providers/virtualbox/action.rb +2 -0
- data/plugins/providers/virtualbox/action/clean_machine_folder.rb +10 -1
- data/plugins/providers/virtualbox/action/export.rb +4 -2
- data/plugins/providers/virtualbox/action/import.rb +8 -4
- data/plugins/providers/virtualbox/action/prepare_clone_snapshot.rb +4 -2
- data/plugins/providers/virtualbox/action/snapshot_delete.rb +4 -2
- data/plugins/providers/virtualbox/action/snapshot_restore.rb +4 -2
- data/plugins/providers/virtualbox/cap/cleanup_disks.rb +54 -0
- data/plugins/providers/virtualbox/cap/configure_disks.rb +287 -0
- data/plugins/providers/virtualbox/cap/validate_disk_ext.rb +27 -0
- data/plugins/providers/virtualbox/driver/base.rb +15 -0
- data/plugins/providers/virtualbox/driver/meta.rb +14 -2
- data/plugins/providers/virtualbox/driver/version_5_0.rb +142 -2
- data/plugins/providers/virtualbox/driver/version_6_1.rb +39 -0
- data/plugins/providers/virtualbox/plugin.rb +21 -0
- data/plugins/provisioners/ansible/cap/guest/alpine/ansible_install.rb +44 -0
- data/plugins/provisioners/ansible/cap/guest/arch/ansible_install.rb +20 -3
- data/plugins/provisioners/ansible/cap/guest/debian/ansible_install.rb +4 -5
- data/plugins/provisioners/ansible/cap/guest/fedora/ansible_install.rb +2 -2
- data/plugins/provisioners/ansible/cap/guest/freebsd/ansible_install.rb +2 -2
- data/plugins/provisioners/ansible/cap/guest/pip/pip.rb +8 -4
- data/plugins/provisioners/ansible/cap/guest/redhat/ansible_install.rb +2 -2
- data/plugins/provisioners/ansible/cap/guest/suse/ansible_install.rb +2 -1
- data/plugins/provisioners/ansible/cap/guest/ubuntu/ansible_install.rb +3 -3
- data/plugins/provisioners/ansible/plugin.rb +5 -0
- data/plugins/provisioners/ansible/provisioner/base.rb +1 -1
- data/plugins/provisioners/container/client.rb +203 -0
- data/plugins/provisioners/container/config.rb +83 -0
- data/plugins/provisioners/container/installer.rb +13 -0
- data/plugins/provisioners/container/plugin.rb +23 -0
- data/plugins/provisioners/container/provisioner.rb +28 -0
- data/plugins/provisioners/docker/cap/{redhat → centos}/docker_install.rb +10 -7
- data/plugins/provisioners/docker/cap/centos/docker_start_service.rb +24 -0
- data/plugins/provisioners/docker/client.rb +4 -175
- data/plugins/provisioners/docker/config.rb +2 -72
- data/plugins/provisioners/docker/installer.rb +3 -5
- data/plugins/provisioners/docker/plugin.rb +6 -6
- data/plugins/provisioners/docker/provisioner.rb +4 -10
- data/plugins/provisioners/podman/cap/centos/podman_install.rb +35 -0
- data/plugins/provisioners/podman/cap/linux/podman_installed.rb +13 -0
- data/plugins/provisioners/podman/cap/redhat/podman_install.rb +26 -0
- data/plugins/provisioners/podman/client.rb +12 -0
- data/plugins/provisioners/podman/config.rb +28 -0
- data/plugins/provisioners/podman/installer.rb +33 -0
- data/plugins/provisioners/podman/plugin.rb +38 -0
- data/plugins/provisioners/podman/provisioner.rb +52 -0
- data/plugins/provisioners/salt/provisioner.rb +4 -0
- data/plugins/provisioners/shell/config.rb +1 -6
- data/plugins/provisioners/shell/provisioner.rb +54 -25
- data/plugins/synced_folders/smb/synced_folder.rb +1 -1
- data/templates/commands/init/Vagrantfile.erb +1 -1
- data/templates/locales/en.yml +123 -4
- data/templates/locales/providers_docker.yml +2 -0
- data/templates/nfs/exports_darwin.erb +7 -0
- data/vagrant.gemspec +8 -9
- data/version.txt +1 -1
- metadata +3731 -3663
- data/lib/vagrant/action/builtin/after_trigger.rb +0 -31
- data/lib/vagrant/action/builtin/before_trigger.rb +0 -28
- data/plugins/provisioners/docker/cap/redhat/docker_start_service.rb +0 -16
@@ -348,9 +348,15 @@ module Vagrant
|
|
348
348
|
end
|
349
349
|
|
350
350
|
if opts[:checksum] && opts[:checksum_type]
|
351
|
-
|
352
|
-
|
353
|
-
|
351
|
+
if opts[:checksum].to_s.strip.empty?
|
352
|
+
@logger.warn("Given checksum is empty, cannot validate checksum for box")
|
353
|
+
elsif opts[:checksum_type].to_s.strip.empty?
|
354
|
+
@logger.warn("Given checksum type is empty, cannot validate checksum for box")
|
355
|
+
else
|
356
|
+
env[:ui].detail(I18n.t("vagrant.actions.box.add.checksumming"))
|
357
|
+
validate_checksum(
|
358
|
+
opts[:checksum_type], opts[:checksum], box_url)
|
359
|
+
end
|
354
360
|
end
|
355
361
|
|
356
362
|
# Add the box!
|
@@ -427,7 +433,8 @@ module Vagrant
|
|
427
433
|
downloader_options[:headers] = ["Accept: application/json"] if opts[:json]
|
428
434
|
downloader_options[:ui] = env[:ui] if opts[:ui]
|
429
435
|
downloader_options[:location_trusted] = env[:box_download_location_trusted]
|
430
|
-
|
436
|
+
downloader_options[:box_extra_download_options] = env[:box_extra_download_options]
|
437
|
+
|
431
438
|
Util::Downloader.new(url, temp_path, downloader_options)
|
432
439
|
end
|
433
440
|
|
@@ -40,7 +40,7 @@ module Vagrant
|
|
40
40
|
# Have download options specified in the environment override
|
41
41
|
# options specified for the machine.
|
42
42
|
download_options = {
|
43
|
-
automatic_check:
|
43
|
+
automatic_check: !env[:box_outdated_force],
|
44
44
|
ca_cert: env[:ca_cert] || machine.config.vm.box_download_ca_cert,
|
45
45
|
ca_path: env[:ca_path] || machine.config.vm.box_download_ca_path,
|
46
46
|
client_cert: env[:client_cert] ||
|
@@ -70,15 +70,23 @@ module Vagrant
|
|
70
70
|
message: e.message))
|
71
71
|
end
|
72
72
|
env[:box_outdated] = update != nil
|
73
|
-
|
73
|
+
local_update = check_outdated_local(env)
|
74
|
+
if update && (local_update.nil? || (local_update.version < update[1].version))
|
74
75
|
env[:ui].warn(I18n.t(
|
75
76
|
"vagrant.box_outdated_single",
|
76
77
|
name: update[0].name,
|
77
78
|
provider: box.provider,
|
78
79
|
current: box.version,
|
79
80
|
latest: update[1].version))
|
81
|
+
elsif local_update
|
82
|
+
env[:ui].warn(I18n.t(
|
83
|
+
"vagrant.box_outdated_local",
|
84
|
+
name: local_update.name,
|
85
|
+
old: box.version,
|
86
|
+
new: local_update.version))
|
87
|
+
env[:box_outdated] = true
|
80
88
|
else
|
81
|
-
|
89
|
+
env[:box_outdated] = false
|
82
90
|
end
|
83
91
|
|
84
92
|
@app.call(env)
|
@@ -93,19 +101,8 @@ module Vagrant
|
|
93
101
|
version ||= ""
|
94
102
|
version += "> #{machine.box.version}"
|
95
103
|
|
96
|
-
|
104
|
+
env[:box_collection].find(
|
97
105
|
machine.box.name, machine.box.provider, version)
|
98
|
-
if box
|
99
|
-
env[:ui].warn(I18n.t(
|
100
|
-
"vagrant.box_outdated_local",
|
101
|
-
name: box.name,
|
102
|
-
old: machine.box.version,
|
103
|
-
new: box.version))
|
104
|
-
env[:box_outdated] = true
|
105
|
-
return
|
106
|
-
end
|
107
|
-
|
108
|
-
env[:box_outdated] = false
|
109
106
|
end
|
110
107
|
end
|
111
108
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module Action
|
5
|
+
module Builtin
|
6
|
+
class CleanupDisks
|
7
|
+
# Removes any attached disks no longer defined in a Vagrantfile config
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
@logger = Log4r::Logger.new("vagrant::action::builtin::disk")
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
machine = env[:machine]
|
15
|
+
defined_disks = get_disks(machine, env)
|
16
|
+
|
17
|
+
# Call into providers machine implementation for disk management
|
18
|
+
disk_meta_file = read_disk_metadata(machine)
|
19
|
+
|
20
|
+
if !disk_meta_file.empty?
|
21
|
+
if machine.provider.capability?(:cleanup_disks)
|
22
|
+
machine.provider.capability(:cleanup_disks, defined_disks, disk_meta_file)
|
23
|
+
else
|
24
|
+
env[:ui].warn(I18n.t("vagrant.actions.disk.provider_unsupported",
|
25
|
+
provider: machine.provider_name))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Continue On
|
30
|
+
@app.call(env)
|
31
|
+
end
|
32
|
+
|
33
|
+
def read_disk_metadata(machine)
|
34
|
+
meta_file = machine.data_dir.join("disk_meta")
|
35
|
+
if File.file?(meta_file)
|
36
|
+
disk_meta = JSON.parse(meta_file.read)
|
37
|
+
else
|
38
|
+
@logger.info("No previous disk_meta file defined for guest #{machine.name}")
|
39
|
+
disk_meta = {}
|
40
|
+
end
|
41
|
+
|
42
|
+
return disk_meta
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_disks(machine, env)
|
46
|
+
return @_disks if @_disks
|
47
|
+
|
48
|
+
@_disks = []
|
49
|
+
@_disks = machine.config.vm.disks
|
50
|
+
|
51
|
+
@_disks
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Action
|
3
|
+
module Builtin
|
4
|
+
# This class is used to delay execution until the end of
|
5
|
+
# a configured stack
|
6
|
+
class Delayed
|
7
|
+
# @param [Object] callable The object to call (must respond to #call)
|
8
|
+
def initialize(app, env, callable)
|
9
|
+
if !callable.respond_to?(:call)
|
10
|
+
raise TypeError, "Callable argument is expected to respond to `#call`"
|
11
|
+
end
|
12
|
+
@app = app
|
13
|
+
@env = env
|
14
|
+
@callable = callable
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
# Allow the rest of the call stack to execute
|
19
|
+
@app.call(env)
|
20
|
+
# Now call our delayed stack
|
21
|
+
@callable.call(env)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module Action
|
5
|
+
module Builtin
|
6
|
+
class Disk
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@logger = Log4r::Logger.new("vagrant::action::builtin::disk")
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
machine = env[:machine]
|
14
|
+
defined_disks = get_disks(machine, env)
|
15
|
+
|
16
|
+
# Call into providers machine implementation for disk management
|
17
|
+
configured_disks = {}
|
18
|
+
if !defined_disks.empty?
|
19
|
+
if machine.provider.capability?(:configure_disks)
|
20
|
+
configured_disks = machine.provider.capability(:configure_disks, defined_disks)
|
21
|
+
else
|
22
|
+
env[:ui].warn(I18n.t("vagrant.actions.disk.provider_unsupported",
|
23
|
+
provider: machine.provider_name))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
write_disk_metadata(machine, configured_disks) unless configured_disks.empty?
|
28
|
+
|
29
|
+
# Continue On
|
30
|
+
@app.call(env)
|
31
|
+
end
|
32
|
+
|
33
|
+
def write_disk_metadata(machine, current_disks)
|
34
|
+
meta_file = machine.data_dir.join("disk_meta")
|
35
|
+
@logger.debug("Writing disk metadata file to #{meta_file}")
|
36
|
+
File.open(meta_file.to_s, "w+") do |file|
|
37
|
+
file.write(JSON.dump(current_disks))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_disks(machine, env)
|
42
|
+
return @_disks if @_disks
|
43
|
+
|
44
|
+
@_disks = []
|
45
|
+
@_disks = machine.config.vm.disks
|
46
|
+
|
47
|
+
@_disks
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -67,6 +67,7 @@ module Vagrant
|
|
67
67
|
box_download_checksum_type = machine.config.vm.box_download_checksum_type
|
68
68
|
box_download_checksum = machine.config.vm.box_download_checksum
|
69
69
|
box_download_location_trusted = machine.config.vm.box_download_location_trusted
|
70
|
+
box_extra_download_options = machine.config.vm.box_extra_download_options
|
70
71
|
box_formats = machine.provider_options[:box_format] ||
|
71
72
|
machine.provider_name
|
72
73
|
|
@@ -92,6 +93,7 @@ module Vagrant
|
|
92
93
|
box_checksum_type: box_download_checksum_type,
|
93
94
|
box_checksum: box_download_checksum,
|
94
95
|
box_download_location_trusted: box_download_location_trusted,
|
96
|
+
box_extra_download_options: box_extra_download_options,
|
95
97
|
}))
|
96
98
|
rescue Errors::BoxAlreadyExists
|
97
99
|
# Just ignore this, since it means the next part will succeed!
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "set"
|
2
2
|
|
3
3
|
require "log4r"
|
4
|
+
require "socket"
|
4
5
|
|
5
6
|
require "vagrant/util/is_port_open"
|
6
7
|
|
@@ -242,18 +243,36 @@ module Vagrant
|
|
242
243
|
return extra_in_use.fetch(hostport).include?(hostip)
|
243
244
|
end
|
244
245
|
|
246
|
+
def ipv4_interfaces
|
247
|
+
Socket.getifaddrs.select do |ifaddr|
|
248
|
+
ifaddr.addr && ifaddr.addr.ipv4?
|
249
|
+
end.map do |ifaddr|
|
250
|
+
[ifaddr.name, ifaddr.addr.ip_address]
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
245
254
|
def port_check(host_ip, host_port)
|
246
|
-
# If no host_ip is specified, intention taken to be
|
247
|
-
# If platform is windows, default back to localhost only
|
255
|
+
# If no host_ip is specified, intention taken to be listen on all interfaces.
|
248
256
|
test_host_ip = host_ip || "0.0.0.0"
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
257
|
+
if Util::Platform.windows? && test_host_ip == "0.0.0.0"
|
258
|
+
@logger.debug("Testing port #{host_port} on all IPv4 interfaces...")
|
259
|
+
available_interfaces = ipv4_interfaces.select do |interface|
|
260
|
+
@logger.debug("Testing #{interface[0]} with IP address #{interface[1]}")
|
261
|
+
!is_port_open?(interface[1], host_port)
|
262
|
+
end
|
263
|
+
if available_interfaces.empty?
|
264
|
+
@logger.debug("Cannot forward port #{host_port} on any interfaces.")
|
265
|
+
true
|
266
|
+
else
|
267
|
+
@logger.debug("Port #{host_port} will forward to the guest on the following interfaces: #{available_interfaces}")
|
268
|
+
false
|
269
|
+
end
|
270
|
+
else
|
271
|
+
# Do a regular check
|
272
|
+
if test_host_ip == "0.0.0.0" || ipv4_interfaces.detect { |iface| iface[1] == test_host_ip }
|
273
|
+
is_port_open?(test_host_ip, host_port)
|
255
274
|
else
|
256
|
-
raise
|
275
|
+
raise Errors::ForwardPortHostIPNotFound, name: @machine.name, host_ip: host_ip
|
257
276
|
end
|
258
277
|
end
|
259
278
|
end
|
@@ -25,9 +25,27 @@ module Vagrant
|
|
25
25
|
# Store in the type map so that --provision-with works properly
|
26
26
|
@_provisioner_types[result] = provisioner.type
|
27
27
|
|
28
|
+
# Set top level provisioner name to provisioner configs name if top level name not set.
|
29
|
+
# This is mostly for handling the shell provisioner, if a user has set its name like:
|
30
|
+
#
|
31
|
+
# config.vm.provision "shell", name: "my_provisioner"
|
32
|
+
#
|
33
|
+
# Where `name` is a shell config option, not a top level provisioner class option
|
34
|
+
#
|
35
|
+
# Note: `name` is set to a symbol, since it is converted to one via #Config::VM.provision
|
36
|
+
provisioner_name = provisioner.name
|
37
|
+
if !provisioner_name
|
38
|
+
if provisioner.config.respond_to?(:name) &&
|
39
|
+
provisioner.config.name
|
40
|
+
provisioner_name = provisioner.config.name.to_sym
|
41
|
+
end
|
42
|
+
else
|
43
|
+
provisioner_name = provisioner_name.to_sym
|
44
|
+
end
|
45
|
+
|
28
46
|
# Build up the options
|
29
47
|
options = {
|
30
|
-
name:
|
48
|
+
name: provisioner_name,
|
31
49
|
run: provisioner.run,
|
32
50
|
before: provisioner.before,
|
33
51
|
after: provisioner.after,
|
@@ -36,17 +36,35 @@ module Vagrant
|
|
36
36
|
|
37
37
|
# Get the command and wrap it in a login shell
|
38
38
|
command = ShellQuote.escape(env[:ssh_run_command], "'")
|
39
|
-
|
39
|
+
|
40
|
+
if env[:machine].config.vm.communicator == :winssh
|
41
|
+
shell = env[:machine].config.winssh.shell
|
42
|
+
else
|
43
|
+
shell = env[:machine].config.ssh.shell
|
44
|
+
end
|
45
|
+
|
46
|
+
if shell == "cmd"
|
47
|
+
# Add an extra space to the command so cmd.exe quoting works
|
48
|
+
# properly
|
49
|
+
command = "#{shell} /C #{command} "
|
50
|
+
elsif shell == "powershell"
|
51
|
+
command = "$ProgressPreference = \"SilentlyContinue\"; #{command}"
|
52
|
+
command = Base64.strict_encode64(command.encode("UTF-16LE", "UTF-8"))
|
53
|
+
command = "#{shell} -encodedCommand #{command}"
|
54
|
+
else
|
55
|
+
command = "#{shell} -c '#{command}'"
|
56
|
+
end
|
40
57
|
|
41
58
|
# Execute!
|
42
59
|
opts = env[:ssh_opts] || {}
|
43
60
|
opts[:extra_args] ||= []
|
44
61
|
|
45
62
|
# Allow the user to specify a tty or non-tty manually, but if they
|
46
|
-
# don't then we default to a TTY
|
63
|
+
# don't then we default to a TTY unless they are using WinSSH
|
47
64
|
if !opts[:extra_args].include?("-t") &&
|
48
65
|
!opts[:extra_args].include?("-T") &&
|
49
|
-
env[:tty]
|
66
|
+
env[:tty] &&
|
67
|
+
env[:machine].config.vm.communicator != :winssh
|
50
68
|
opts[:extra_args] << "-t"
|
51
69
|
end
|
52
70
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Action
|
3
|
+
module Builtin
|
4
|
+
# This class is used within the Builder class for injecting triggers into
|
5
|
+
# different parts of the call stack.
|
6
|
+
class Trigger
|
7
|
+
# @param [Class, String, Symbol] name Name of trigger to fire
|
8
|
+
# @param [Vagrant::Plugin::V2::Triger] triggers Trigger object
|
9
|
+
# @param [Symbol] timing When trigger should fire (:before/:after)
|
10
|
+
# @param [Symbol] type Type of trigger
|
11
|
+
def initialize(app, env, name, triggers, timing, type=:action)
|
12
|
+
@app = app
|
13
|
+
@env = env
|
14
|
+
@triggers = triggers
|
15
|
+
@name = name
|
16
|
+
@timing = timing
|
17
|
+
@type = type
|
18
|
+
|
19
|
+
if ![:before, :after].include?(timing)
|
20
|
+
raise ArgumentError,
|
21
|
+
"Invalid value provided for `timing` (allowed: :before or :after)"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(env)
|
26
|
+
machine = env[:machine]
|
27
|
+
machine_name = machine.name if machine
|
28
|
+
|
29
|
+
@triggers.fire(@name, @timing, machine_name, @type)
|
30
|
+
# Carry on
|
31
|
+
@app.call(env)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/vagrant/action/hook.rb
CHANGED
@@ -65,6 +65,14 @@ module Vagrant
|
|
65
65
|
@prepend_hooks << [new, args, block]
|
66
66
|
end
|
67
67
|
|
68
|
+
# @return [Boolean]
|
69
|
+
def empty?
|
70
|
+
before_hooks.empty? &&
|
71
|
+
after_hooks.empty? &&
|
72
|
+
prepend_hooks.empty? &&
|
73
|
+
append_hooks.empty?
|
74
|
+
end
|
75
|
+
|
68
76
|
# This applies the given hook to a builder. This should not be
|
69
77
|
# called directly.
|
70
78
|
#
|
@@ -75,12 +83,22 @@ module Vagrant
|
|
75
83
|
if !options[:no_prepend_or_append]
|
76
84
|
# Prepends first
|
77
85
|
@prepend_hooks.each do |klass, args, block|
|
78
|
-
|
86
|
+
if options[:root]
|
87
|
+
idx = builder.index(options[:root])
|
88
|
+
else
|
89
|
+
idx = 0
|
90
|
+
end
|
91
|
+
builder.insert(idx, klass, *args, &block)
|
79
92
|
end
|
80
93
|
|
81
94
|
# Appends
|
82
95
|
@append_hooks.each do |klass, args, block|
|
83
|
-
|
96
|
+
if options[:root]
|
97
|
+
idx = builder.index(options[:root])
|
98
|
+
builder.insert(idx + 1, klass, *args, &block)
|
99
|
+
else
|
100
|
+
builder.use(klass, *args, &block)
|
101
|
+
end
|
84
102
|
end
|
85
103
|
end
|
86
104
|
|
@@ -34,30 +34,19 @@ module Vagrant
|
|
34
34
|
environment.merge!(@lazy_globals.call) if @lazy_globals
|
35
35
|
environment.merge!(options || {})
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
machine = environment[:machine]
|
44
|
-
machine_name = machine.name if machine
|
37
|
+
# NOTE: Triggers are initialized later in the Action::Runer because of
|
38
|
+
# how `@lazy_globals` are evaluated. Rather than trying to guess where
|
39
|
+
# the `env` is coming from, we can wait until they're merged into a single
|
40
|
+
# hash above.
|
41
|
+
env = environment[:env]
|
42
|
+
machine = environment[:machine]
|
45
43
|
|
46
|
-
|
47
|
-
triggers = Vagrant::Plugin::V2::Trigger.new(env, env.vagrantfile.config.trigger, machine, ui)
|
48
|
-
end
|
49
|
-
|
50
|
-
# Setup the action hooks
|
51
|
-
hooks = Vagrant.plugin("2").manager.action_hooks(environment[:action_name])
|
52
|
-
if !hooks.empty?
|
53
|
-
@logger.info("Preparing hooks for middleware sequence...")
|
54
|
-
environment[:action_hooks] = hooks.map do |hook_proc|
|
55
|
-
Hook.new.tap do |h|
|
56
|
-
hook_proc.call(h)
|
57
|
-
end
|
58
|
-
end
|
44
|
+
environment[:triggers] = machine.triggers if machine
|
59
45
|
|
60
|
-
|
46
|
+
if env
|
47
|
+
ui = Vagrant::UI::Prefixed.new(env.ui, "vagrant")
|
48
|
+
environment[:triggers] ||= Vagrant::Plugin::V2::Trigger.
|
49
|
+
new(env, env.vagrantfile.config.trigger, machine, ui)
|
61
50
|
end
|
62
51
|
|
63
52
|
# Run the action chain in a busy block, marking the environment as
|
@@ -95,14 +84,10 @@ module Vagrant
|
|
95
84
|
|
96
85
|
action_name = environment[:action_name]
|
97
86
|
|
98
|
-
triggers.fire_triggers(action_name, :before, machine_name, :hook) if Vagrant::Util::Experimental.feature_enabled?("typed_triggers")
|
99
|
-
|
100
87
|
# We place a process lock around every action that is called
|
101
88
|
@logger.info("Running action: #{environment[:action_name]} #{callable_id}")
|
102
89
|
Util::Busy.busy(int_callback) { callable.call(environment) }
|
103
90
|
|
104
|
-
triggers.fire_triggers(action_name, :after, machine_name, :hook) if Vagrant::Util::Experimental.feature_enabled?("typed_triggers")
|
105
|
-
|
106
91
|
# Return the environment in case there are things in there that
|
107
92
|
# the caller wants to use.
|
108
93
|
environment
|