From ab8dee7a728a1cdd47ac2f0a13093cf100c23406 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Fri, 18 Feb 2022 16:50:27 -0800 Subject: [PATCH] Add some missing mappers for converting to proto --- plugins/commands/serve/mappers/host.rb | 57 ++++++++++++++++++- .../commands/serve/mappers/target_index.rb | 32 +++++++++++ 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/plugins/commands/serve/mappers/host.rb b/plugins/commands/serve/mappers/host.rb index 3e67bc10b..26274f451 100644 --- a/plugins/commands/serve/mappers/host.rb +++ b/plugins/commands/serve/mappers/host.rb @@ -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 diff --git a/plugins/commands/serve/mappers/target_index.rb b/plugins/commands/serve/mappers/target_index.rb index c3400d28c..51fc1d1a2 100644 --- a/plugins/commands/serve/mappers/target_index.rb +++ b/plugins/commands/serve/mappers/target_index.rb @@ -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