Update capability to request and handle direct args

This commit is contained in:
Chris Roberts 2021-10-06 08:15:22 -07:00 committed by Paul Hinze
parent ab6f18093b
commit 75b9950ae4
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0

View File

@ -53,33 +53,21 @@ module VagrantPlugins
end
def capability_spec(req, ctx)
with_info(ctx) do |info|
cap_name = req.name.to_sym
plugin_name = info.plugin_name.to_sym
logger.debug("generating capabillity spec for #{cap_name} capability in #{plugin_name}")
caps_registry = @capabilities[plugin_name]
target_cap = caps_registry.get(cap_name)
args = target_cap.method(cap_name).parameters
# The first argument is always a machine, drop it
args.shift
cap_args = @default_args
# TODO: take the rest of `args` and create entries for them in
# `cap_args`
return SDK::FuncSpec.new(
name: "has_capability_spec",
args: cap_args,
result: [
SDK::FuncSpec::Value.new(
type: "hashicorp.vagrant.sdk.Platform.Capability.Resp",
name: "",
),
],
)
end
SDK::FuncSpec.new(
name: "capability_spec",
args: [
SDK::FuncSpec::Value.new(
type: "hashicorp.vagrant.sdk.Args.Direct",
name: "",
)
],
result: [
SDK::FuncSpec::Value.new(
type: "hashicorp.vagrant.sdk.Platform.Capability.Resp",
name: "",
)
]
)
end
def capability(req, ctx)
@ -90,12 +78,15 @@ module VagrantPlugins
caps_registry = @capabilities[plugin_name]
target_cap = caps_registry.get(cap_name)
# TODO: how to all the args to pass into the cap method
# TODO: this needs to be adjusted to only be
# provided during mapping
mapper.add_argument(broker)
args = mapper.funcspec_map(req.func_args)
cap_method = target_cap.method(cap_name)
# TODO: pass in args too
resp = cap_method.call({})
resp = cap_method.call(*args)
val = Google::Protobuf::Value.new
val.from_ruby(resp)