Add some missing mappers for converting to proto

This commit is contained in:
Chris Roberts 2022-02-18 16:50:27 -08:00 committed by Paul Hinze
parent 6dd5a3ae9b
commit ab8dee7a72
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
2 changed files with 87 additions and 2 deletions

View File

@ -20,7 +20,7 @@ module VagrantPlugins
end
# Build a guest client from a FuncSpec value
class HostFromSpec < Mapper
class HostClientFromSpec < Mapper
def initialize
inputs = [].tap do |i|
i << Input.new(type: SDK::FuncSpec::Value) { |arg|
@ -38,7 +38,7 @@ module VagrantPlugins
end
# Build a guest client from a proto instance
class HostFromProto < Mapper
class HostClientFromProto < Mapper
def initialize
inputs = [].tap do |i|
i << Input.new(type: SDK::Args::Host)
@ -51,6 +51,59 @@ module VagrantPlugins
Client::Host.load(proto, broker: broker)
end
end
class HostFromClient < Mapper
def initialize
super(
inputs: [
Input.new(type: Client::Host),
],
output: Vagrant::Host,
func: method(:converter)
)
end
def converter(client)
Vagrant::Host.new(
client, nil,
Vagrant.plugin("2").
local_manager.
host_capabilities
)
end
end
class HostProtoFromHost < Mapper
def initialize
super(
inputs: [
Input.new(type: Vagrant::Host)
],
output: SDK::Args::Host,
func: method(:converter),
)
end
def converter(host)
host.client.to_proto
end
end
class HostProtoFromClient < Mapper
def initialize
super(
inputs: [
Input.new(type: Client::Host),
],
output: SDK::Args::Host,
func: method(:converter)
)
end
def converter(client)
client.to_proto
end
end
end
end
end

View File

@ -52,6 +52,38 @@ module VagrantPlugins
Client::TargetIndex.load(proto, broker: broker)
end
end
class TargetIndexToProto < Mapper
def initialize
super(
inputs: [
Input.new(type: Client::TargetIndex),
],
output: SDK::Args::TargetIndex,
func: method(:converter)
)
end
def converter(index)
index.to_proto
end
end
class MachineIndexToProto < Mapper
def initialize
super(
inputs: [
Input.new(type: Vagrant::MachineIndex),
],
output: SDK::Args::TargetIndex,
func: method(:converter)
)
end
def converter(index)
index.client.to_proto
end
end
end
end
end