2014-01-25 01:52:52 +00:00
|
|
|
require 'optparse'
|
|
|
|
|
Add HTTPS download options to `box update` and `box outdated`
Vagrant::Box.load_metadata did not provide a way to specify the HTTPS
download options that could be specified when downloading boxes
(ca cert, ca path, client cert, insecure). As a result, while it was
possible to add a box whose metadata file needed to be downloaded with one of
those options specified, it was impossible to check for updates. The following
changes have been made to address the situation:
1. Create a DownloadMixins module to provide the --insecure, --cacert, --capth,
and --cert command line options to all of `vagrant box add`,
`vagrant box update`, and `vagrant box outdated`.
2. Extend `Vagrant::Box.has_update?` and `Vagrant::Box.load_metadata` to accept
said download options.
3. Extend `box outdated` and `box update` commands to pass download options
down.
4. Extend `Vagrant::Builtin::Action::BoxCheckOutdated` to honour download
options.
5. Options specified on the command line take precedence over options specified
in the machine configuration, if any.
6. Fix bug in `vagrant box add` where client cert was being passed down using
the wrong environment key.
7. Unit test coverage in update_test and box_check_outdated_test.
Resolves #4420
2014-09-08 03:45:32 +00:00
|
|
|
require_relative 'download_mixins'
|
|
|
|
|
2014-01-25 01:52:52 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module CommandBox
|
|
|
|
module Command
|
|
|
|
class Update < Vagrant.plugin("2", :command)
|
Add HTTPS download options to `box update` and `box outdated`
Vagrant::Box.load_metadata did not provide a way to specify the HTTPS
download options that could be specified when downloading boxes
(ca cert, ca path, client cert, insecure). As a result, while it was
possible to add a box whose metadata file needed to be downloaded with one of
those options specified, it was impossible to check for updates. The following
changes have been made to address the situation:
1. Create a DownloadMixins module to provide the --insecure, --cacert, --capth,
and --cert command line options to all of `vagrant box add`,
`vagrant box update`, and `vagrant box outdated`.
2. Extend `Vagrant::Box.has_update?` and `Vagrant::Box.load_metadata` to accept
said download options.
3. Extend `box outdated` and `box update` commands to pass download options
down.
4. Extend `Vagrant::Builtin::Action::BoxCheckOutdated` to honour download
options.
5. Options specified on the command line take precedence over options specified
in the machine configuration, if any.
6. Fix bug in `vagrant box add` where client cert was being passed down using
the wrong environment key.
7. Unit test coverage in update_test and box_check_outdated_test.
Resolves #4420
2014-09-08 03:45:32 +00:00
|
|
|
include DownloadMixins
|
|
|
|
|
2014-01-25 01:52:52 +00:00
|
|
|
def execute
|
|
|
|
options = {}
|
Add HTTPS download options to `box update` and `box outdated`
Vagrant::Box.load_metadata did not provide a way to specify the HTTPS
download options that could be specified when downloading boxes
(ca cert, ca path, client cert, insecure). As a result, while it was
possible to add a box whose metadata file needed to be downloaded with one of
those options specified, it was impossible to check for updates. The following
changes have been made to address the situation:
1. Create a DownloadMixins module to provide the --insecure, --cacert, --capth,
and --cert command line options to all of `vagrant box add`,
`vagrant box update`, and `vagrant box outdated`.
2. Extend `Vagrant::Box.has_update?` and `Vagrant::Box.load_metadata` to accept
said download options.
3. Extend `box outdated` and `box update` commands to pass download options
down.
4. Extend `Vagrant::Builtin::Action::BoxCheckOutdated` to honour download
options.
5. Options specified on the command line take precedence over options specified
in the machine configuration, if any.
6. Fix bug in `vagrant box add` where client cert was being passed down using
the wrong environment key.
7. Unit test coverage in update_test and box_check_outdated_test.
Resolves #4420
2014-09-08 03:45:32 +00:00
|
|
|
download_options = {}
|
2014-01-25 01:52:52 +00:00
|
|
|
|
|
|
|
opts = OptionParser.new do |o|
|
|
|
|
o.banner = "Usage: vagrant box update [options]"
|
|
|
|
o.separator ""
|
|
|
|
o.separator "Updates the box that is in use in the current Vagrant environment,"
|
|
|
|
o.separator "if there any updates available. This does not destroy/recreate the"
|
|
|
|
o.separator "machine, so you'll have to do that to see changes."
|
|
|
|
o.separator ""
|
|
|
|
o.separator "To update a specific box (not tied to a Vagrant environment), use the"
|
|
|
|
o.separator "--box flag."
|
|
|
|
o.separator ""
|
|
|
|
o.separator "Options:"
|
|
|
|
o.separator ""
|
|
|
|
|
2014-02-08 08:20:50 +00:00
|
|
|
o.on("--box BOX", String, "Update a specific box") do |b|
|
2014-01-25 01:52:52 +00:00
|
|
|
options[:box] = b
|
|
|
|
end
|
2014-01-25 18:03:33 +00:00
|
|
|
|
2014-02-08 08:20:50 +00:00
|
|
|
o.on("--provider PROVIDER", String, "Update box with specific provider") do |p|
|
2014-01-25 18:03:33 +00:00
|
|
|
options[:provider] = p.to_sym
|
|
|
|
end
|
Add HTTPS download options to `box update` and `box outdated`
Vagrant::Box.load_metadata did not provide a way to specify the HTTPS
download options that could be specified when downloading boxes
(ca cert, ca path, client cert, insecure). As a result, while it was
possible to add a box whose metadata file needed to be downloaded with one of
those options specified, it was impossible to check for updates. The following
changes have been made to address the situation:
1. Create a DownloadMixins module to provide the --insecure, --cacert, --capth,
and --cert command line options to all of `vagrant box add`,
`vagrant box update`, and `vagrant box outdated`.
2. Extend `Vagrant::Box.has_update?` and `Vagrant::Box.load_metadata` to accept
said download options.
3. Extend `box outdated` and `box update` commands to pass download options
down.
4. Extend `Vagrant::Builtin::Action::BoxCheckOutdated` to honour download
options.
5. Options specified on the command line take precedence over options specified
in the machine configuration, if any.
6. Fix bug in `vagrant box add` where client cert was being passed down using
the wrong environment key.
7. Unit test coverage in update_test and box_check_outdated_test.
Resolves #4420
2014-09-08 03:45:32 +00:00
|
|
|
|
2017-08-09 23:21:13 +00:00
|
|
|
o.on("-f", "--force", "Overwrite an existing box if it exists") do |f|
|
|
|
|
options[:force] = f
|
|
|
|
end
|
|
|
|
|
Add HTTPS download options to `box update` and `box outdated`
Vagrant::Box.load_metadata did not provide a way to specify the HTTPS
download options that could be specified when downloading boxes
(ca cert, ca path, client cert, insecure). As a result, while it was
possible to add a box whose metadata file needed to be downloaded with one of
those options specified, it was impossible to check for updates. The following
changes have been made to address the situation:
1. Create a DownloadMixins module to provide the --insecure, --cacert, --capth,
and --cert command line options to all of `vagrant box add`,
`vagrant box update`, and `vagrant box outdated`.
2. Extend `Vagrant::Box.has_update?` and `Vagrant::Box.load_metadata` to accept
said download options.
3. Extend `box outdated` and `box update` commands to pass download options
down.
4. Extend `Vagrant::Builtin::Action::BoxCheckOutdated` to honour download
options.
5. Options specified on the command line take precedence over options specified
in the machine configuration, if any.
6. Fix bug in `vagrant box add` where client cert was being passed down using
the wrong environment key.
7. Unit test coverage in update_test and box_check_outdated_test.
Resolves #4420
2014-09-08 03:45:32 +00:00
|
|
|
build_download_options(o, download_options)
|
2014-01-25 01:52:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
argv = parse_options(opts)
|
|
|
|
return if !argv
|
|
|
|
|
2014-01-25 18:03:33 +00:00
|
|
|
if options[:box]
|
2017-08-09 23:21:13 +00:00
|
|
|
update_specific(options[:box], options[:provider], download_options, options[:force])
|
2014-01-25 18:03:33 +00:00
|
|
|
else
|
2017-08-09 23:21:13 +00:00
|
|
|
update_vms(argv, options[:provider], download_options, options[:force])
|
2014-01-25 18:03:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
0
|
|
|
|
end
|
|
|
|
|
2017-08-09 23:21:13 +00:00
|
|
|
def update_specific(name, provider, download_options, force)
|
2014-01-25 18:03:33 +00:00
|
|
|
boxes = {}
|
|
|
|
@env.boxes.all.each do |n, v, p|
|
|
|
|
boxes[n] ||= {}
|
|
|
|
boxes[n][p] ||= []
|
|
|
|
boxes[n][p] << v
|
|
|
|
end
|
|
|
|
|
|
|
|
if !boxes[name]
|
|
|
|
raise Vagrant::Errors::BoxNotFound, name: name.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
if !provider
|
|
|
|
if boxes[name].length > 1
|
|
|
|
raise Vagrant::Errors::BoxUpdateMultiProvider,
|
|
|
|
name: name.to_s,
|
|
|
|
providers: boxes[name].keys.map(&:to_s).sort.join(", ")
|
|
|
|
end
|
|
|
|
|
|
|
|
provider = boxes[name].keys.first
|
|
|
|
elsif !boxes[name][provider]
|
|
|
|
raise Vagrant::Errors::BoxNotFoundWithProvider,
|
|
|
|
name: name.to_s,
|
|
|
|
provider: provider.to_s,
|
|
|
|
providers: boxes[name].keys.map(&:to_s).sort.join(", ")
|
|
|
|
end
|
|
|
|
|
|
|
|
to_update = [
|
2014-04-12 09:03:04 +00:00
|
|
|
[name, provider, boxes[name][provider].sort.last],
|
2014-01-25 18:03:33 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
to_update.each do |n, p, v|
|
|
|
|
box = @env.boxes.find(n, p, v)
|
2017-08-09 23:21:13 +00:00
|
|
|
box_update(box, "> #{v}", @env.ui, download_options, force)
|
2014-01-25 18:03:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-09 23:21:13 +00:00
|
|
|
def update_vms(argv, provider, download_options, force)
|
2016-06-01 03:08:51 +00:00
|
|
|
machines = {}
|
|
|
|
|
2014-08-29 19:05:44 +00:00
|
|
|
with_target_vms(argv, provider: provider) do |machine|
|
2014-08-29 18:19:54 +00:00
|
|
|
if !machine.config.vm.box
|
|
|
|
machine.ui.output(I18n.t(
|
|
|
|
"vagrant.errors.box_update_no_name"))
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2014-01-25 02:13:37 +00:00
|
|
|
if !machine.box
|
2018-08-02 23:12:10 +00:00
|
|
|
collection = Vagrant::BoxCollection.new(@env.boxes_path)
|
|
|
|
machine.box = collection.find(machine.config.vm.box, provider || @env.default_provider, "> 0")
|
|
|
|
if !machine.box
|
|
|
|
machine.ui.output(I18n.t(
|
|
|
|
"vagrant.errors.box_update_no_box",
|
|
|
|
name: machine.config.vm.box))
|
|
|
|
next
|
|
|
|
end
|
2014-01-25 02:13:37 +00:00
|
|
|
end
|
|
|
|
|
2016-06-01 03:08:51 +00:00
|
|
|
name = machine.box.name
|
|
|
|
provider = machine.box.provider
|
|
|
|
version = machine.config.vm.box_version || machine.box.version
|
|
|
|
|
|
|
|
machines["#{name}_#{provider}_#{version}"] = machine
|
|
|
|
end
|
|
|
|
|
|
|
|
machines.each do |_, machine|
|
2014-01-25 02:13:37 +00:00
|
|
|
box = machine.box
|
2014-01-25 02:23:14 +00:00
|
|
|
version = machine.config.vm.box_version
|
Add HTTPS download options to `box update` and `box outdated`
Vagrant::Box.load_metadata did not provide a way to specify the HTTPS
download options that could be specified when downloading boxes
(ca cert, ca path, client cert, insecure). As a result, while it was
possible to add a box whose metadata file needed to be downloaded with one of
those options specified, it was impossible to check for updates. The following
changes have been made to address the situation:
1. Create a DownloadMixins module to provide the --insecure, --cacert, --capth,
and --cert command line options to all of `vagrant box add`,
`vagrant box update`, and `vagrant box outdated`.
2. Extend `Vagrant::Box.has_update?` and `Vagrant::Box.load_metadata` to accept
said download options.
3. Extend `box outdated` and `box update` commands to pass download options
down.
4. Extend `Vagrant::Builtin::Action::BoxCheckOutdated` to honour download
options.
5. Options specified on the command line take precedence over options specified
in the machine configuration, if any.
6. Fix bug in `vagrant box add` where client cert was being passed down using
the wrong environment key.
7. Unit test coverage in update_test and box_check_outdated_test.
Resolves #4420
2014-09-08 03:45:32 +00:00
|
|
|
# Get download options from machine configuration if not specified
|
|
|
|
# on the command line.
|
|
|
|
download_options[:ca_cert] ||= machine.config.vm.box_download_ca_cert
|
|
|
|
download_options[:ca_path] ||= machine.config.vm.box_download_ca_path
|
|
|
|
download_options[:client_cert] ||= machine.config.vm.box_download_client_cert
|
|
|
|
if download_options[:insecure].nil?
|
|
|
|
download_options[:insecure] = machine.config.vm.box_download_insecure
|
|
|
|
end
|
2017-08-09 23:21:13 +00:00
|
|
|
box_update(box, version, machine.ui, download_options, force)
|
2014-01-25 18:03:33 +00:00
|
|
|
end
|
|
|
|
end
|
2014-01-25 02:23:14 +00:00
|
|
|
|
2017-08-09 23:21:13 +00:00
|
|
|
def box_update(box, version, ui, download_options, force)
|
2014-01-25 18:03:33 +00:00
|
|
|
ui.output(I18n.t("vagrant.box_update_checking", name: box.name))
|
2014-04-15 01:55:22 +00:00
|
|
|
ui.detail("Latest installed version: #{box.version}")
|
2014-01-25 18:03:33 +00:00
|
|
|
ui.detail("Version constraints: #{version}")
|
|
|
|
ui.detail("Provider: #{box.provider}")
|
2014-01-25 02:13:37 +00:00
|
|
|
|
Add HTTPS download options to `box update` and `box outdated`
Vagrant::Box.load_metadata did not provide a way to specify the HTTPS
download options that could be specified when downloading boxes
(ca cert, ca path, client cert, insecure). As a result, while it was
possible to add a box whose metadata file needed to be downloaded with one of
those options specified, it was impossible to check for updates. The following
changes have been made to address the situation:
1. Create a DownloadMixins module to provide the --insecure, --cacert, --capth,
and --cert command line options to all of `vagrant box add`,
`vagrant box update`, and `vagrant box outdated`.
2. Extend `Vagrant::Box.has_update?` and `Vagrant::Box.load_metadata` to accept
said download options.
3. Extend `box outdated` and `box update` commands to pass download options
down.
4. Extend `Vagrant::Builtin::Action::BoxCheckOutdated` to honour download
options.
5. Options specified on the command line take precedence over options specified
in the machine configuration, if any.
6. Fix bug in `vagrant box add` where client cert was being passed down using
the wrong environment key.
7. Unit test coverage in update_test and box_check_outdated_test.
Resolves #4420
2014-09-08 03:45:32 +00:00
|
|
|
update = box.has_update?(version, download_options: download_options)
|
2014-01-25 18:03:33 +00:00
|
|
|
if !update
|
|
|
|
ui.success(I18n.t(
|
|
|
|
"vagrant.box_up_to_date_single",
|
|
|
|
name: box.name, version: box.version))
|
|
|
|
return
|
2014-01-25 01:52:52 +00:00
|
|
|
end
|
2014-01-25 18:03:33 +00:00
|
|
|
|
|
|
|
ui.output(I18n.t(
|
|
|
|
"vagrant.box_updating",
|
|
|
|
name: update[0].name,
|
|
|
|
provider: update[2].name,
|
|
|
|
old: box.version,
|
|
|
|
new: update[1].version))
|
|
|
|
@env.action_runner.run(Vagrant::Action.action_box_add, {
|
|
|
|
box_url: box.metadata_url,
|
|
|
|
box_provider: update[2].name,
|
|
|
|
box_version: update[1].version,
|
|
|
|
ui: ui,
|
2017-08-09 23:21:13 +00:00
|
|
|
box_force: force,
|
Add HTTPS download options to `box update` and `box outdated`
Vagrant::Box.load_metadata did not provide a way to specify the HTTPS
download options that could be specified when downloading boxes
(ca cert, ca path, client cert, insecure). As a result, while it was
possible to add a box whose metadata file needed to be downloaded with one of
those options specified, it was impossible to check for updates. The following
changes have been made to address the situation:
1. Create a DownloadMixins module to provide the --insecure, --cacert, --capth,
and --cert command line options to all of `vagrant box add`,
`vagrant box update`, and `vagrant box outdated`.
2. Extend `Vagrant::Box.has_update?` and `Vagrant::Box.load_metadata` to accept
said download options.
3. Extend `box outdated` and `box update` commands to pass download options
down.
4. Extend `Vagrant::Builtin::Action::BoxCheckOutdated` to honour download
options.
5. Options specified on the command line take precedence over options specified
in the machine configuration, if any.
6. Fix bug in `vagrant box add` where client cert was being passed down using
the wrong environment key.
7. Unit test coverage in update_test and box_check_outdated_test.
Resolves #4420
2014-09-08 03:45:32 +00:00
|
|
|
box_client_cert: download_options[:client_cert],
|
|
|
|
box_download_ca_cert: download_options[:ca_cert],
|
|
|
|
box_download_ca_path: download_options[:ca_path],
|
|
|
|
box_download_insecure: download_options[:insecure]
|
2014-01-25 18:03:33 +00:00
|
|
|
})
|
2014-01-25 01:52:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|