17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/opswalrus/host.rb', line 17
def self.define_host_proxy_class(ops_file)
klass = Class.new(HostProxy)
methods_defined = Set.new
ops_file.local_symbol_table.each do |symbol_name, import_reference|
unless methods_defined.include? symbol_name
klass.define_method(symbol_name) do |*args, **kwargs, &block|
App.instance.trace "resolving local symbol table entry: #{symbol_name}"
namespace_or_ops_file = @runtime_env.resolve_import_reference(ops_file, import_reference)
App.instance.trace "namespace_or_ops_file=#{namespace_or_ops_file.to_s}"
invocation_context = case import_reference
when PackageDependencyReference, DynamicPackageImportReference
RemoteImportInvocationContext.new(@runtime_env, self, namespace_or_ops_file, true, ops_prompt_for_sudo_password: !!ssh_password)
when DirectoryReference, OpsFileReference
RemoteImportInvocationContext.new(@runtime_env, self, namespace_or_ops_file, false, ops_prompt_for_sudo_password: !!ssh_password)
end
invocation_context._invoke(*args, **kwargs)
end
methods_defined << symbol_name
end
end
sibling_symbol_table = Set.new
sibling_symbol_table |= ops_file.dirname.glob("*.ops").map {|ops_file_path| ops_file_path.basename(".ops").to_s } sibling_symbol_table |= ops_file.dirname.glob("*").select(&:directory?).map {|dir_path| dir_path.basename.to_s } sibling_symbol_table.each do |symbol_name|
unless methods_defined.include? symbol_name
klass.define_method(symbol_name) do |*args, **kwargs, &block|
App.instance.trace "resolving implicit import: #{symbol_name}"
namespace_or_ops_file = @runtime_env.resolve_sibling_symbol(ops_file, symbol_name)
App.instance.trace "namespace_or_ops_file=#{namespace_or_ops_file.to_s}"
invocation_context = RemoteImportInvocationContext.new(@runtime_env, self, namespace_or_ops_file, false, ops_prompt_for_sudo_password: !!ssh_password)
invocation_context._invoke(*args, **kwargs)
end
methods_defined << symbol_name
end
end
klass
end
|