| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  | require 'db/mongo/models/stack_template/stack_template_factory' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Devops | 
					
						
							|  |  |  |   module Version2_0 | 
					
						
							|  |  |  |     module Handler | 
					
						
							|  |  |  |       class StackTemplate | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def self.get_stack_templates | 
					
						
							|  |  |  |           lambda { | 
					
						
							|  |  |  |             check_privileges('stack_template', 'r') | 
					
						
							|  |  |  |             stack_templates = settings.mongo.stack_templates | 
					
						
							|  |  |  |             json stack_templates.map(&:to_hash) | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def self.get_stack_templates_for_provider | 
					
						
							|  |  |  |           lambda { | 
					
						
							|  |  |  |             check_privileges('stack_template', 'r') | 
					
						
							|  |  |  |             check_provider(params[:provider]) | 
					
						
							|  |  |  |             stack_templates = settings.mongo.stack_templates(params[:provider]) | 
					
						
							|  |  |  |             json stack_templates.map(&:to_hash) | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def self.create_stack_template | 
					
						
							|  |  |  |           lambda { | 
					
						
							|  |  |  |             check_privileges('stack_template', 'w') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             attrs = create_object_from_json_body | 
					
						
							|  |  |  |             template_model = Model::StackTemplateFactory.create(attrs['provider'], attrs) | 
					
						
							|  |  |  |             settings.mongo.stack_template_insert(template_model) | 
					
						
							| 
									
										
										
										
											2015-07-13 20:26:13 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  |             create_response 'Created', template_model.to_hash, 201
 | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def self.get_stack_template | 
					
						
							|  |  |  |           lambda { | 
					
						
							|  |  |  |             check_privileges('stack_template', 'r') | 
					
						
							|  |  |  |             stack_template = settings.mongo.stack_template(params[:stack_template_id]) | 
					
						
							|  |  |  |             json stack_template.to_hash | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def self.delete_stack_template | 
					
						
							|  |  |  |           lambda { | 
					
						
							|  |  |  |             check_privileges('stack_template', 'w') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             settings.mongo.stack_template_delete params[:stack_template_id] | 
					
						
							|  |  |  |             create_response("Template '#{params[:stack_template_id]}' has been removed") | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |