Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'fog'
- require 'sinatra'
- # setup connection from ~/.fog default credential
- compute = Fog::Compute.new(:provider => 'AWS')
- compute.collections.each do |collection|
- if collection.respond_to?(:create)
- delete("/compute/aws/#{collection}/:identity" do |identity|
- compute.send(collection).new(:identity => identity).destroy
- 204
- end
- get("/compute/aws/#{collection}") do
- content_type :json
- data = compute.send(collection)
- [200, MultiJson.encode(data.attributes)]
- end
- get("/compute/aws/#{collection}/:identity") do |identity|
- content_type :json
- instance = compute.send(collection).get(identity)
- [200, MultiJson.encode(instance.attributes)]
- end
- post("/compute/aws/#{collection}") do
- content_type :json
- attributes = MultiJson.decode(request.body)
- instance = compute.send(collection).create(attributes)
- [200, MultiJson.encode(instance.attributes)]
- end
- end
- end
Add Comment
Please, Sign In to add comment