module Devops module API2_0 module Routes module ImageRoutes def self.registered(app) # 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] do check_privileges("image", "r") json Devops::API2_0::Handler::Image.new(request).images.map(&:to_hash) end # 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] do |provider| check_privileges("image", "r") check_provider(provider) json Devops::API2_0::Handler::Image.new(request).provider_images(provider) end # 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] do check_privileges("image", "w") Devops::API2_0::Handler::Image.new(request).create_image() create_response "Created", nil, 201 end 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"] = lambda { |image_id| check_privileges("image", "r") json Devops::API2_0::Handler::Image.new(request).image(image_id) } # 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"] = lambda {|image_id| check_privileges("image", "w") Devops::API2_0::Handler::Image.new(request).update_image(image_id) create_response("Image '#{image_id}' has been updated") } # Delete devops image # # * *Request* # - method : DELETE # - headers : # - Accept: application/json # # * *Returns* : # 200 - Deleted hash["DELETE"] = lambda {|image_id| check_privileges("image", "w") Devops::API2_0::Handler::Image.new(request).delete_image(image_id) create_response("Image '#{image_id}' has been removed") } app.multi_routes "/image/:image_id", {}, hash puts "Image routes initialized" end end end end end