deltacloud-core 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +23 -0
- data/NOTICE +3 -0
- data/Rakefile +32 -20
- data/bin/deltacloudd +1 -1
- data/config.ru +25 -32
- data/deltacloud-core.gemspec +1 -1
- data/lib/cimi/collections.rb +4 -1
- data/lib/cimi/collections/address_templates.rb +2 -2
- data/lib/cimi/collections/addresses.rb +1 -1
- data/lib/cimi/collections/base.rb +64 -0
- data/lib/cimi/collections/{machine_admins.rb → credentials.rb} +12 -12
- data/lib/cimi/collections/{vsp_templates.rb → forwarding_group_templates.rb} +12 -16
- data/lib/cimi/collections/{vsp_configurations.rb → forwarding_groups.rb} +12 -13
- data/lib/cimi/collections/machine_configurations.rb +2 -2
- data/lib/cimi/collections/machine_images.rb +1 -1
- data/lib/cimi/collections/machines.rb +8 -2
- data/lib/cimi/collections/network_configurations.rb +2 -2
- data/lib/cimi/collections/{routing_groups.rb → network_port_configurations.rb} +12 -12
- data/lib/cimi/collections/{routing_group_templates.rb → network_port_templates.rb} +15 -12
- data/lib/cimi/collections/{vsps.rb → network_ports.rb} +33 -32
- data/lib/cimi/collections/network_templates.rb +2 -2
- data/lib/cimi/collections/networks.rb +17 -2
- data/lib/cimi/collections/{entity_metadata.rb → resource_metadata.rb} +10 -10
- data/lib/cimi/collections/volume_configurations.rb +1 -1
- data/lib/cimi/collections/volume_images.rb +1 -1
- data/lib/cimi/collections/volumes.rb +1 -2
- data/lib/cimi/dependencies.rb +1 -1
- data/lib/cimi/helpers.rb +3 -84
- data/lib/cimi/helpers/cimi_helper.rb +15 -14
- data/lib/cimi/models.rb +20 -36
- data/lib/cimi/models/address.rb +32 -4
- data/lib/cimi/models/address_template.rb +2 -2
- data/lib/cimi/models/base.rb +24 -5
- data/lib/cimi/models/cloud_entry_point.rb +4 -9
- data/lib/cimi/models/collection.rb +101 -0
- data/lib/cimi/models/{machine_admin.rb → credential.rb} +6 -4
- data/lib/cimi/models/disk_collection.rb +1 -2
- data/lib/cimi/models/{routing_group_template.rb → forwarding_group.rb} +5 -3
- data/lib/cimi/models/{routing_group.rb → forwarding_group_template.rb} +5 -3
- data/lib/cimi/models/machine.rb +9 -7
- data/lib/cimi/models/machine_configuration.rb +2 -0
- data/lib/cimi/models/machine_image.rb +2 -0
- data/lib/cimi/models/machine_template.rb +3 -1
- data/lib/cimi/models/machine_volume_collection.rb +1 -1
- data/lib/cimi/models/network.rb +2 -0
- data/lib/cimi/models/network_configuration.rb +4 -8
- data/lib/cimi/models/{vsp.rb → network_port.rb} +7 -11
- data/lib/cimi/models/{network_configuration_collection.rb → network_port_collection.rb} +25 -8
- data/lib/cimi/models/{vsp_configuration.rb → network_port_configuration.rb} +6 -10
- data/lib/cimi/models/{network_collection.rb → network_port_configuration_collection.rb} +9 -9
- data/lib/cimi/models/{vsp_template.rb → network_port_template.rb} +6 -4
- data/lib/cimi/models/{network_template_collection.rb → network_port_template_collection.rb} +10 -8
- data/lib/cimi/models/network_template.rb +3 -1
- data/lib/cimi/models/{entity_metadata.rb → resource_metadata.rb} +16 -15
- data/lib/cimi/models/schema.rb +23 -12
- data/lib/cimi/models/volume.rb +2 -0
- data/lib/cimi/models/volume_configuration.rb +2 -0
- data/lib/cimi/models/volume_image.rb +2 -0
- data/lib/cimi/models/volume_template.rb +2 -0
- data/lib/cimi/server.rb +10 -6
- data/lib/deltacloud/collections.rb +7 -2
- data/lib/deltacloud/collections/addresses.rb +3 -1
- data/lib/deltacloud/collections/base.rb +64 -0
- data/lib/deltacloud/collections/buckets.rb +14 -4
- data/lib/deltacloud/collections/drivers.rb +1 -1
- data/lib/deltacloud/collections/firewalls.rb +1 -1
- data/lib/deltacloud/collections/instances.rb +5 -1
- data/lib/deltacloud/collections/keys.rb +1 -1
- data/lib/deltacloud/collections/load_balancers.rb +2 -0
- data/lib/deltacloud/collections/storage_volumes.rb +3 -5
- data/lib/deltacloud/core_ext.rb +1 -0
- data/lib/deltacloud/core_ext/hash.rb +8 -0
- data/lib/deltacloud/core_ext/ordered_hash.rb +222 -0
- data/lib/deltacloud/core_ext/string.rb +9 -0
- data/lib/deltacloud/drivers/aruba/aruba_driver.rb +0 -9
- data/lib/deltacloud/drivers/base_driver.rb +22 -4
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +0 -4
- data/lib/deltacloud/drivers/exceptions.rb +30 -13
- data/lib/deltacloud/drivers/features.rb +7 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +1 -9
- data/lib/deltacloud/drivers/google/google_driver.rb +13 -0
- data/lib/deltacloud/drivers/mock/data/addresses/192.168.0.1.yml +3 -0
- data/lib/deltacloud/drivers/mock/data/addresses/192.168.0.2.yml +3 -0
- data/lib/deltacloud/drivers/mock/data/addresses/192.168.0.3.yml +3 -0
- data/lib/deltacloud/drivers/mock/data/addresses/192.168.0.4.yml +3 -0
- data/lib/deltacloud/drivers/mock/mock_driver.rb +65 -1
- data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +55 -32
- data/lib/deltacloud/drivers/openstack/openstack_driver.rb +18 -6
- data/lib/deltacloud/helpers.rb +0 -75
- data/lib/deltacloud/helpers/deltacloud_helper.rb +66 -28
- data/lib/deltacloud/helpers/driver_helper.rb +7 -0
- data/lib/deltacloud/helpers/rabbit_helper.rb +51 -0
- data/lib/deltacloud/server.rb +12 -14
- data/lib/deltacloud/version.rb +1 -1
- data/lib/deltacloud_rack.rb +26 -2
- data/lib/ec2/query_parser.rb +18 -3
- data/lib/sinatra/rack_accept.rb +7 -2
- data/lib/sinatra/rack_matrix_params.rb +14 -14
- data/public/javascripts/cmwgapp.js +2 -2
- data/tests/cimi/collections/cloud_entry_point_test.rb +3 -3
- data/tests/cimi/collections/machine_images_test.rb +2 -2
- data/tests/cimi/collections/machines_test.rb +1 -1
- data/tests/cimi/collections/url_helper_test.rb +31 -0
- data/tests/cimi/spec/cimi/model/{machine_admin_spec.rb → credential_spec.rb} +4 -4
- data/tests/deltacloud/base_collection_test.rb +0 -5
- data/tests/deltacloud/collections/buckets_collection_test.rb +1 -1
- data/tests/deltacloud/collections/drivers_collection_test.rb +1 -1
- data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +1 -1
- data/tests/deltacloud/collections/images_collection_test.rb +1 -1
- data/tests/deltacloud/collections/instance_states_collection_test.rb +1 -1
- data/tests/deltacloud/collections/instances_collection_test.rb +1 -1
- data/tests/deltacloud/collections/keys_collection_test.rb +1 -4
- data/tests/deltacloud/deltacloud_helper_test.rb +0 -9
- data/tests/deltacloud/server_test.rb +1 -1
- data/tests/drivers/base/base_driver_test.rb +30 -0
- data/tests/drivers/base/common.rb +14 -0
- data/tests/drivers/base/exceptions_test.rb +64 -0
- data/tests/drivers/ec2/buckets_test.rb +45 -0
- data/tests/drivers/ec2/keys_test.rb +1 -1
- data/tests/drivers/google/buckets_test.rb +2 -2
- data/tests/drivers/google/common.rb +3 -3
- data/tests/test_helper.rb +28 -0
- data/views/api/show.html.haml +2 -2
- data/views/api/show.xml.haml +1 -1
- data/views/buckets/index.html.haml +1 -1
- data/views/cimi/cloudEntryPoint/index.xml.haml +1 -1
- data/views/cimi/collection/index.html.haml +3 -3
- data/views/cimi/collection/response.xml.haml +1 -1
- data/views/cimi/error.html.haml +1 -1
- data/views/cimi/errors/500.xml.haml +1 -1
- data/views/cimi/layout.html.haml +1 -1
- data/views/cimi/machine_configurations/show.html.haml +2 -2
- data/views/cimi/machine_configurations/show.xml.haml +1 -1
- data/views/cimi/machine_images/show.html.haml +2 -2
- data/views/cimi/machine_images/show.xml.haml +1 -1
- data/views/cimi/machines/show.html.haml +2 -2
- data/views/cimi/machines/show.xml.haml +1 -1
- data/views/cimi/volumes/show.html.haml +2 -2
- data/views/cimi/volumes/show.xml.haml +1 -1
- data/views/docs/collection.html.haml +1 -1
- data/views/docs/collection.xml.haml +2 -2
- data/views/docs/index.html.haml +1 -1
- data/views/docs/index.xml.haml +1 -1
- data/views/docs/operation.xml.haml +1 -1
- data/views/error.html.haml +1 -1
- data/views/errors/500.html.haml +7 -4
- data/views/firewalls/index.html.haml +1 -1
- data/views/firewalls/show.html.haml +1 -1
- data/views/images/show.html.haml +2 -2
- data/views/index.html.haml +9 -0
- data/views/instance_states/show.html.haml +1 -1
- data/views/instances/run_command.html.haml +1 -1
- data/views/instances/show.html.haml +2 -2
- data/views/keys/index.html.haml +1 -1
- data/views/layout.html.haml +1 -1
- data/views/load_balancers/index.html.haml +1 -1
- data/views/load_balancers/show.html.haml +3 -3
- data/views/storage_snapshots/show.html.haml +1 -1
- data/views/storage_volumes/attach.html.haml +1 -1
- data/views/storage_volumes/index.html.haml +1 -1
- data/views/storage_volumes/show.html.haml +4 -4
- metadata +40 -43
- data/lib/cimi/models/address_collection.rb +0 -34
- data/lib/cimi/models/address_template_collection.rb +0 -34
- data/lib/cimi/models/entity_metadata_collection.rb +0 -31
- data/lib/cimi/models/machine_admin_collection.rb +0 -34
- data/lib/cimi/models/machine_collection.rb +0 -37
- data/lib/cimi/models/machine_configuration_collection.rb +0 -36
- data/lib/cimi/models/machine_image_collection.rb +0 -36
- data/lib/cimi/models/machine_template_collection.rb +0 -36
- data/lib/cimi/models/routing_group_collection.rb +0 -34
- data/lib/cimi/models/routing_group_template_collection.rb +0 -35
- data/lib/cimi/models/volume_collection.rb +0 -36
- data/lib/cimi/models/volume_configuration_collection.rb +0 -36
- data/lib/cimi/models/volume_image_collection.rb +0 -36
- data/lib/cimi/models/volume_template_collection.rb +0 -36
- data/lib/cimi/models/vsp_collection.rb +0 -34
- data/lib/cimi/models/vsp_configuration_collection.rb +0 -34
- data/lib/cimi/models/vsp_template_collection.rb +0 -34
- data/lib/deltacloud/helpers/url_helper.rb +0 -115
data/lib/deltacloud/helpers.rb
CHANGED
@@ -15,81 +15,6 @@
|
|
15
15
|
|
16
16
|
require_relative 'helpers/driver_helper'
|
17
17
|
require_relative 'helpers/auth_helper'
|
18
|
-
require_relative 'helpers/url_helper'
|
19
18
|
require_relative 'helpers/deltacloud_helper'
|
20
19
|
require_relative 'helpers/rabbit_helper'
|
21
20
|
require_relative 'helpers/blob_stream_helper'
|
22
|
-
|
23
|
-
module Deltacloud::Collections
|
24
|
-
class Base < Sinatra::Base
|
25
|
-
|
26
|
-
include Sinatra::Rabbit
|
27
|
-
extend Deltacloud::Helpers::Drivers
|
28
|
-
include Sinatra::Rabbit::Features
|
29
|
-
|
30
|
-
helpers Deltacloud::Helpers::Drivers
|
31
|
-
helpers Sinatra::AuthHelper
|
32
|
-
helpers Sinatra::UrlForHelper
|
33
|
-
helpers Rack::RespondTo::Helpers
|
34
|
-
helpers Deltacloud::Helpers::Application
|
35
|
-
|
36
|
-
register Rack::RespondTo
|
37
|
-
|
38
|
-
enable :xhtml
|
39
|
-
enable :dump_errors
|
40
|
-
enable :show_errors
|
41
|
-
enable :method_override
|
42
|
-
disable :show_exceptions
|
43
|
-
|
44
|
-
set :config, Deltacloud[:deltacloud]
|
45
|
-
set :root_url, config.root_url
|
46
|
-
set :root_path, config.root_url
|
47
|
-
set :version, config.version
|
48
|
-
set :root, File.join(File.dirname(__FILE__), '..', '..')
|
49
|
-
set :views, root + '/views'
|
50
|
-
set :public_folder, root + '/public'
|
51
|
-
|
52
|
-
Sinatra::Rabbit.set :root_path, "#{config.root_url}/"
|
53
|
-
|
54
|
-
error do
|
55
|
-
report_error
|
56
|
-
end
|
57
|
-
|
58
|
-
error Deltacloud::ExceptionHandler::ValidationFailure do
|
59
|
-
report_error
|
60
|
-
end
|
61
|
-
|
62
|
-
before do
|
63
|
-
# Respond with 400, If we don't get a http Host header,
|
64
|
-
halt 400, "Unable to find HTTP Host header" if @env['HTTP_HOST'] == nil
|
65
|
-
end
|
66
|
-
|
67
|
-
after do
|
68
|
-
headers 'Server' => 'Apache-Deltacloud/' + settings.version
|
69
|
-
headers 'X-Deltacloud-Driver' => driver_name
|
70
|
-
if provider_name
|
71
|
-
headers 'X-Deltacloud-Provider' => provider_name
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.new_route_for(route, &block)
|
76
|
-
get route_for('/' + route.to_s + '/new') do
|
77
|
-
instance_eval(&block) if block_given?
|
78
|
-
respond_to do |format|
|
79
|
-
format.html do
|
80
|
-
haml :"#{route}/new"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.check_features(opts={})
|
87
|
-
Sinatra::Rabbit.set :check_features, opts[:for]
|
88
|
-
end
|
89
|
-
|
90
|
-
def self.route_for(url)
|
91
|
-
"#{settings.root_url}#{url}"
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
end
|
@@ -18,22 +18,6 @@ module Deltacloud::Helpers
|
|
18
18
|
|
19
19
|
require 'benchmark'
|
20
20
|
|
21
|
-
def supported_collections
|
22
|
-
collection_arr = []
|
23
|
-
Deltacloud::Collections.deltacloud_modules.each do |m|
|
24
|
-
m.collections.each do |c|
|
25
|
-
# Get the required capability for the :index operation (like 'realms' or 'instance_state_machine')
|
26
|
-
index_operation_capability = c.operation(:index).required_capability
|
27
|
-
# Then use this capability to check if the 'capability' lambda defined
|
28
|
-
# for the Sinatra::Base class evaluate to 'true'
|
29
|
-
next if m.settings.respond_to?(:capability) and !m.settings.capability(index_operation_capability)
|
30
|
-
yield c if block_given?
|
31
|
-
collection_arr << c
|
32
|
-
end
|
33
|
-
end
|
34
|
-
collection_arr
|
35
|
-
end
|
36
|
-
|
37
21
|
def auth_feature_name
|
38
22
|
return 'key' if driver.class.has_feature?(:instances, :authentication_key)
|
39
23
|
return 'password' if driver.class.has_feature?(:instances, :authentication_password)
|
@@ -49,18 +33,10 @@ module Deltacloud::Helpers
|
|
49
33
|
end
|
50
34
|
|
51
35
|
def filter_all(model)
|
52
|
-
filter = {}
|
53
|
-
filter.merge!(:id => params[:id]) if params[:id]
|
54
|
-
filter.merge!(:architecture => params[:architecture]) if params[:architecture]
|
55
|
-
filter.merge!(:owner_id => params[:owner_id]) if params[:owner_id]
|
56
|
-
filter.merge!(:state => params[:state]) if params[:state]
|
57
|
-
filter = {} if filter.keys.size.eql?(0)
|
58
36
|
begin
|
59
|
-
@benchmark = Benchmark.measure
|
60
|
-
|
61
|
-
|
62
|
-
rescue
|
63
|
-
@exception = $!
|
37
|
+
@benchmark = Benchmark.measure { @elements = driver.send(model.to_sym, credentials, params) }
|
38
|
+
rescue => e
|
39
|
+
@exception = e
|
64
40
|
end
|
65
41
|
if @elements
|
66
42
|
headers['X-Backend-Runtime'] = @benchmark.real.to_s
|
@@ -105,9 +81,24 @@ module Deltacloud::Helpers
|
|
105
81
|
@error, @code = (request.env['sinatra.error'] || @exception), code
|
106
82
|
@code = 500 if not @code and not @error.class.method_defined? :code
|
107
83
|
response.status = @code || @error.code
|
84
|
+
log = Deltacloud::ExceptionHandler.logger
|
85
|
+
message = @error.respond_to?(:message) ? @error.message : translate_error_code(@code)
|
86
|
+
backtrace = (@error.respond_to?(:backtrace) and !@error.backtrace.nil?) ?
|
87
|
+
"\n\n#{@error.backtrace[0..10].join("\n")}\n\n" : ''
|
88
|
+
log.error "[#{@code}] #{[@error.class.to_s, message].join(':')}#{backtrace}"
|
108
89
|
respond_to do |format|
|
109
90
|
format.xml { haml :"errors/#{@code || @error.code}", :layout => false }
|
110
|
-
format.
|
91
|
+
format.json { xml_to_json("errors/#{@code || @error.code}") }
|
92
|
+
format.html {
|
93
|
+
begin
|
94
|
+
haml :"errors/#{@code || @error.code}", :layout => :error
|
95
|
+
rescue RuntimeError
|
96
|
+
# If the HTML representation of error is missing, then try to report
|
97
|
+
# it through XML
|
98
|
+
@media_type=:xml
|
99
|
+
haml :"errors/#{@code || @error.code}", :layout => false
|
100
|
+
end
|
101
|
+
}
|
111
102
|
end
|
112
103
|
end
|
113
104
|
|
@@ -286,6 +277,53 @@ module Deltacloud::Helpers
|
|
286
277
|
not features_arr.empty?
|
287
278
|
end
|
288
279
|
|
280
|
+
module SinatraHelper
|
281
|
+
|
282
|
+
def new_route_for(route, &block)
|
283
|
+
get '/%s/new' % route.to_s do
|
284
|
+
instance_eval(&block) if block_given?
|
285
|
+
respond_to do |format|
|
286
|
+
format.html do
|
287
|
+
haml :"#{route}/new"
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
def check_features(opts={})
|
294
|
+
Sinatra::Rabbit.set :check_features, opts[:for]
|
295
|
+
end
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
def Application.included(klass)
|
300
|
+
klass.extend SinatraHelper
|
301
|
+
end
|
302
|
+
|
303
|
+
HTML_ESCAPE = { '&' => '&', '>' => '>', '<' => '<', '"' => '"' }
|
304
|
+
|
305
|
+
def h(s)
|
306
|
+
s.to_s.gsub(/[&"><]/n) { |special| HTML_ESCAPE[special] }
|
307
|
+
end
|
308
|
+
|
309
|
+
def bt(trace)
|
310
|
+
return trace.join("\n") if params['fulltrace']
|
311
|
+
app_path = File::expand_path("../../..", __FILE__)
|
312
|
+
dots = false
|
313
|
+
|
314
|
+
trace = trace.map { |t| t.match(%r{^#{app_path}(.*)$}) ? "$app#{$1}" : "..." }.select do |t|
|
315
|
+
if t == "..."
|
316
|
+
keep = ! dots
|
317
|
+
dots = true
|
318
|
+
else
|
319
|
+
keep = true
|
320
|
+
dots = false
|
321
|
+
end
|
322
|
+
keep
|
323
|
+
end
|
324
|
+
"[\nAbbreviated trace\n pass fulltrace=1 as query param to see everything\n $app = #{app_path}\n]\n" + trace.join("\n")
|
325
|
+
end
|
326
|
+
|
289
327
|
private
|
290
328
|
def hardware_property_unit(prop)
|
291
329
|
u = ::Deltacloud::HardwareProfile::unit(prop)
|
@@ -17,6 +17,13 @@ module Deltacloud::Helpers
|
|
17
17
|
|
18
18
|
module Drivers
|
19
19
|
|
20
|
+
# This will make the Driver helpers, like 'driver'
|
21
|
+
# accessible on class level
|
22
|
+
#
|
23
|
+
def Drivers.included(klass)
|
24
|
+
klass.extend Deltacloud::Helpers::Drivers
|
25
|
+
end
|
26
|
+
|
20
27
|
def driver_symbol
|
21
28
|
driver_name.to_sym
|
22
29
|
end
|
@@ -32,3 +32,54 @@ Sinatra::Rabbit::Collection.class_eval do
|
|
32
32
|
|
33
33
|
end
|
34
34
|
|
35
|
+
module Sinatra::Rabbit
|
36
|
+
|
37
|
+
module URLHelper
|
38
|
+
def url_for(path); url(path); end
|
39
|
+
def root_url; settings.root_url; end
|
40
|
+
def base_uri; url_for('/').gsub(/\/$/,''); end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.URLFor(collections)
|
44
|
+
collections.each do |c|
|
45
|
+
c.operations.each do |operation|
|
46
|
+
URLHelper.instance_eval(&generate_url_helper_for(c, operation)[0])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
URLHelper
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.generate_url_helper_for(collection, operation)
|
53
|
+
operation_name = operation.operation_name.to_s
|
54
|
+
collection_name = collection.collection_name.to_s
|
55
|
+
|
56
|
+
# Construct OPERATION_COLLECTION_URL helper
|
57
|
+
# The :index and :create operation does not get any prefix
|
58
|
+
#
|
59
|
+
|
60
|
+
helper_method_name = case operation_name
|
61
|
+
when 'index' then collection_name
|
62
|
+
when 'show' then collection_name.singularize
|
63
|
+
else operation_name + '_' + collection_name.singularize
|
64
|
+
end
|
65
|
+
|
66
|
+
helper_method_name += '_url'
|
67
|
+
|
68
|
+
[Proc.new do
|
69
|
+
define_method helper_method_name do |*args|
|
70
|
+
if (opts = args.first).kind_of? Hash
|
71
|
+
path = operation.full_path.convert_query_params(opts)
|
72
|
+
elsif !args.empty? and (obj_id = args.first)
|
73
|
+
path = operation.full_path.convert_query_params(:id => obj_id)
|
74
|
+
elsif operation_name == 'show'
|
75
|
+
path = collection.operation(:index).full_path
|
76
|
+
else
|
77
|
+
path = operation.full_path
|
78
|
+
end
|
79
|
+
path.slice!(root_url)
|
80
|
+
url(path)
|
81
|
+
end unless respond_to?(helper_method_name)
|
82
|
+
end, helper_method_name]
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
data/lib/deltacloud/server.rb
CHANGED
@@ -36,20 +36,20 @@ module Deltacloud
|
|
36
36
|
use Deltacloud[:deltacloud].logger unless RUBY_PLATFORM == 'java'
|
37
37
|
use Rack::Date
|
38
38
|
use Rack::ETag
|
39
|
-
use Rack::MatrixParams
|
40
39
|
use Rack::DriverSelect
|
41
|
-
use Rack::Accept
|
42
|
-
use Rack::MediaType
|
43
40
|
|
44
41
|
include Deltacloud::Helpers
|
45
42
|
include Deltacloud::Collections
|
46
43
|
|
44
|
+
helpers Sinatra::Rabbit::URLFor(Deltacloud.collections)
|
45
|
+
|
47
46
|
set :config, Deltacloud[:deltacloud]
|
48
47
|
|
49
|
-
get
|
48
|
+
get '/' do
|
50
49
|
if params[:force_auth]
|
51
50
|
return [401, 'Authentication failed'] unless driver.valid_credentials?(credentials)
|
52
51
|
end
|
52
|
+
@collections = driver.supported_collections(credentials)
|
53
53
|
respond_to do |format|
|
54
54
|
format.xml { haml :"api/show" }
|
55
55
|
format.json { xml_to_json :"api/show" }
|
@@ -57,24 +57,22 @@ module Deltacloud
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
options
|
61
|
-
headers 'Allow' => supported_collections { |c| c.collection_name }.join(',')
|
60
|
+
options '/' do
|
61
|
+
headers 'Allow' => driver.supported_collections(credentials) { |c| c.collection_name }.join(',')
|
62
62
|
end
|
63
63
|
|
64
|
-
post
|
64
|
+
post '/' do
|
65
65
|
param_driver, param_provider = params["driver"], params["provider"]
|
66
66
|
if param_driver
|
67
|
-
redirect "#{
|
67
|
+
redirect "#{root_url};driver=#{param_driver}", 301
|
68
68
|
elsif param_provider && param_provider != "default"
|
69
|
-
|
70
|
-
|
71
|
-
if current_matrix_driver
|
72
|
-
redirect "#{Deltacloud.config[:deltacloud].root_url}\;driver=#{$2}\;provider=#{param_provider}", 301
|
69
|
+
if request.referrer and request.referrer[/\;(driver)=(\w*).*$/i]
|
70
|
+
redirect "#{root_url};driver=#{$2}\;provider=#{param_provider}", 301
|
73
71
|
else
|
74
|
-
redirect "#{
|
72
|
+
redirect "#{root_url};provider=#{param_provider}", 301
|
75
73
|
end
|
76
74
|
else
|
77
|
-
redirect
|
75
|
+
redirect url('/'), 301
|
78
76
|
end
|
79
77
|
end
|
80
78
|
|
data/lib/deltacloud/version.rb
CHANGED
data/lib/deltacloud_rack.rb
CHANGED
@@ -42,6 +42,10 @@ module Deltacloud
|
|
42
42
|
Deltacloud[frontend].klass eval('::'+Deltacloud[frontend].klass)
|
43
43
|
end
|
44
44
|
|
45
|
+
def self.enabled_frontends
|
46
|
+
@config.keys.select { |k| frontend_required?(k) }.map { |f| Deltacloud[f] }
|
47
|
+
end
|
48
|
+
|
45
49
|
def self.frontend_required?(frontend)
|
46
50
|
true unless Deltacloud[frontend].klass.kind_of? String
|
47
51
|
end
|
@@ -52,6 +56,26 @@ module Deltacloud
|
|
52
56
|
@default_frontend || config[:deltacloud]
|
53
57
|
end
|
54
58
|
|
59
|
+
require 'sinatra/base'
|
60
|
+
require_relative './deltacloud/helpers/deltacloud_helper'
|
61
|
+
require_relative './sinatra/rack_accept'
|
62
|
+
|
63
|
+
class IndexApp < Sinatra::Base
|
64
|
+
|
65
|
+
helpers Deltacloud::Helpers::Application
|
66
|
+
register Rack::RespondTo
|
67
|
+
|
68
|
+
set :views, File.join(File.dirname(__FILE__), '..', 'views')
|
69
|
+
|
70
|
+
get '/' do
|
71
|
+
respond_to do |format|
|
72
|
+
format.xml { haml :'index', :layout => false }
|
73
|
+
format.html { haml :'index', :layout => false }
|
74
|
+
format.json { xml_to_json "index" }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
55
79
|
class Server
|
56
80
|
|
57
81
|
attr_reader :name
|
@@ -66,8 +90,8 @@ module Deltacloud
|
|
66
90
|
@root_url = opts[:root_url]
|
67
91
|
@version = opts[:version]
|
68
92
|
@klass = opts[:klass]
|
69
|
-
@logger = opts[:logger] || Rack::DeltacloudLogger
|
70
|
-
@default_driver = opts[:default_driver] || :mock
|
93
|
+
@logger = opts[:logger] || Rack::DeltacloudLogger.setup(ENV['API_LOG'], ENV['API_VERBOSE'])
|
94
|
+
@default_driver = opts[:default_driver] || ENV['API_DRIVER'] || :mock
|
71
95
|
instance_eval(&block)
|
72
96
|
end
|
73
97
|
|
data/lib/ec2/query_parser.rb
CHANGED
@@ -20,7 +20,7 @@ module Deltacloud::EC2
|
|
20
20
|
MAPPINGS = {
|
21
21
|
:describe_availability_zones => { :method => :realms, :params => { 'ZoneName.1' => :id } },
|
22
22
|
:describe_images => { :method => :images, :params => { 'ImageId.1' => :id }},
|
23
|
-
:describe_instances => { :method => :instances, :params => {} },
|
23
|
+
:describe_instances => { :method => :instances, :params => {'InstanceId.1' => :id } },
|
24
24
|
:describe_key_pairs => { :method => :keys, :params => {} },
|
25
25
|
:create_key_pair => { :method => :create_key, :params => { 'KeyName' => :key_name }},
|
26
26
|
:delete_key_pair => { :method => :destroy_key, :params => { 'KeyName' => :id }},
|
@@ -56,14 +56,29 @@ module Deltacloud::EC2
|
|
56
56
|
def perform!(credentials, driver)
|
57
57
|
@result = case deltacloud_method
|
58
58
|
when :create_instance then driver.send(deltacloud_method, credentials, deltacloud_method_params.delete(:image_id), deltacloud_method_params)
|
59
|
-
when :stop_instance then driver
|
60
|
-
when :start_instance then driver
|
59
|
+
when :stop_instance then instance_action(driver, deltacloud_method, credentials, deltacloud_method_params.delete(:id))
|
60
|
+
when :start_instance then instance_action(driver, deltacloud_method, credentials, deltacloud_method_params.delete(:id))
|
61
61
|
when :destroy_instance then driver.send(deltacloud_method, credentials, deltacloud_method_params.delete(:id))
|
62
62
|
when :reboot_instance then driver.send(deltacloud_method, credentials, deltacloud_method_params.delete(:id))
|
63
63
|
else driver.send(deltacloud_method, credentials, deltacloud_method_params)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
+
# Some drivers, like RHEV-M does not return the instance object
|
68
|
+
# but just notify client that the action was executed successfully.
|
69
|
+
#
|
70
|
+
# If we not received an Instance object, then we need to do additional
|
71
|
+
# query.
|
72
|
+
#
|
73
|
+
def instance_action(driver, action, credentials, id)
|
74
|
+
instance = driver.send(action, credentials, id)
|
75
|
+
if instance.kind_of? Instance
|
76
|
+
instance
|
77
|
+
else
|
78
|
+
driver.instance(credentials, :id => id)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
67
82
|
def to_xml(context)
|
68
83
|
ResultParser.parse(action, @result, context)
|
69
84
|
end
|
data/lib/sinatra/rack_accept.rb
CHANGED
@@ -23,6 +23,9 @@ module Rack
|
|
23
23
|
# We need to overide the default render method to supply correct path to the
|
24
24
|
# template, since Sinatra is by default looking in the current __FILE__ path
|
25
25
|
def self.registered(app)
|
26
|
+
app.use Rack::Accept
|
27
|
+
app.use Rack::MediaType
|
28
|
+
app.helpers Rack::RespondTo::Helpers
|
26
29
|
app.class_eval do
|
27
30
|
alias :render_without_format :render
|
28
31
|
def render(*args, &block)
|
@@ -48,12 +51,14 @@ module Rack
|
|
48
51
|
# rack-accept middleware.
|
49
52
|
def self.included(klass)
|
50
53
|
klass.class_eval do
|
51
|
-
|
54
|
+
alias_method :original_content_type, :content_type
|
55
|
+
|
52
56
|
def content_type(*args)
|
53
|
-
|
57
|
+
original_content_type(*args)
|
54
58
|
request.env['rack-accept.formats'] = { args.first.to_sym => 1 }
|
55
59
|
response['Content-Type']
|
56
60
|
end
|
61
|
+
|
57
62
|
end
|
58
63
|
end
|
59
64
|
|