我正在为木偶使用msutter DSC模块。在阅读源代码时,我遇到了这样的代码(在dsc_configuration_provider.rb中):
def create
Puppet.debug "n" + ps_script_content('set')
output = powershell(ps_script_content('set'))
Puppet.debug output
end
哪个文件定义powershell函数或方法?它是红宝石内置的吗?内置的木偶?从类继承?我知道它被用来将文本作为命令发送到powershell并收集结果,但为了我的目的,我需要查看源代码来了解如何改进其错误日志记录,因为某些powershell错误正在被吞噬,并且Puppet日志中没有打印任何警告。
文件dsc_provider_helpers.rb中的这些行可能是相关的:
provider.commands :powershell =>
if File.exists?("#{ENV['SYSTEMROOT']}\sysnative\WindowsPowershell\v1.0\powershell.exe")
"#{ENV['SYSTEMROOT']}\sysnative\WindowsPowershell\v1.0\powershell.exe"
elsif File.exists?("#{ENV['SYSTEMROOT']}\system32\WindowsPowershell\v1.0\powershell.exe")
"#{ENV['SYSTEMROOT']}\system32\WindowsPowershell\v1.0\powershell.exe"
else
'powershell.exe'
end
当然,这定义了Powershell可执行文件的位置,但没有说明如何调用它以及如何派生它的返回值。stdout和stderr合并了吗?我得到的是文本输出还是错误代码?等等
这是Puppet的核心逻辑。当提供者有一个命令时,如
commands :powershell => some binary
这被连接为函数powershell(*args)
。
你可以在其他供应商那里看到,比如巧克力:
commands :chocolatey => chocolatey_command
def self.chocolatey_command
if Puppet::Util::Platform.windows?
# must determine how to get to params in ruby
#default_location = $chocolatey::params::install_location || ENV['ALLUSERSPROFILE'] + 'chocolatey'
chocopath = ENV['ChocolateyInstall'] ||
('C:Chocolatey' if File.directory?('C:Chocolatey')) ||
('C:ProgramDatachocolatey' if File.directory?('C:ProgramDatachocolatey')) ||
"#{ENV['ALLUSERSPROFILE']}chocolatey"
chocopath += 'binchoco.exe'
else
chocopath = 'choco.exe'
end
chocopath
end
然后其他位置可以像使用args:的函数一样调用chocolatey
chocolatey(*args)