| 
									
										
										
										
											2015-08-11 19:47:54 +03:00
										 |  |  | require "commands/knife_commands" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class KnifeFactory | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-12 11:37:17 +03:00
										 |  |  |   @instance = nil | 
					
						
							| 
									
										
										
										
											2015-08-11 19:47:54 +03:00
										 |  |  |   class << self | 
					
						
							|  |  |  |     def init | 
					
						
							| 
									
										
										
										
											2015-08-12 09:41:19 +03:00
										 |  |  |       c = DevopsConfig.config[:knife_config_file] | 
					
						
							| 
									
										
										
										
											2018-04-04 22:44:39 +03:00
										 |  |  |       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 | 
					
						
							| 
									
										
										
										
											2015-08-11 19:47:54 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 22:44:39 +03:00
										 |  |  |     def keys | 
					
						
							|  |  |  |       @instance.keys | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-08-11 19:47:54 +03:00
										 |  |  | end |