Get first level parent from ruby plugins
This commit is contained in:
parent
fd96279d82
commit
4251b2ff7c
@ -17,30 +17,6 @@ module Vagrant
|
||||
def detect?(machine)
|
||||
false
|
||||
end
|
||||
|
||||
# Returns list of parents for
|
||||
# this guest
|
||||
#
|
||||
# @return [Array<Symbol>]
|
||||
def parents
|
||||
guests = Vagrant.plugin("2").manager.guests.to_hash
|
||||
ancestors = []
|
||||
n, entry = guests.detect { |_, v| v.first == self.class }
|
||||
while n
|
||||
n = nil
|
||||
if entry.last
|
||||
ancestors << entry.last
|
||||
# `guests` might not have the key, if the entry does not exist within
|
||||
# the Ruby runtime. For example, if a Ruby plugin has a dependency
|
||||
# on a Go plugin.
|
||||
if guests.has_key?(entry.last)
|
||||
entry = guests[entry.last]
|
||||
n = entry.last
|
||||
end
|
||||
end
|
||||
end
|
||||
ancestors
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -13,30 +13,6 @@ module Vagrant
|
||||
def detect?(env)
|
||||
false
|
||||
end
|
||||
|
||||
# Returns list of parents for
|
||||
# this host
|
||||
#
|
||||
# @return [Array<Symbol>]
|
||||
def parents
|
||||
hosts = Vagrant.plugin("2").manager.hosts.to_hash
|
||||
ancestors = []
|
||||
n, entry = hosts.detect { |_, v| v.first == self.class }
|
||||
while n
|
||||
n = nil
|
||||
if entry.last
|
||||
ancestors << entry.last
|
||||
# `hosts` might not have the key, if the entry does not exist within
|
||||
# the Ruby runtime. For example, if a Ruby plugin has a dependency
|
||||
# on a Go plugin.
|
||||
if hosts.has_key?(entry.last)
|
||||
entry = hosts[entry.last]
|
||||
n = entry.last
|
||||
end
|
||||
end
|
||||
end
|
||||
ancestors
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -63,25 +63,26 @@ module VagrantPlugins
|
||||
end
|
||||
end
|
||||
|
||||
def parents_spec(*_)
|
||||
def parent_spec(*_)
|
||||
SDK::FuncSpec.new(
|
||||
name: "parents_spec",
|
||||
name: "parent_spec",
|
||||
result: [
|
||||
type: "hashicorp.vagrant.sdk.Platform.ParentsResp",
|
||||
type: "hashicorp.vagrant.sdk.Platform.ParentResp",
|
||||
name: "",
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
def parents(req, ctx)
|
||||
def parent(req, ctx)
|
||||
with_info(ctx) do |info|
|
||||
plugin_name = info.plugin_name
|
||||
plugin = Vagrant.plugin("2").manager.guests[plugin_name.to_s.to_sym].to_a.first
|
||||
guest_hash = Vagrant.plugin("2").manager.guests[plugin_name.to_s.to_sym].to_a
|
||||
plugin = guest_hash.first
|
||||
if !plugin
|
||||
raise "Failed to locate guest plugin for: #{plugin_name.inspect}"
|
||||
end
|
||||
SDK::Platform::ParentsResp.new(
|
||||
parents: plugin.new.parents
|
||||
SDK::Platform::ParentResp.new(
|
||||
parent: guest_hash.last
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@ -58,26 +58,26 @@ module VagrantPlugins
|
||||
end
|
||||
end
|
||||
|
||||
def parents_spec(*_)
|
||||
def parent_spec(*_)
|
||||
SDK::FuncSpec.new(
|
||||
name: "parents_spec",
|
||||
name: "parent_spec",
|
||||
result: [
|
||||
type: "hashicorp.vagrant.sdk.Host.ParentsResp",
|
||||
type: "hashicorp.vagrant.sdk.Host.ParentResp",
|
||||
name: "",
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
def parents(req, ctx)
|
||||
def parent(req, ctx)
|
||||
with_info(ctx) do |info|
|
||||
plugin_name = info.plugin_name
|
||||
plugin = Vagrant.plugin("2").manager.hosts[plugin_name.to_s.to_sym].to_a.first
|
||||
host_hash = Vagrant.plugin("2").manager.hosts[plugin_name.to_s.to_sym].to_a
|
||||
plugin = host_hash.first
|
||||
if !plugin
|
||||
raise "Failed to locate host plugin for: #{plugin_name.inspect}"
|
||||
end
|
||||
p = plugin.new.parents
|
||||
SDK::Platform::ParentsResp.new(
|
||||
parents: p
|
||||
SDK::Platform::ParentResp.new(
|
||||
parent: host_hash.last
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user