Add box collection client

This commit is contained in:
sophia 2021-11-12 13:22:22 -06:00 committed by Paul Hinze
parent e7a8c7120e
commit fd0df0865c
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
3 changed files with 86 additions and 0 deletions

View File

@ -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

View File

@ -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<Vagrant::Box>] 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

View File

@ -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