box_url works with all box formats a provider supports [GH-1752]
This commit is contained in:
parent
25895b5099
commit
cf0ba53fbb
|
@ -18,6 +18,8 @@ IMPROVEMENTS:
|
||||||
|
|
||||||
BUG FIXES:
|
BUG FIXES:
|
||||||
|
|
||||||
|
- `box_url` now handles the case where the provider doesn't perfectly
|
||||||
|
match the provider in use, but the provider supports it. [GH-1752]
|
||||||
- Fix uninitialized constant error when configuring Arch Linux network. [GH-1734]
|
- Fix uninitialized constant error when configuring Arch Linux network. [GH-1734]
|
||||||
- Debian/Ubuntu change hostname works properly if eth0 is configured
|
- Debian/Ubuntu change hostname works properly if eth0 is configured
|
||||||
with hot-plugging. [GH-1929]
|
with hot-plugging. [GH-1929]
|
||||||
|
|
|
@ -43,9 +43,9 @@ module Vagrant
|
||||||
# First see if we actually have the box now.
|
# First see if we actually have the box now.
|
||||||
has_box = false
|
has_box = false
|
||||||
|
|
||||||
formats = env[:machine].provider_options[:box_format] ||
|
box_formats = env[:machine].provider_options[:box_format] ||
|
||||||
env[:machine].provider_name
|
env[:machine].provider_name
|
||||||
if env[:box_collection].find(box_name, formats)
|
if env[:box_collection].find(box_name, box_formats)
|
||||||
has_box = true
|
has_box = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
@ -61,7 +61,7 @@ module Vagrant
|
||||||
begin
|
begin
|
||||||
env[:action_runner].run(Vagrant::Action.action_box_add, {
|
env[:action_runner].run(Vagrant::Action.action_box_add, {
|
||||||
:box_name => box_name,
|
:box_name => box_name,
|
||||||
:box_provider => env[:machine].provider_name,
|
:box_provider => box_formats,
|
||||||
:box_url => box_url
|
:box_url => box_url
|
||||||
})
|
})
|
||||||
rescue Errors::BoxAlreadyExists
|
rescue Errors::BoxAlreadyExists
|
||||||
|
|
|
@ -70,31 +70,35 @@ module Vagrant
|
||||||
# the box represents will be added.
|
# the box represents will be added.
|
||||||
# @param [Boolean] force If true, any existing box with the same name
|
# @param [Boolean] force If true, any existing box with the same name
|
||||||
# and provider will be replaced.
|
# and provider will be replaced.
|
||||||
def add(path, name, provider=nil, force=false)
|
def add(path, name, formats=nil, force=false)
|
||||||
|
formats = [formats] if formats && !formats.is_a?(Array)
|
||||||
|
provider = nil
|
||||||
|
|
||||||
with_collection_lock do
|
with_collection_lock do
|
||||||
# A helper to check if a box exists. We store this in a variable
|
# A helper to check if a box exists. We store this in a variable
|
||||||
# since we call it multiple times.
|
# since we call it multiple times.
|
||||||
check_box_exists = lambda do |box_provider|
|
check_box_exists = lambda do |box_formats|
|
||||||
box = find(name, box_provider)
|
box = find(name, box_formats)
|
||||||
next if !box
|
next if !box
|
||||||
|
|
||||||
if !force
|
if !force
|
||||||
@logger.error("Box already exists, can't add: #{name} #{box_provider}")
|
@logger.error("Box already exists, can't add: #{name} #{box_formats.join(", ")}")
|
||||||
raise Errors::BoxAlreadyExists, :name => name, :provider => box_provider
|
raise Errors::BoxAlreadyExists, :name => name, :formats => box_formats.join(", ")
|
||||||
end
|
end
|
||||||
|
|
||||||
# We're forcing, so just delete the old box
|
# We're forcing, so just delete the old box
|
||||||
@logger.info("Box already exists, but forcing so removing: #{name} #{box_provider}")
|
@logger.info(
|
||||||
|
"Box already exists, but forcing so removing: #{name} #{box_formats.join(", ")}")
|
||||||
box.destroy!
|
box.destroy!
|
||||||
end
|
end
|
||||||
|
|
||||||
log_provider = provider ? provider : "any provider"
|
log_provider = formats ? formats.join(", ") : "any provider"
|
||||||
@logger.debug("Adding box: #{name} (#{log_provider}) from #{path}")
|
@logger.debug("Adding box: #{name} (#{log_provider}) from #{path}")
|
||||||
|
|
||||||
# Verify the box doesn't exist early if we're given a provider. This
|
# Verify the box doesn't exist early if we're given a provider. This
|
||||||
# can potentially speed things up considerably since we don't need
|
# can potentially speed things up considerably since we don't need
|
||||||
# to unpack any files.
|
# to unpack any files.
|
||||||
check_box_exists.call(provider) if provider
|
check_box_exists.call(formats) if formats
|
||||||
|
|
||||||
# Verify that a V1 box doesn't exist. If it does, then we signal
|
# Verify that a V1 box doesn't exist. If it does, then we signal
|
||||||
# to the user that we need an upgrade.
|
# to the user that we need an upgrade.
|
||||||
|
@ -121,26 +125,35 @@ module Vagrant
|
||||||
with_temp_dir(temp_dir) do |final_temp_dir|
|
with_temp_dir(temp_dir) do |final_temp_dir|
|
||||||
# Get an instance of the box we just added before it is finalized
|
# Get an instance of the box we just added before it is finalized
|
||||||
# in the system so we can inspect and use its metadata.
|
# in the system so we can inspect and use its metadata.
|
||||||
box = Box.new(name, provider, final_temp_dir)
|
box = Box.new(name, nil, final_temp_dir)
|
||||||
|
|
||||||
# Get the provider, since we'll need that to at the least add it
|
# Get the provider, since we'll need that to at the least add it
|
||||||
# to the system or check that it matches what is given to us.
|
# to the system or check that it matches what is given to us.
|
||||||
box_provider = box.metadata["provider"]
|
box_provider = box.metadata["provider"]
|
||||||
|
|
||||||
if provider
|
if formats
|
||||||
# Verify that the given provider matches what the box has.
|
found = false
|
||||||
if box_provider.to_sym != provider
|
formats.each do |format|
|
||||||
@logger.error("Added box provider doesnt match expected: #{box_provider}")
|
# Verify that the given provider matches what the box has.
|
||||||
raise Errors::BoxProviderDoesntMatch, :expected => provider, :actual => box_provider
|
if box_provider.to_sym == format
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if !found
|
||||||
|
@logger.error("Added box provider doesnt match expected: #{log_provider}")
|
||||||
|
raise Errors::BoxProviderDoesntMatch,
|
||||||
|
:expected => log_provider, :actual => box_provider
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# We weren't given a provider, so store this one.
|
|
||||||
provider = box_provider.to_sym
|
|
||||||
|
|
||||||
# Verify the box doesn't already exist
|
# Verify the box doesn't already exist
|
||||||
check_box_exists.call(provider)
|
check_box_exists.call([box_provider])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# We weren't given a provider, so store this one.
|
||||||
|
provider = box_provider.to_sym
|
||||||
|
|
||||||
# Create the directory for this box, not including the provider
|
# Create the directory for this box, not including the provider
|
||||||
box_dir = @directory.join(name)
|
box_dir = @directory.join(name)
|
||||||
box_dir.mkpath
|
box_dir.mkpath
|
||||||
|
|
|
@ -1006,7 +1006,7 @@ en:
|
||||||
The box you're attempting to add already exists:
|
The box you're attempting to add already exists:
|
||||||
|
|
||||||
Name: %{name}
|
Name: %{name}
|
||||||
Provider: %{provider}
|
Provider: %{formats}
|
||||||
add:
|
add:
|
||||||
adding: |-
|
adding: |-
|
||||||
Extracting box...
|
Extracting box...
|
||||||
|
|
Loading…
Reference in New Issue