| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  | module Devops | 
					
						
							| 
									
										
										
										
											2015-07-27 15:40:10 +03:00
										 |  |  |   module API2_0 | 
					
						
							| 
									
										
										
										
											2014-12-22 14:22:04 +03:00
										 |  |  |     module Routes | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  |       module ImageRoutes | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  |         def self.registered(app) | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  |           # Get devops images list | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : GET | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Accept: application/json | 
					
						
							|  |  |  |           #   - parameters: | 
					
						
							|  |  |  |           #     - provider=ec2|openstack -> return images for provider | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Returns* : | 
					
						
							|  |  |  |           #   [ | 
					
						
							|  |  |  |           #     { | 
					
						
							|  |  |  |           #       "provider": "openstack", | 
					
						
							|  |  |  |           #       "name": "centos-6.4-x86_64", | 
					
						
							|  |  |  |           #       "remote_user": "root", | 
					
						
							|  |  |  |           #       "bootstrap_template": null, | 
					
						
							|  |  |  |           #       "id": "36dc7618-4178-4e29-be43-286fbfe90f50" | 
					
						
							|  |  |  |           #     } | 
					
						
							|  |  |  |           #   ] | 
					
						
							| 
									
										
										
										
											2015-07-27 15:40:10 +03:00
										 |  |  |           app.get_with_headers "/images", :headers => [:accept] do | 
					
						
							|  |  |  |             check_privileges("image", "r") | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |             json Devops::API2_0::Handler::Image.new(request).images.map(&:to_hash) | 
					
						
							| 
									
										
										
										
											2015-07-27 15:40:10 +03:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2014-12-22 14:22:04 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  |           # Get raw images for :provider | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : GET | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Accept: application/json | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Returns* : | 
					
						
							|  |  |  |           #   - ec2 | 
					
						
							|  |  |  |           #   [ | 
					
						
							|  |  |  |           #     { | 
					
						
							|  |  |  |           #       "id": "ami-83e4bcea", | 
					
						
							|  |  |  |           #       "name": "amzn-ami-pv-2013.09.1.x86_64-ebs", | 
					
						
							|  |  |  |           #       "status": "available" | 
					
						
							|  |  |  |           #     } | 
					
						
							|  |  |  |           #   ] | 
					
						
							|  |  |  |           #   - openstack | 
					
						
							|  |  |  |           #   [ | 
					
						
							|  |  |  |           #      { | 
					
						
							|  |  |  |           #       "id": "36dc7618-4178-4e29-be43-286fbfe90f50", | 
					
						
							|  |  |  |           #       "name": "centos-6.4-x86_64", | 
					
						
							|  |  |  |           #       "status": "ACTIVE" | 
					
						
							|  |  |  |           #     } | 
					
						
							|  |  |  |           #   ] | 
					
						
							| 
									
										
										
										
											2015-07-27 15:40:10 +03:00
										 |  |  |           app.get_with_headers "/images/provider/:provider", :headers => [:accept] do |provider| | 
					
						
							|  |  |  |             check_privileges("image", "r") | 
					
						
							|  |  |  |             check_provider(provider) | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |             json Devops::API2_0::Handler::Image.new(request).provider_images(provider) | 
					
						
							| 
									
										
										
										
											2015-07-27 15:40:10 +03:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  |           # Create devops image | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : POST | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Accept: application/json | 
					
						
							|  |  |  |           #     - Content-Type: application/json | 
					
						
							|  |  |  |           #   - body : | 
					
						
							|  |  |  |           #     { | 
					
						
							|  |  |  |           #       "id": "image id", | 
					
						
							|  |  |  |           #       "provider": "image provider", | 
					
						
							|  |  |  |           #       "remote_user": "user", -> the ssh username | 
					
						
							|  |  |  |           #       "bootstrap_template": null, -> specific bootstrap template name or nil | 
					
						
							|  |  |  |           #       "name": "image name" | 
					
						
							|  |  |  |           #     } | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Returns* : | 
					
						
							|  |  |  |           #   201 - Created | 
					
						
							| 
									
										
										
										
											2015-07-27 15:40:10 +03:00
										 |  |  |           app.post_with_headers "/image", :headers => [:accept, :content_type] do | 
					
						
							|  |  |  |             check_privileges("image", "w") | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |             Devops::API2_0::Handler::Image.new(request).create_image() | 
					
						
							| 
									
										
										
										
											2015-07-27 15:40:10 +03:00
										 |  |  |             create_response "Created", nil, 201
 | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-18 13:50:02 +03:00
										 |  |  |           hash = {} | 
					
						
							|  |  |  |           # Get devops image by id | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : GET | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Accept: application/json | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Returns* : | 
					
						
							|  |  |  |           #   { | 
					
						
							|  |  |  |           #     "provider": "openstack", | 
					
						
							|  |  |  |           #     "name": "centos-6.4-x86_64", | 
					
						
							|  |  |  |           #     "remote_user": "root", | 
					
						
							|  |  |  |           #     "bootstrap_template": null, | 
					
						
							|  |  |  |           #     "id": "36dc7618-4178-4e29-be43-286fbfe90f50" | 
					
						
							|  |  |  |           #   } | 
					
						
							| 
									
										
										
										
											2015-07-27 15:40:10 +03:00
										 |  |  |           hash["GET"] = lambda { |image_id| | 
					
						
							|  |  |  |             check_privileges("image", "r") | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |             json Devops::API2_0::Handler::Image.new(request).image(image_id) | 
					
						
							| 
									
										
										
										
											2015-07-27 15:40:10 +03:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2015-02-18 13:50:02 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  |           # Update devops image | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : PUT | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Accept: application/json | 
					
						
							|  |  |  |           #     - Content-Type: application/json | 
					
						
							|  |  |  |           #   - body : | 
					
						
							|  |  |  |           #     { | 
					
						
							|  |  |  |           #       "id": "image id", | 
					
						
							|  |  |  |           #       "provider": "image provider", | 
					
						
							|  |  |  |           #       "remote_user": "user" -> the ssh username | 
					
						
							|  |  |  |           #       "bootstrap_template": null -> specific bootstrap template name or nil | 
					
						
							|  |  |  |           #       "name": "image name" | 
					
						
							|  |  |  |           #     } | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Returns* : | 
					
						
							|  |  |  |           #   200 - Updated | 
					
						
							| 
									
										
										
										
											2015-07-27 15:40:10 +03:00
										 |  |  |           hash["PUT"] = lambda {|image_id| | 
					
						
							|  |  |  |             check_privileges("image", "w") | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |             Devops::API2_0::Handler::Image.new(request).update_image(image_id) | 
					
						
							| 
									
										
										
										
											2015-07-27 15:40:10 +03:00
										 |  |  |             create_response("Image '#{image_id}' has been updated") | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  |           # Delete devops image | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : DELETE | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Accept: application/json | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Returns* : | 
					
						
							|  |  |  |           #   200 - Deleted | 
					
						
							| 
									
										
										
										
											2015-07-27 15:40:10 +03:00
										 |  |  |           hash["DELETE"] = lambda {|image_id| | 
					
						
							|  |  |  |             check_privileges("image", "w") | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |             Devops::API2_0::Handler::Image.new(request).delete_image(image_id) | 
					
						
							| 
									
										
										
										
											2015-07-27 15:40:10 +03:00
										 |  |  |             create_response("Image '#{image_id}' has been removed") | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2015-02-18 13:50:02 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |           app.multi_routes "/image/:image_id", {}, hash | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  |           puts "Image routes initialized" | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |