| 
									
										
										
										
											2015-06-17 22:37:08 +03:00
										 |  |  | module Devops | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |   module API2_0 | 
					
						
							| 
									
										
										
										
											2015-06-17 22:37:08 +03:00
										 |  |  |     module Routes | 
					
						
							| 
									
										
										
										
											2015-07-15 19:21:23 +03:00
										 |  |  |       module StackPresetRoutes | 
					
						
							| 
									
										
										
										
											2015-06-17 22:37:08 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         def self.registered(app) | 
					
						
							|  |  |  |           # Get list of available stack_template_presets | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : GET | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Accept: application/json | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Returns* : array of hashes | 
					
						
							|  |  |  |           #   [ {id: 'preset id', template_preset_body: 'long body'} ] | 
					
						
							|  |  |  |           # | 
					
						
							| 
									
										
										
										
											2015-07-27 16:42:28 +03:00
										 |  |  |           app.get_with_headers "/stack_presets", :headers => [:accept] do | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |             # check_privileges("stack_template_presets", "r") | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |             json Devops::API2_0::Handler::StackPreset.new(request).presets.map(&:to_hash) | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2015-06-17 22:37:08 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |           # Get information about stack_template_preset | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : GET | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Accept: application/json | 
					
						
							|  |  |  |           # | 
					
						
							| 
									
										
										
										
											2015-07-08 15:56:24 +03:00
										 |  |  |           # * *Returns* : hash | 
					
						
							|  |  |  |           #   {id: 'preset id', template_preset_body: 'long body'} | 
					
						
							| 
									
										
										
										
											2015-06-17 22:37:08 +03:00
										 |  |  |           # | 
					
						
							| 
									
										
										
										
											2015-07-27 16:42:28 +03:00
										 |  |  |           app.get_with_headers "/stack_presets/:id", :headers => [:accept] do |id| | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |             # check_privileges("stack_template_presets", "r") | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |             json Devops::API2_0::Handler::StackPreset.new(request).preset(id).to_hash | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2015-06-18 17:53:03 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |           # Build stack template from preset | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : POST | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Accept: application/json | 
					
						
							|  |  |  |           #   - params : | 
					
						
							|  |  |  |           #     - provider: string | 
					
						
							|  |  |  |           #     - stack_template_id: id of stack template to create | 
					
						
							|  |  |  |           #     - template_attrs: hash with template attributes | 
					
						
							|  |  |  |           # | 
					
						
							| 
									
										
										
										
											2015-07-08 15:56:24 +03:00
										 |  |  |           # TODO: not stack template, but stack itself | 
					
						
							|  |  |  |           # | 
					
						
							| 
									
										
										
										
											2015-06-18 17:53:03 +03:00
										 |  |  |           # * *Returns* : created stack template model | 
					
						
							|  |  |  |           #   { | 
					
						
							|  |  |  |           #     id: 'template id', | 
					
						
							|  |  |  |           #     provider: 'provider', | 
					
						
							|  |  |  |           #     template_body: 'long body' | 
					
						
							|  |  |  |           #   } | 
					
						
							|  |  |  |           # | 
					
						
							| 
									
										
										
										
											2015-07-27 16:42:28 +03:00
										 |  |  |           app.post_with_headers "/stack_presets/:id/apply", :headers => [:accept] do |id| | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |             # check_privileges("stack_template_presets", "r") | 
					
						
							|  |  |  |             check_privileges('stack_template', 'w') | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |             stack = Devops::API2_0::Handler::StackPreset.new(request).apply(id) | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |             create_response 'Created', stack.to_hash, 201
 | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2015-06-18 17:53:03 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-17 22:37:08 +03:00
										 |  |  |           puts "Stack template presets routes initialized" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |