Add mapper for machine state
This commit is contained in:
parent
8355209654
commit
274ed6c756
@ -51,14 +51,15 @@ module VagrantPlugins
|
||||
client.machine_id_changed(req)
|
||||
end
|
||||
|
||||
# @return [SDK::SSHInfo] ssh info for machine
|
||||
# @return [Hash] ssh info for machine
|
||||
def ssh_info
|
||||
req = SDK::FuncSpec::Args.new(args: seed_protos)
|
||||
client.ssh_info(req)
|
||||
machine_ssh_info = client.ssh_info(req)
|
||||
machine_ssh_info.to_h
|
||||
end
|
||||
|
||||
# @param [Sdk::Args::Machine]
|
||||
# @return [SDK::Args::Target::Machine::State] machine state
|
||||
# @return [Vagrant::MachineState] machine state
|
||||
def state(machine)
|
||||
args = seed_protos
|
||||
args << SDK::FuncSpec::Value.new(
|
||||
@ -66,7 +67,8 @@ module VagrantPlugins
|
||||
value: Google::Protobuf::Any.pack(machine),
|
||||
)
|
||||
req = SDK::FuncSpec::Args.new(args: args)
|
||||
client.state(req)
|
||||
machine_state = client.state(req)
|
||||
mapper.map(machine_state, to: Vagrant::MachineState)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -103,6 +103,40 @@ module VagrantPlugins
|
||||
m.to_proto
|
||||
end
|
||||
end
|
||||
|
||||
class MachineStateFromProto < Mapper
|
||||
def initialize
|
||||
super(
|
||||
inputs: [Input.new(type: SDK::Args::Target::Machine::State)],
|
||||
output: Vagrant::MachineState,
|
||||
func: method(:converter),
|
||||
)
|
||||
end
|
||||
|
||||
def converter(m)
|
||||
Vagrant::MachineState.new(
|
||||
m.id, m.short_description, m.long_description
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class MachineStateToProto < Mapper
|
||||
def initialize
|
||||
super(
|
||||
inputs: [Input.new(type: Vagrant::MachineState)],
|
||||
output: SDK::Args::Target::Machine::State,
|
||||
func: method(:converter),
|
||||
)
|
||||
end
|
||||
|
||||
def converter(machine_state)
|
||||
SDK::Args::Target::Machine::State.new(
|
||||
id: machine_state.id,
|
||||
short_description: machine_state.short_description,
|
||||
long_description: machine_state.long_description,
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -149,17 +149,10 @@ module VagrantPlugins
|
||||
def state(req, ctx)
|
||||
plugins = Vagrant.plugin("2").local_manager.providers
|
||||
with_plugin(ctx, plugins, broker: broker) do |plugin|
|
||||
machine = mapper.funcspec_map(
|
||||
req.func_args,
|
||||
expect: [Vagrant::Machine]
|
||||
)
|
||||
machine = mapper.funcspec_map(req, expect: [Vagrant::Machine])
|
||||
provider = plugin.new(machine)
|
||||
machine_state = provider.state
|
||||
return SDK::Args::Target::Machine::State.new(
|
||||
id: machine_state.id,
|
||||
short_description: machine_state.short_description,
|
||||
long_description: machine_state.long_description,
|
||||
)
|
||||
return mapper.map(machine_state, to: SDK::Args::Target::Machine::State)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user