28 lines
757 B
Ruby
28 lines
757 B
Ruby
require "commands/knife_commands"
|
|
|
|
class KnifeFactory
|
|
|
|
@instance = nil
|
|
class << self
|
|
def init
|
|
c = DevopsConfig.config[:knife_config_file]
|
|
raise "Option ':knife_config_file' is undefined or is not a Hash({key => config}), please check config.rb file" unless c.is_a?(Hash)
|
|
@instance = {}
|
|
c.each do |key, config|
|
|
@instance[key] = KnifeCommands.new(config)
|
|
DevopsLogger.logger.info("Knife #{key} instance has been initialized with config '#{config}'")
|
|
end
|
|
end
|
|
|
|
def instance key
|
|
res = @instance[key]
|
|
raise Devops::Exception::KnifeConfigError.new "Can not find configuration for chef environment '#{key}'" if res.nil?
|
|
res
|
|
end
|
|
|
|
def keys
|
|
@instance.keys
|
|
end
|
|
end
|
|
end
|