157 lines
4.7 KiB
Ruby
157 lines
4.7 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
|
|
|
|
app.before "/images" do
|
|
check_headers :accept
|
|
check_privileges("image", "r")
|
|
check_provider(params[:provider]) if params[:provider]
|
|
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 "/images", &Devops::Version2_0::Handler::Image.get_images
|
|
|
|
app.before "/images/provider/:provider" do
|
|
check_headers :accept
|
|
check_privileges("image", "r")
|
|
check_provider(params[:provider])
|
|
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 "/images/provider/:provider", &Devops::Version2_0::Handler::Image.get_provider_images
|
|
|
|
app.before "/image/:image_id" do
|
|
case request.method
|
|
when "get"
|
|
check_headers :accept
|
|
check_privileges("image", "r")
|
|
when "delete", "put"
|
|
check_headers
|
|
check_privileges("image", "w")
|
|
end
|
|
end
|
|
# 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"
|
|
# }
|
|
app.get "/image/:image_id", &Devops::Version2_0::Handler::Image.get_image
|
|
|
|
app.before "/image" do
|
|
check_headers
|
|
check_privileges("image", "w")
|
|
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 "/image", &Devops::Version2_0::Handler::Image.create_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
|
|
app.put "/image/:image_id", &Devops::Version2_0::Handler::Image.update_image
|
|
|
|
# Delete devops image
|
|
#
|
|
# * *Request*
|
|
# - method : DELETE
|
|
# - headers :
|
|
# - Accept: application/json
|
|
#
|
|
# * *Returns* :
|
|
# 200 - Deleted
|
|
app.delete "/image/:image_id", &Devops::Version2_0::Handler::Image.delete_image
|
|
|
|
puts "Image routes initialized"
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|
|
end
|