vagrant-unbundled 2.2.6.1 → 2.2.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. checksums.yaml +4 -4
  2. data/.hashibot.hcl +14 -0
  3. data/CHANGELOG.md +153 -2
  4. data/README.md +5 -7
  5. data/bin/vagrant +23 -0
  6. data/contrib/README.md +1 -0
  7. data/contrib/bash/completion.sh +13 -1
  8. data/contrib/sudoers/linux-suse +2 -2
  9. data/contrib/zsh/_vagrant +736 -0
  10. data/contrib/zsh/generate_zsh_completion.rb +166 -0
  11. data/lib/vagrant.rb +25 -0
  12. data/lib/vagrant/action.rb +8 -0
  13. data/lib/vagrant/action/builder.rb +193 -38
  14. data/lib/vagrant/action/builtin/box_add.rb +15 -7
  15. data/lib/vagrant/action/builtin/box_check_outdated.rb +12 -15
  16. data/lib/vagrant/action/builtin/cleanup_disks.rb +56 -0
  17. data/lib/vagrant/action/builtin/cloud_init_setup.rb +127 -0
  18. data/lib/vagrant/action/builtin/cloud_init_wait.rb +30 -0
  19. data/lib/vagrant/action/builtin/delayed.rb +26 -0
  20. data/lib/vagrant/action/builtin/disk.rb +52 -0
  21. data/lib/vagrant/action/builtin/handle_box.rb +3 -1
  22. data/lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb +28 -9
  23. data/lib/vagrant/action/builtin/has_provisioner.rb +36 -0
  24. data/lib/vagrant/action/builtin/mixin_provisioners.rb +20 -1
  25. data/lib/vagrant/action/builtin/mixin_synced_folders.rb +20 -21
  26. data/lib/vagrant/action/builtin/set_hostname.rb +5 -1
  27. data/lib/vagrant/action/builtin/ssh_run.rb +21 -3
  28. data/lib/vagrant/action/builtin/synced_folders.rb +10 -0
  29. data/lib/vagrant/action/builtin/trigger.rb +37 -0
  30. data/lib/vagrant/action/hook.rb +76 -23
  31. data/lib/vagrant/action/runner.rb +11 -26
  32. data/lib/vagrant/action/warden.rb +28 -22
  33. data/lib/vagrant/box.rb +5 -4
  34. data/lib/vagrant/box_metadata.rb +17 -3
  35. data/lib/vagrant/bundler.rb +265 -53
  36. data/lib/vagrant/cli.rb +4 -2
  37. data/lib/vagrant/errors.rb +61 -1
  38. data/lib/vagrant/machine.rb +56 -6
  39. data/lib/vagrant/machine_index.rb +27 -1
  40. data/lib/vagrant/plugin/manager.rb +25 -14
  41. data/lib/vagrant/plugin/v2/command.rb +6 -2
  42. data/lib/vagrant/plugin/v2/components.rb +6 -0
  43. data/lib/vagrant/plugin/v2/manager.rb +67 -0
  44. data/lib/vagrant/plugin/v2/plugin.rb +13 -0
  45. data/lib/vagrant/plugin/v2/synced_folder.rb +50 -0
  46. data/lib/vagrant/plugin/v2/trigger.rb +64 -25
  47. data/lib/vagrant/shared_helpers.rb +28 -0
  48. data/lib/vagrant/ui.rb +51 -5
  49. data/lib/vagrant/util.rb +1 -0
  50. data/lib/vagrant/util/ansi_escape_code_remover.rb +1 -1
  51. data/lib/vagrant/util/caps.rb +48 -0
  52. data/lib/vagrant/util/credential_scrubber.rb +1 -1
  53. data/lib/vagrant/util/curl_helper.rb +8 -5
  54. data/lib/vagrant/util/directory.rb +19 -0
  55. data/lib/vagrant/util/downloader.rb +7 -3
  56. data/lib/vagrant/util/file_checksum.rb +6 -2
  57. data/lib/vagrant/util/guest_hosts.rb +68 -0
  58. data/lib/vagrant/util/guest_inspection.rb +9 -1
  59. data/lib/vagrant/util/install_cli_autocomplete.rb +118 -0
  60. data/lib/vagrant/util/io.rb +7 -27
  61. data/lib/vagrant/util/ipv4_interfaces.rb +15 -0
  62. data/lib/vagrant/util/is_port_open.rb +8 -20
  63. data/lib/vagrant/util/map_command_options.rb +33 -0
  64. data/lib/vagrant/util/network_ip.rb +11 -1
  65. data/lib/vagrant/util/numeric.rb +69 -0
  66. data/lib/vagrant/util/platform.rb +8 -1
  67. data/lib/vagrant/util/powershell.rb +1 -1
  68. data/lib/vagrant/util/subprocess.rb +9 -1
  69. data/lib/vagrant/vagrantfile.rb +1 -1
  70. data/plugins/commands/autocomplete/command/install.rb +49 -0
  71. data/plugins/commands/autocomplete/command/root.rb +64 -0
  72. data/plugins/commands/autocomplete/plugin.rb +18 -0
  73. data/plugins/commands/box/command/outdated.rb +14 -2
  74. data/plugins/commands/cloud/locales/en.yml +1 -1
  75. data/plugins/commands/cloud/publish.rb +1 -1
  76. data/plugins/commands/destroy/command.rb +6 -2
  77. data/plugins/commands/snapshot/command/save.rb +13 -8
  78. data/plugins/commands/ssh_config/command.rb +1 -1
  79. data/plugins/communicators/ssh/communicator.rb +25 -24
  80. data/plugins/communicators/winrm/config.rb +1 -1
  81. data/plugins/communicators/winrm/helper.rb +1 -1
  82. data/plugins/communicators/winrm/shell.rb +1 -1
  83. data/plugins/communicators/winssh/communicator.rb +126 -38
  84. data/plugins/communicators/winssh/config.rb +3 -7
  85. data/plugins/guests/alpine/cap/change_host_name.rb +10 -11
  86. data/plugins/guests/alpine/cap/rsync.rb +1 -1
  87. data/plugins/guests/alpine/plugin.rb +16 -0
  88. data/plugins/guests/alt/cap/change_host_name.rb +40 -53
  89. data/plugins/guests/arch/cap/change_host_name.rb +5 -14
  90. data/plugins/guests/arch/cap/configure_networks.rb +27 -10
  91. data/plugins/guests/atomic/cap/change_host_name.rb +5 -14
  92. data/plugins/guests/centos/cap/flavor.rb +24 -0
  93. data/plugins/guests/centos/guest.rb +9 -0
  94. data/plugins/guests/centos/plugin.rb +20 -0
  95. data/plugins/guests/darwin/cap/change_host_name.rb +10 -6
  96. data/plugins/guests/darwin/cap/mount_vmware_shared_folder.rb +99 -13
  97. data/plugins/guests/darwin/plugin.rb +5 -0
  98. data/plugins/guests/debian/cap/change_host_name.rb +11 -11
  99. data/plugins/guests/debian/cap/configure_networks.rb +14 -6
  100. data/plugins/guests/esxi/cap/public_key.rb +3 -1
  101. data/plugins/guests/freebsd/cap/change_host_name.rb +10 -6
  102. data/plugins/guests/gentoo/cap/change_host_name.rb +14 -22
  103. data/plugins/guests/haiku/cap/rsync.rb +19 -0
  104. data/plugins/guests/haiku/plugin.rb +15 -0
  105. data/plugins/guests/linux/cap/change_host_name.rb +46 -0
  106. data/plugins/guests/linux/cap/halt.rb +9 -1
  107. data/plugins/guests/linux/cap/mount_smb_shared_folder.rb +16 -0
  108. data/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb +4 -11
  109. data/plugins/guests/linux/cap/persist_mount_shared_folder.rb +62 -0
  110. data/plugins/guests/linux/cap/reboot.rb +48 -0
  111. data/plugins/guests/linux/plugin.rb +20 -0
  112. data/plugins/guests/omnios/cap/change_host_name.rb +10 -16
  113. data/plugins/guests/openbsd/cap/change_host_name.rb +10 -6
  114. data/plugins/guests/photon/cap/change_host_name.rb +9 -15
  115. data/plugins/guests/pld/cap/change_host_name.rb +11 -17
  116. data/plugins/guests/redhat/cap/change_host_name.rb +10 -5
  117. data/plugins/guests/redhat/cap/flavor.rb +3 -1
  118. data/plugins/guests/redhat/cap/nfs_client.rb +2 -2
  119. data/plugins/guests/redhat/cap/smb.rb +20 -0
  120. data/plugins/guests/redhat/plugin.rb +5 -0
  121. data/plugins/guests/slackware/cap/change_host_name.rb +11 -17
  122. data/plugins/guests/solaris11/plugin.rb +5 -0
  123. data/plugins/guests/suse/cap/change_host_name.rb +13 -12
  124. data/plugins/guests/windows/cap/public_key.rb +3 -3
  125. data/plugins/guests/windows/cap/reboot.rb +2 -1
  126. data/plugins/hosts/darwin/cap/fs_iso.rb +49 -0
  127. data/plugins/hosts/darwin/cap/nfs.rb +11 -0
  128. data/plugins/hosts/darwin/plugin.rb +15 -0
  129. data/plugins/hosts/linux/cap/fs_iso.rb +49 -0
  130. data/plugins/hosts/linux/cap/nfs.rb +21 -2
  131. data/plugins/hosts/linux/cap/rdp.rb +1 -1
  132. data/plugins/hosts/linux/plugin.rb +10 -0
  133. data/plugins/hosts/windows/cap/fs_iso.rb +48 -0
  134. data/plugins/hosts/windows/cap/rdp.rb +1 -1
  135. data/plugins/hosts/windows/plugin.rb +15 -0
  136. data/plugins/kernel_v2/config/cloud_init.rb +126 -0
  137. data/plugins/kernel_v2/config/disk.rb +221 -0
  138. data/plugins/kernel_v2/config/ssh_connect.rb +24 -0
  139. data/plugins/kernel_v2/config/vm.rb +225 -11
  140. data/plugins/kernel_v2/config/vm_provisioner.rb +17 -3
  141. data/plugins/kernel_v2/config/vm_trigger.rb +6 -5
  142. data/plugins/providers/docker/action.rb +8 -17
  143. data/plugins/providers/docker/action/forwarded_ports.rb +2 -0
  144. data/plugins/providers/docker/action/prepare_forwarded_port_collision_params.rb +61 -0
  145. data/plugins/providers/docker/cap/has_communicator.rb +11 -0
  146. data/plugins/providers/docker/communicator.rb +1 -1
  147. data/plugins/providers/docker/driver.rb +73 -10
  148. data/plugins/providers/docker/errors.rb +4 -0
  149. data/plugins/providers/docker/executor/local.rb +7 -1
  150. data/plugins/providers/docker/plugin.rb +5 -0
  151. data/plugins/providers/hyperv/action.rb +2 -0
  152. data/plugins/providers/hyperv/action/configure.rb +8 -0
  153. data/plugins/providers/hyperv/action/export.rb +4 -2
  154. data/plugins/providers/hyperv/cap/cleanup_disks.rb +54 -0
  155. data/plugins/providers/hyperv/cap/configure_disks.rb +200 -0
  156. data/plugins/providers/hyperv/cap/validate_disk_ext.rb +34 -0
  157. data/plugins/providers/hyperv/config.rb +5 -0
  158. data/plugins/providers/hyperv/driver.rb +90 -9
  159. data/plugins/providers/hyperv/plugin.rb +25 -0
  160. data/plugins/providers/hyperv/scripts/attach_disk_drive.ps1 +28 -0
  161. data/plugins/providers/hyperv/scripts/dismount_vhd.ps1 +13 -0
  162. data/plugins/providers/hyperv/scripts/get_vhd.ps1 +16 -0
  163. data/plugins/providers/hyperv/scripts/get_vm_status.ps1 +1 -1
  164. data/plugins/providers/hyperv/scripts/list_hdds.ps1 +17 -0
  165. data/plugins/providers/hyperv/scripts/new_vhd.ps1 +31 -0
  166. data/plugins/providers/hyperv/scripts/remove_disk_drive.ps1 +25 -0
  167. data/plugins/providers/hyperv/scripts/resize_disk_drive.ps1 +18 -0
  168. data/plugins/providers/hyperv/scripts/set_enhanced_session_transport_type.ps1 +24 -0
  169. data/plugins/providers/hyperv/scripts/set_vm_integration_services.ps1 +3 -3
  170. data/plugins/providers/hyperv/scripts/utils/VagrantVM/VagrantVM.psm1 +14 -6
  171. data/plugins/providers/virtualbox/action.rb +14 -1
  172. data/plugins/providers/virtualbox/action/clean_machine_folder.rb +10 -1
  173. data/plugins/providers/virtualbox/action/export.rb +4 -2
  174. data/plugins/providers/virtualbox/action/forward_ports.rb +2 -2
  175. data/plugins/providers/virtualbox/action/import.rb +8 -4
  176. data/plugins/providers/virtualbox/action/prepare_clone_snapshot.rb +4 -2
  177. data/plugins/providers/virtualbox/action/snapshot_delete.rb +4 -2
  178. data/plugins/providers/virtualbox/action/snapshot_restore.rb +4 -2
  179. data/plugins/providers/virtualbox/cap/cleanup_disks.rb +85 -0
  180. data/plugins/providers/virtualbox/cap/configure_disks.rb +440 -0
  181. data/plugins/providers/virtualbox/cap/mount_options.rb +35 -0
  182. data/plugins/providers/virtualbox/cap/validate_disk_ext.rb +34 -0
  183. data/plugins/providers/virtualbox/driver/base.rb +15 -0
  184. data/plugins/providers/virtualbox/driver/meta.rb +17 -2
  185. data/plugins/providers/virtualbox/driver/version_5_0.rb +217 -2
  186. data/plugins/providers/virtualbox/driver/version_6_1.rb +39 -0
  187. data/plugins/providers/virtualbox/model/storage_controller.rb +135 -0
  188. data/plugins/providers/virtualbox/model/storage_controller_array.rb +100 -0
  189. data/plugins/providers/virtualbox/plugin.rb +38 -0
  190. data/plugins/providers/virtualbox/synced_folder.rb +1 -0
  191. data/plugins/provisioners/ansible/cap/guest/alpine/ansible_install.rb +44 -0
  192. data/plugins/provisioners/ansible/cap/guest/arch/ansible_install.rb +20 -3
  193. data/plugins/provisioners/ansible/cap/guest/debian/ansible_install.rb +4 -5
  194. data/plugins/provisioners/ansible/cap/guest/fedora/ansible_install.rb +2 -2
  195. data/plugins/provisioners/ansible/cap/guest/freebsd/ansible_install.rb +2 -2
  196. data/plugins/provisioners/ansible/cap/guest/pip/pip.rb +8 -4
  197. data/plugins/provisioners/ansible/cap/guest/redhat/ansible_install.rb +2 -2
  198. data/plugins/provisioners/ansible/cap/guest/suse/ansible_install.rb +2 -1
  199. data/plugins/provisioners/ansible/cap/guest/ubuntu/ansible_install.rb +3 -3
  200. data/plugins/provisioners/ansible/plugin.rb +5 -0
  201. data/plugins/provisioners/ansible/provisioner/base.rb +1 -1
  202. data/plugins/provisioners/container/client.rb +203 -0
  203. data/plugins/provisioners/container/config.rb +83 -0
  204. data/plugins/provisioners/container/installer.rb +13 -0
  205. data/plugins/provisioners/container/plugin.rb +23 -0
  206. data/plugins/provisioners/container/provisioner.rb +28 -0
  207. data/plugins/provisioners/docker/cap/{redhat → centos}/docker_install.rb +10 -7
  208. data/plugins/provisioners/docker/cap/centos/docker_start_service.rb +24 -0
  209. data/plugins/provisioners/docker/client.rb +4 -175
  210. data/plugins/provisioners/docker/config.rb +2 -72
  211. data/plugins/provisioners/docker/installer.rb +3 -5
  212. data/plugins/provisioners/docker/plugin.rb +6 -6
  213. data/plugins/provisioners/docker/provisioner.rb +4 -10
  214. data/plugins/provisioners/podman/cap/centos/podman_install.rb +35 -0
  215. data/plugins/provisioners/podman/cap/linux/podman_installed.rb +13 -0
  216. data/plugins/provisioners/podman/cap/redhat/podman_install.rb +26 -0
  217. data/plugins/provisioners/podman/client.rb +12 -0
  218. data/plugins/provisioners/podman/config.rb +28 -0
  219. data/plugins/provisioners/podman/installer.rb +33 -0
  220. data/plugins/provisioners/podman/plugin.rb +38 -0
  221. data/plugins/provisioners/podman/provisioner.rb +52 -0
  222. data/plugins/provisioners/salt/provisioner.rb +4 -0
  223. data/plugins/provisioners/shell/config.rb +1 -6
  224. data/plugins/provisioners/shell/provisioner.rb +61 -26
  225. data/plugins/synced_folders/nfs/synced_folder.rb +3 -1
  226. data/plugins/synced_folders/smb/cap/default_fstab_modification.rb +11 -0
  227. data/plugins/synced_folders/smb/cap/mount_options.rb +36 -0
  228. data/plugins/synced_folders/smb/plugin.rb +10 -0
  229. data/plugins/synced_folders/smb/synced_folder.rb +2 -2
  230. data/plugins/synced_folders/unix_mount_helpers.rb +14 -0
  231. data/templates/commands/init/Vagrantfile.erb +1 -1
  232. data/templates/guests/arch/{network_dhcp.erb → default_network/network_dhcp.erb} +0 -0
  233. data/templates/guests/arch/{network_static.erb → default_network/network_static.erb} +0 -0
  234. data/templates/guests/arch/{network_static6.erb → default_network/network_static6.erb} +0 -0
  235. data/templates/guests/arch/systemd_networkd/network_dhcp.erb +6 -0
  236. data/templates/guests/arch/systemd_networkd/network_static.erb +9 -0
  237. data/templates/guests/arch/systemd_networkd/network_static6.erb +9 -0
  238. data/templates/guests/linux/etc_fstab.erb +6 -0
  239. data/templates/locales/en.yml +235 -6
  240. data/templates/locales/providers_docker.yml +6 -0
  241. data/templates/nfs/exports_darwin.erb +7 -0
  242. data/vagrant.gemspec +12 -12
  243. data/version.txt +1 -1
  244. metadata +3937 -3686
  245. data/lib/vagrant/action/builtin/after_trigger.rb +0 -31
  246. data/lib/vagrant/action/builtin/before_trigger.rb +0 -28
  247. data/plugins/provisioners/docker/cap/redhat/docker_start_service.rb +0 -16
@@ -71,6 +71,7 @@ module Vagrant
71
71
  # @return [Array] List of the hooks for the given action.
72
72
  def self.action_hook(name, hook_name=nil, &block)
73
73
  # The name is currently not used but we want it for the future.
74
+ hook_name = hook_name.to_s if hook_name
74
75
 
75
76
  hook_name ||= ALL_ACTIONS
76
77
  components.action_hooks[hook_name.to_sym] << block
@@ -246,6 +247,18 @@ module Vagrant
246
247
  nil
247
248
  end
248
249
 
250
+ # Defines a capability for the given synced folder. The block should return
251
+ # a class/module that has a method with the capability name, ready
252
+ # to be executed. This means that if it is an instance method,
253
+ # the block should return an instance of the class.
254
+ #
255
+ # @param [String] synced_folder The name of the synced folder
256
+ # @param [String] cap The name of the capability
257
+ def self.synced_folder_capability(synced_folder, cap, &block)
258
+ components.synced_folder_capabilities[synced_folder.to_sym].register(cap.to_sym, &block)
259
+ nil
260
+ end
261
+
249
262
  # Returns the internal data associated with this plugin. This
250
263
  # should NOT be called by the general public.
251
264
  #
@@ -3,6 +3,49 @@ module Vagrant
3
3
  module V2
4
4
  # This is the base class for a synced folder implementation.
5
5
  class SyncedFolder
6
+ class Collection < Hash
7
+
8
+ # @return [Array<Symbol>] names of synced folder types
9
+ def types
10
+ keys
11
+ end
12
+
13
+ # Fetch the synced plugin folder of the given type
14
+ #
15
+ # @param [Symbol] t Synced folder type
16
+ # @return [Vagrant::Plugin::V2::SyncedFolder]
17
+ def type(t)
18
+ f = detect { |k, _| k.to_sym == t.to_sym }.last
19
+ raise KeyError, "Unknown synced folder type" if !f
20
+ f.values.first[:plugin]
21
+ end
22
+
23
+ # Converts to a regular Hash and removes
24
+ # plugin instances so the result is ready
25
+ # for serialization
26
+ #
27
+ # @return [Hash]
28
+ def to_h
29
+ c = lambda do |h|
30
+ h.keys.each do |k|
31
+ if h[k].is_a?(Hash)
32
+ h[k] = c.call(h[k].to_h.clone)
33
+ end
34
+ end
35
+ h
36
+ end
37
+ h = c.call(super)
38
+ h.values.each do |f|
39
+ f.values.each do |g|
40
+ g.delete(:plugin)
41
+ end
42
+ end
43
+ h
44
+ end
45
+ end
46
+
47
+ include CapabilityHost
48
+
6
49
  # This is called early when the synced folder is set to determine
7
50
  # if this implementation can be used for this machine. This should
8
51
  # return true or false.
@@ -54,6 +97,13 @@ module Vagrant
54
97
  # @param [Hash] opts
55
98
  def cleanup(machine, opts)
56
99
  end
100
+
101
+ def _initialize(machine, synced_folder_type)
102
+ plugins = Vagrant.plugin("2").manager.synced_folders
103
+ capabilities = Vagrant.plugin("2").manager.synced_folder_capabilities
104
+ initialize_capabilities!(synced_folder_type, plugins, capabilities, machine)
105
+ self
106
+ end
57
107
  end
58
108
  end
59
109
  end
@@ -30,58 +30,98 @@ module Vagrant
30
30
  @logger = Log4r::Logger.new("vagrant::trigger::#{self.class.to_s.downcase}")
31
31
  end
32
32
 
33
- # Fires all triggers, if any are defined for the action and guest. Returns early
33
+ # Fires all triggers, if any are defined for the named type and guest. Returns early
34
34
  # and logs a warning if the community plugin `vagrant-triggers` is installed
35
35
  #
36
- # @param [Symbol] action Vagrant command to fire trigger on
36
+ # @param [Symbol] name Name of `type` thing to fire trigger on
37
37
  # @param [Symbol] stage :before or :after
38
- # @param [String] guest_name The guest that invoked firing the triggers
39
- def fire_triggers(action, stage, guest_name, type)
38
+ # @param [String] guest The guest that invoked firing the triggers
39
+ # @param [Symbol] type Type of trigger to fire (:action, :hook, :command)
40
+ def fire(name, stage, guest, type, all: false)
40
41
  if community_plugin_detected?
41
42
  @logger.warn("Community plugin `vagrant-triggers detected, so core triggers will not fire")
42
43
  return
43
44
  end
44
45
 
45
- if !action
46
- @logger.warn("Action given is nil, no triggers will fire")
47
- return
48
- else
49
- action = action.to_sym
50
- end
46
+ return @logger.warn("Name given is nil, no triggers will fire") if !name
47
+ return @logger.warn("Name given cannot be symbolized, no triggers will fire") if
48
+ !name.respond_to?(:to_sym)
49
+
50
+ name = name.to_sym
51
51
 
52
52
  # get all triggers matching action
53
- triggers = []
53
+ triggers = find(name, stage, guest, type, all: all)
54
+
55
+ if !triggers.empty?
56
+ @logger.info("Firing trigger for #{type} #{name} on guest #{guest}")
57
+ @ui.info(I18n.t("vagrant.trigger.start", type: type, stage: stage, name: name))
58
+ execute(triggers)
59
+ end
60
+ end
61
+
62
+ # Find all triggers defined for the named type and guest.
63
+ #
64
+ # @param [Symbol] name Name of `type` thing to fire trigger on
65
+ # @param [Symbol] stage :before or :after
66
+ # @param [String] guest The guest that invoked firing the triggers
67
+ # @param [Symbol] type Type of trigger to fire
68
+ # @return [Array]
69
+ def find(name, stage, guest, type, all: false)
70
+ triggers = nil
71
+ name = nameify(name)
72
+
54
73
  if stage == :before
55
74
  triggers = config.before_triggers.select do |t|
56
- t.command == action || (t.command == :all && !t.ignore.include?(action))
75
+ (all && t.command.respond_to?(:to_sym) && t.command.to_sym == :all && !t.ignore.include?(name.to_sym)) ||
76
+ (type == :hook && matched_hook?(t.command, name)) ||
77
+ nameify(t.command) == name
57
78
  end
58
79
  elsif stage == :after
59
80
  triggers = config.after_triggers.select do |t|
60
- t.command == action || (t.command == :all && !t.ignore.include?(action))
81
+ (all && t.command.respond_to?(:to_sym) && t.command.to_sym == :all && !t.ignore.include?(name.to_sym)) ||
82
+ (type == :hook && matched_hook?(t.command, name)) ||
83
+ nameify(t.command) == name
61
84
  end
62
85
  else
63
86
  raise Errors::TriggersNoStageGiven,
64
- action: action,
87
+ name: name,
65
88
  stage: stage,
66
- guest_name: guest_name
89
+ type: type,
90
+ guest_name: guest
67
91
  end
68
92
 
69
- triggers = filter_triggers(triggers, guest_name, type)
70
-
71
- if !triggers.empty?
72
- @logger.info("Firing trigger for action #{action} on guest #{guest_name}")
73
- @ui.info(I18n.t("vagrant.trigger.start", type: type, stage: stage, action: action))
74
- fire(triggers, guest_name)
75
- end
93
+ filter_triggers(triggers, guest, type)
76
94
  end
77
95
 
78
96
  protected
79
97
 
98
+ # Convert object into name
99
+ #
100
+ # @param [Object, Class] object Object to name
101
+ # @return [String]
102
+ def nameify(object)
103
+ if object.is_a?(Class)
104
+ object.name.to_s
105
+ else
106
+ object.to_s
107
+ end
108
+ end
80
109
 
81
110
  #-------------------------------------------------------------------
82
111
  # Internal methods, don't call these.
83
112
  #-------------------------------------------------------------------
84
113
 
114
+ # Generate all valid lookup keys for given action key
115
+ #
116
+ # @param [Class, String] key Base key for generation
117
+ # @return [Array<String>] all valid keys
118
+ def matched_hook?(key, subject)
119
+ subject = nameify(subject)
120
+ Vagrant.plugin("2").manager.generate_hook_keys(key).any? do |k|
121
+ k == subject
122
+ end
123
+ end
124
+
85
125
  # Looks up if the community plugin `vagrant-triggers` is installed
86
126
  # and also caches the result
87
127
  #
@@ -133,12 +173,11 @@ module Vagrant
133
173
  return triggers
134
174
  end
135
175
 
136
- # Fires off all triggers in the given array
176
+ # Execute all triggers in the given array
137
177
  #
138
178
  # @param [Array] triggers An array of triggers to be fired
139
- def fire(triggers, guest_name)
179
+ def execute(triggers)
140
180
  # ensure on_error is respected by exiting or continuing
141
-
142
181
  triggers.each do |trigger|
143
182
  @logger.debug("Running trigger #{trigger.id}...")
144
183
 
@@ -186,4 +186,32 @@ module Vagrant
186
186
  end
187
187
  @_global_logger
188
188
  end
189
+
190
+ # Add a new block of default CLI options which
191
+ # should be automatically added to all commands
192
+ #
193
+ # @param [Proc] block Proc instance containing OptParser configuration
194
+ # @return [nil]
195
+ def self.add_default_cli_options(block)
196
+ if !block.is_a?(Proc)
197
+ raise TypeError,
198
+ "Expecting type `Proc` but received `#{block.class}`"
199
+ end
200
+ if block.arity != 1 && block.arity != -1
201
+ raise ArgumentError,
202
+ "Proc must accept OptionParser argument"
203
+ end
204
+ @_default_cli_options = [] if !@_default_cli_options
205
+ @_default_cli_options << block
206
+ nil
207
+ end
208
+
209
+ # Array of default CLI options to automatically
210
+ # add to commands.
211
+ #
212
+ # @return [Array<Proc>] Default optparse options
213
+ def self.default_cli_options
214
+ @_default_cli_options = [] if !@_default_cli_options
215
+ @_default_cli_options.dup
216
+ end
189
217
  end
@@ -75,6 +75,13 @@ module Vagrant
75
75
  def machine(type, *data)
76
76
  @logger.info("Machine: #{type} #{data.inspect}")
77
77
  end
78
+
79
+ # Yields self (UI)
80
+ # Provides a way for selectively displaying or not displaying
81
+ # updating content like download progress.
82
+ def rewriting
83
+ yield self
84
+ end
78
85
  end
79
86
 
80
87
  # This is a UI implementation that does nothing.
@@ -220,7 +227,7 @@ module Vagrant
220
227
 
221
228
  # This method handles actually outputting a message of a given type
222
229
  # to the console.
223
- def say(type, message, **opts)
230
+ def say(type, message, opts={})
224
231
  defaults = { new_line: true, prefix: true }
225
232
  opts = defaults.merge(@opts).merge(opts)
226
233
 
@@ -252,6 +259,31 @@ module Vagrant
252
259
  end
253
260
  end
254
261
 
262
+
263
+ class NonInteractive < Basic
264
+ def initialize
265
+ super
266
+ end
267
+
268
+ def rewriting
269
+ # no-op
270
+ end
271
+
272
+ def report_progress(progress, total, show_parts=true)
273
+ # no-op
274
+ end
275
+
276
+ def clear_line
277
+ @logger.warn("Using `clear line` in a non interactive ui")
278
+ say(:info, "\n", opts)
279
+ end
280
+
281
+ def ask(*args)
282
+ # Non interactive can't ask for input
283
+ raise Errors::UIExpectsTTY
284
+ end
285
+ end
286
+
255
287
  # Prefixed wraps an existing UI and adds a prefix to it.
256
288
  class Prefixed < Interface
257
289
  # The prefix for `output` messages.
@@ -290,7 +322,9 @@ module Vagrant
290
322
 
291
323
  [:clear_line, :report_progress].each do |method|
292
324
  # By default do nothing, these aren't formatted
293
- define_method(method) { |*args| @ui.send(method, *args) }
325
+ define_method(method) do |*args|
326
+ @ui.send(method, *args)
327
+ end
294
328
  end
295
329
 
296
330
  # For machine-readable output, set the prefix in the
@@ -329,16 +363,28 @@ module Vagrant
329
363
  target = opts[:target] if opts.key?(:target)
330
364
  target = "#{target}:" if target != ""
331
365
 
332
- # Get the lines. The first default is because if the message
333
- # is an empty string, then we want to still use the empty string.
334
366
  lines = [message]
335
- lines = message.split("\n") if message != ""
367
+ if message != ""
368
+ lines = [].tap do |l|
369
+ message.scan(/(.*?)(\n|$)/).each do |m|
370
+ l << m.first if m.first != "" || (m.first == "" && m.last == "\n")
371
+ end
372
+ end
373
+ lines << "" if message.end_with?("\n")
374
+ end
336
375
 
337
376
  # Otherwise, make sure to prefix every line properly
338
377
  lines.map do |line|
339
378
  "#{prefix}#{target} #{line}"
340
379
  end.join("\n")
341
380
  end
381
+
382
+ def rewriting
383
+ @ui.rewriting do |ui|
384
+ yield ui
385
+ end
386
+ end
387
+
342
388
  end
343
389
 
344
390
  # This is a UI implementation that outputs color for various types
@@ -7,6 +7,7 @@ module Vagrant
7
7
  autoload :CredentialScrubber, 'vagrant/util/credential_scrubber'
8
8
  autoload :DeepMerge, 'vagrant/util/deep_merge'
9
9
  autoload :Env, 'vagrant/util/env'
10
+ autoload :Experimental, 'vagrant/util/experimental'
10
11
  autoload :HashWithIndifferentAccess, 'vagrant/util/hash_with_indifferent_access'
11
12
  autoload :GuestInspection, 'vagrant/util/guest_inspection'
12
13
  autoload :LoggingFormatter, 'vagrant/util/logging_formatter'
@@ -19,7 +19,7 @@ module Vagrant
19
19
  /\e\[\?[1-9][hl]/, # Matches \e[?2h
20
20
  /\e\[20[hl]/, # Matches \e[20l]
21
21
  /\e[DME78H]/, # Matches \eD, \eH, etc.
22
- /\e\[[0-2]?[JK]/, # Matches \e[0J, \e[K, etc.
22
+ /\e\[[0-3]?[JK]/, # Matches \e[0J, \e[K, etc.
23
23
  ]
24
24
 
25
25
  # Take each matcher and replace it with emptiness.
@@ -0,0 +1,48 @@
1
+ require "tempfile"
2
+ require "fileutils"
3
+ require "pathname"
4
+ require "vagrant/util/directory"
5
+ require "vagrant/util/subprocess"
6
+
7
+ module Vagrant
8
+ module Util
9
+ module Caps
10
+ module BuildISO
11
+
12
+ # Builds an iso given a compatible iso_command
13
+ #
14
+ # @param [List<String>] command to build iso
15
+ # @param [Pathname] input directory for iso build
16
+ # @param [Pathname] output file for iso build
17
+ def build_iso(iso_command, source_directory, file_destination)
18
+ FileUtils.mkdir_p(file_destination.dirname)
19
+ if !file_destination.exist? || Vagrant::Util::Directory.directory_changed?(source_directory, file_destination.mtime)
20
+ result = Vagrant::Util::Subprocess.execute(*iso_command)
21
+ if result.exit_code != 0
22
+ raise Vagrant::Errors::ISOBuildFailed, cmd: iso_command.join(" "), stdout: result.stdout, stderr: result.stderr
23
+ end
24
+ end
25
+ end
26
+
27
+ protected
28
+
29
+ def ensure_output_iso(file_destination)
30
+ if file_destination.nil?
31
+ tmpfile = Tempfile.new(["vagrant", ".iso"])
32
+ file_destination = Pathname.new(tmpfile.path)
33
+ tmpfile.close
34
+ tmpfile.unlink
35
+ else
36
+ file_destination = Pathname.new(file_destination.to_s)
37
+ # If the file destination path is a folder, target the output to a randomly named
38
+ # file in that dir
39
+ if file_destination.extname != ".iso"
40
+ file_destination = file_destination.join("#{SecureRandom.hex(3)}_vagrant.iso")
41
+ end
42
+ end
43
+ file_destination
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -32,7 +32,7 @@ module Vagrant
32
32
  def self.desensitize(string)
33
33
  string = string.to_s.dup
34
34
  sensitive_strings.each do |remove|
35
- string.gsub!(remove, REPLACEMENT_TEXT)
35
+ string.gsub!(/(\W|^)#{Regexp.escape(remove)}(\W|$)/, "\\1#{REPLACEMENT_TEXT}\\2")
36
36
  end
37
37
  string
38
38
  end
@@ -37,8 +37,10 @@ module Vagrant
37
37
  source_host = source_uri.host.to_s.split(".", 2).last
38
38
  location_host = location_uri.host.to_s.split(".", 2).last
39
39
  if !redirect_notify && location_host != source_host && !SILENCED_HOSTS.include?(location_host)
40
- ui.clear_line
41
- ui.detail "Download redirected to host: #{location_uri.host}"
40
+ ui.rewriting do |ui|
41
+ ui.clear_line
42
+ ui.detail "Download redirected to host: #{location_uri.host}"
43
+ end
42
44
  end
43
45
  redirect_notify = true
44
46
  end
@@ -82,10 +84,11 @@ module Vagrant
82
84
  # 9 - Time spent
83
85
  # 10 - Time left
84
86
  # 11 - Current speed
85
-
86
87
  output = "Progress: #{columns[0]}% (Rate: #{columns[11]}/s, Estimated time remaining: #{columns[10]})"
87
- ui.clear_line
88
- ui.detail(output, new_line: false)
88
+ ui.rewriting do |ui|
89
+ ui.clear_line
90
+ ui.detail(output, new_line: false)
91
+ end
89
92
  end
90
93
  end
91
94