From 8ead293836fe4cad7ccdd3ccd908ba0fc4a85fb0 Mon Sep 17 00:00:00 2001 From: sophia Date: Fri, 12 Nov 2021 14:16:17 -0600 Subject: [PATCH] Enable box collection for server mode --- lib/vagrant/box_collection.rb | 2 ++ lib/vagrant/box_collection/remote.rb | 51 ++++++++++++++++++++++++++++ lib/vagrant/shared_helpers.rb | 1 + 3 files changed, 54 insertions(+) create mode 100644 lib/vagrant/box_collection/remote.rb diff --git a/lib/vagrant/box_collection.rb b/lib/vagrant/box_collection.rb index 9e0471f5b..d0d9aa987 100644 --- a/lib/vagrant/box_collection.rb +++ b/lib/vagrant/box_collection.rb @@ -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 diff --git a/lib/vagrant/box_collection/remote.rb b/lib/vagrant/box_collection/remote.rb new file mode 100644 index 000000000..a2f3f4dd2 --- /dev/null +++ b/lib/vagrant/box_collection/remote.rb @@ -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 diff --git a/lib/vagrant/shared_helpers.rb b/lib/vagrant/shared_helpers.rb index 2fce8ef46..e324b2978 100644 --- a/lib/vagrant/shared_helpers.rb +++ b/lib/vagrant/shared_helpers.rb @@ -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) },