| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  | module Devops | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |   module API2_0 | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  |     module Routes | 
					
						
							|  |  |  |       module StackRoutes | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def self.registered(app) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |           app.get_with_headers '/stacks', :headers => [:accept] do | 
					
						
							|  |  |  |             check_privileges("stack", "r") | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |             json Devops::API2_0::Handler::Stack.new(request).stacks.map(&:to_hash) | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |           app.get_with_headers '/stacks/provider/:provider', :headers => [:accept] do |provider| | 
					
						
							|  |  |  |             check_privileges("stack", "r") | 
					
						
							|  |  |  |             check_provider(provider) | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |             json Devops::API2_0::Handler::Stack.new(request).stacks_for_provider(provider).map(&:to_hash) | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-19 16:52:01 +03:00
										 |  |  |           app.get_with_headers '/stack/:name/servers', :headers => [:accept] do |name| | 
					
						
							|  |  |  |             check_privileges("stack", "r") | 
					
						
							|  |  |  |             json Devops::API2_0::Handler::Stack.new(request).stack_servers(name).map(&:to_hash) | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 11:25:20 +03:00
										 |  |  |           app.post_with_headers "/stack", :headers => [:accept, :content_type] do | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |             check_privileges("stack", "w") | 
					
						
							| 
									
										
										
										
											2015-08-14 17:48:07 +03:00
										 |  |  |             json Devops::API2_0::Handler::Stack.new(request).create_stack | 
					
						
							|  |  |  |             #create_response "Created", nil, 201 | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |           hash = {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |           hash['GET'] = lambda { |stack_id| | 
					
						
							|  |  |  |             check_privileges("stack", "r") | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |             json Devops::API2_0::Handler::Stack.new(request).stack(stack_id).to_hash | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |           hash['DELETE'] = lambda { |stack_id| | 
					
						
							|  |  |  |             check_privileges("stack", "w") | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |             Devops::API2_0::Handler::Stack.new(request).delete_stack(stack_id) | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |             create_response("Stack '#{stack_id}' has been removed") | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           app.multi_routes '/stack/:stack_id', {:headers => [:accept]}, hash | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-27 16:42:28 +03:00
										 |  |  |           app.post_with_headers "/stack/:stack_id/sync_details", :headers => [:accept] do |stack_id| | 
					
						
							|  |  |  |             check_privileges("stack", "w") | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |             json Devops::API2_0::Handler::Stack.new(request).sync_details(stack_id).to_hash | 
					
						
							| 
									
										
										
										
											2015-07-27 16:42:28 +03:00
										 |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           app.get_with_headers "/stack/:stack_id/resources", :headers => [:accept] do |stack_id| | 
					
						
							|  |  |  |             check_privileges("stack", "r") | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |             json Devops::API2_0::Handler::Stack.new(request).resources(stack_id) | 
					
						
							| 
									
										
										
										
											2015-07-27 16:42:28 +03:00
										 |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           app.get_with_headers "/stack/:stack_id/resources/:resource_id", :headers => [:accept] do |stack_id, resource_id| | 
					
						
							|  |  |  |             check_privileges("stack", "r") | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |             json Devops::API2_0::Handler::Stack.new(request).resource(stack_id, resource_id) | 
					
						
							| 
									
										
										
										
											2015-07-27 16:42:28 +03:00
										 |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-04 12:36:10 +03:00
										 |  |  |           # Set run_list to stack | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : PATCH | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Accept: application/json | 
					
						
							|  |  |  |           #     - Content-Type: application/json | 
					
						
							|  |  |  |           #   - body : | 
					
						
							|  |  |  |           #     [ | 
					
						
							|  |  |  |           #       "role[role_1]", | 
					
						
							|  |  |  |           #       "recipe[recipe_1]" | 
					
						
							|  |  |  |           #     ] | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Returns* : | 
					
						
							|  |  |  |           #   200 - Updated | 
					
						
							|  |  |  |           app.patch_with_headers "/stack/:id/run_list", :headers => [:accept, :content_type] do |id| | 
					
						
							|  |  |  |             check_privileges("stack", "w") | 
					
						
							|  |  |  |             info = Devops::API2_0::Handler::Stack.new(request).set_run_list(id) | 
					
						
							|  |  |  |             create_response(info) | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 13:28:03 +03:00
										 |  |  |           # Deploy stack instances | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : POST | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Accept: application/json | 
					
						
							|  |  |  |           #     - Content-Type: application/json | 
					
						
							|  |  |  |           #   - body : | 
					
						
							|  |  |  |           #     { | 
					
						
							|  |  |  |           #       "tags" : ["tag1", "tag2"] | 
					
						
							|  |  |  |           #     } | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Returns* : | 
					
						
							|  |  |  |           #   200 - Updated | 
					
						
							| 
									
										
										
										
											2015-09-02 11:38:58 +03:00
										 |  |  |           app.post_with_headers "/stack/:id/deploy", :headers => [:accept, :content_type] do |id| | 
					
						
							| 
									
										
										
										
											2015-08-14 13:28:03 +03:00
										 |  |  |             check_privileges("stack", "x") | 
					
						
							|  |  |  |             if request["X-Stream"] | 
					
						
							|  |  |  |               stream() do |out| | 
					
						
							|  |  |  |                 status = [] | 
					
						
							|  |  |  |                 begin | 
					
						
							|  |  |  |                   status = Devops::API2_0::Handler::Stack.new(request).deploy_stream(id, out) | 
					
						
							|  |  |  |                   out << create_status(status) | 
					
						
							|  |  |  |                 rescue IOError => e | 
					
						
							|  |  |  |                   logger.error e.message | 
					
						
							|  |  |  |                   break | 
					
						
							|  |  |  |                 end | 
					
						
							|  |  |  |               end # stream | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |               files = Devops::API2_0::Handler::Stack.new(request).deploy(id) | 
					
						
							|  |  |  |               sleep 1
 | 
					
						
							|  |  |  |               json files | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2015-08-04 12:36:10 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  |           puts "Stack routes initialized" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  | end |