Guest User

Untitled

a guest
Jan 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. require 'fog'
  2. require 'sinatra'
  3.  
  4. # setup connection from ~/.fog default credential
  5. compute = Fog::Compute.new(:provider => 'AWS')
  6.  
  7. compute.collections.each do |collection|
  8.  
  9. if collection.respond_to?(:create)
  10.  
  11. delete("/compute/aws/#{collection}/:identity" do |identity|
  12. compute.send(collection).new(:identity => identity).destroy
  13. 204
  14. end
  15.  
  16. get("/compute/aws/#{collection}") do
  17. content_type :json
  18. data = compute.send(collection)
  19. [200, MultiJson.encode(data.attributes)]
  20. end
  21.  
  22. get("/compute/aws/#{collection}/:identity") do |identity|
  23. content_type :json
  24. instance = compute.send(collection).get(identity)
  25. [200, MultiJson.encode(instance.attributes)]
  26. end
  27.  
  28. post("/compute/aws/#{collection}") do
  29. content_type :json
  30. attributes = MultiJson.decode(request.body)
  31. instance = compute.send(collection).create(attributes)
  32. [200, MultiJson.encode(instance.attributes)]
  33. end
  34.  
  35. end
  36.  
  37. end
Add Comment
Please, Sign In to add comment