diff --git a/plugins/commands/serve/client.rb b/plugins/commands/serve/client.rb index e38b0e05b..56f1e85d9 100644 --- a/plugins/commands/serve/client.rb +++ b/plugins/commands/serve/client.rb @@ -2,6 +2,7 @@ module VagrantPlugins module CommandServe module Client autoload :Box, Vagrant.source_root.join("plugins/commands/serve/client/box").to_s + autoload :BoxCollection, Vagrant.source_root.join("plugins/commands/serve/client/box_collection").to_s autoload :CapabilityPlatform, Vagrant.source_root.join("plugins/commands/serve/client/capability_platform").to_s autoload :Guest, Vagrant.source_root.join("plugins/commands/serve/client/guest").to_s autoload :Host, Vagrant.source_root.join("plugins/commands/serve/client/host").to_s diff --git a/plugins/commands/serve/client/box_collection.rb b/plugins/commands/serve/client/box_collection.rb new file mode 100644 index 000000000..96e3a8519 --- /dev/null +++ b/plugins/commands/serve/client/box_collection.rb @@ -0,0 +1,66 @@ +module VagrantPlugins + module CommandServe + module Client + class BoxCollection + prepend Util::ClientSetup + prepend Util::HasLogger + + # @return [Vagrant::Box] box added + def add(path, name, version, force=false, metadata_url=nil, providers=[]) + res = client.add(SDK::BoxCollection::AddRequest.new( + path: path, name: name, version: version, metadataUrl: metadata_url, + force: force, providers: providers + )) + box_client = Box.load(res, broker: broker) + box = Vagrant::Box.new( + box_client.name, + box_client.provider.to_sym, + box_client.version, + Pathname.new(box_client.directory), + client: box_client + ) + box + end + + # @return [List] all the boxes available + def all + res = client.all(Empty.new) + boxes = [] + res.boxes.each do |box| + box_client = Box.load(box, broker: broker) + boxes << Vagrant::Box.new( + box_client.name, + box_client.provider.to_sym, + box_client.version, + Pathname.new(box_client.directory), + client: box_client + ) + end + boxes + end + + def clean(name) + client.clean( + SDK::BoxCollection::CleanRequest.new(name: name) + ) + end + + # @return [Vagrant::Box] box found + def find(name, providers, versions) + res = client.find(SDK::BoxCollection::FindRequest.new( + name: name, version: version, providers: providers + )) + box_client = Box.load(res, broker: broker) + box = Vagrant::Box.new( + box_client.name, + box_client.provider.to_sym, + box_client.version, + Pathname.new(box_client.directory), + client: box_client + ) + box + end + end + end + end +end diff --git a/plugins/commands/serve/mappers/box.rb b/plugins/commands/serve/mappers/box.rb index 6562724b7..adc0d3d22 100644 --- a/plugins/commands/serve/mappers/box.rb +++ b/plugins/commands/serve/mappers/box.rb @@ -15,6 +15,25 @@ module VagrantPlugins Client::Box.load(proto, broker: broker) end end + + class BoxClientToBox < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: Client::Box) + end + super(inputs: inputs, output: Vagrant::Box, func: method(:converter)) + end + + def converter(box_client) + Vagrant::Box.new( + box_client.name, + box_client.provider.to_sym, + box_client.version, + Pathname.new(box_client.directory), + client: box_client + ) + end + end end end end