136 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			136 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| module Devops
 | |
|   module Version2_0
 | |
|     module Routes
 | |
|       module ImageRoutes
 | |
| 
 | |
|         def self.registered(app)
 | |
|           app.after %r{\A/image(/[\w]+)?\z} do
 | |
|             statistic
 | |
|           end
 | |
| 
 | |
|           # 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"
 | |
|           #     }
 | |
|           #   ]
 | |
|           app.get_with_headers "/images", :headers => [:accept], &Devops::Version2_0::Handler::Image.get_images
 | |
| 
 | |
|           # 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"
 | |
|           #     }
 | |
|           #   ]
 | |
|           app.get_with_headers "/images/provider/:provider", :headers => [:accept], &Devops::Version2_0::Handler::Image.get_provider_images
 | |
| 
 | |
|           # 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
 | |
|           app.post_with_headers "/image", :headers => [:accept, :content_type], &Devops::Version2_0::Handler::Image.create_image
 | |
| 
 | |
|           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"
 | |
|           #   }
 | |
|           hash["GET"] = Devops::Version2_0::Handler::Image.get_image
 | |
| 
 | |
|           # 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
 | |
|           hash["PUT"] = Devops::Version2_0::Handler::Image.update_image
 | |
| 
 | |
|           # Delete devops image
 | |
|           #
 | |
|           # * *Request*
 | |
|           #   - method : DELETE
 | |
|           #   - headers :
 | |
|           #     - Accept: application/json
 | |
|           #
 | |
|           # * *Returns* :
 | |
|           #   200 - Deleted
 | |
|           hash["DELETE"] = Devops::Version2_0::Handler::Image.delete_image
 | |
| 
 | |
|           app.multi_routes "/image/:image_id", {}, hash
 | |
| 
 | |
|           puts "Image routes initialized"
 | |
|         end
 | |
| 
 | |
|       end
 | |
|     end
 | |
|   end
 | |
| end
 | 
