Enable box collection for server mode

This commit is contained in:
sophia 2021-11-12 14:16:17 -06:00 committed by Paul Hinze
parent fd0df0865c
commit 8ead293836
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
3 changed files with 54 additions and 0 deletions

View File

@ -17,6 +17,8 @@ module Vagrant
VAGRANT_SLASH = "-VAGRANTSLASH-".freeze
VAGRANT_COLON = "-VAGRANTCOLON-".freeze
autoload :Remote, "vagrant/box_collection/remote"
# The directory where the boxes in this collection are stored.
#
# A box collection matches a very specific folder structure that Vagrant

View File

@ -0,0 +1,51 @@
module Vagrant
class BoxCollection
# This module enables the BoxCollection for server mode
module Remote
# Add an attribute reader for the client
# when applied to the BoxCollection class
def self.prepended(klass)
klass.class_eval do
attr_reader :client
end
end
def initialize(directory, options=nil)
@client = options[:client]
if @client.nil?
raise ArgumentError,
"Remote client is required for `#{self.class.name}'"
end
@directory = directory
@hook = options[:hook]
@logger = Log4r::Logger.new("vagrant::box_collection")
end
# @return [Vagrant::Box]
def add(path, name, version, **opts)
client.add(
path, name, version, force: opts[:force],
metadata_url: opts[:metadata_url], provider:opts[:providers]
)
end
# @return [Array] Array of `[name, version, provider]` of the boxes
# installed on this system.
def all
client.all
end
# @return [Box] The box found, or `nil` if not found.
def find(name, providers, version)
client.find(name, providers, version)
end
def clean(name)
client.clean(name)
end
end
end
end

View File

@ -254,6 +254,7 @@ module Vagrant
SERVER_MODE_CALLBACKS = [
->{ Vagrant::Box.prepend(Vagrant::Box::Remote) },
->{ Vagrant::BoxCollection.prepend(Vagrant::BoxCollection::Remote) },
->{ Vagrant::Guest.prepend(Vagrant::Guest::Remote) },
->{ Vagrant::Host.prepend(Vagrant::Host::Remote) },
->{ Vagrant::Machine.prepend(Vagrant::Machine::Remote) },