deltacloud-core 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +99 -141
- data/bin/deltacloudd +4 -1
- data/config.ru +13 -6
- data/config/drivers/aruba.yaml +8 -0
- data/config/drivers/fgcp.yaml +3 -2
- data/deltacloud-core.gemspec +13 -9
- data/lib/cimi/collections/cloud_entry_point.rb +1 -1
- data/lib/cimi/models.rb +1 -7
- data/lib/cimi/models/base.rb +1 -4
- data/lib/cimi/models/cloud_entry_point.rb +14 -0
- data/lib/cimi/models/machine.rb +4 -4
- data/lib/cimi/models/machine_admin.rb +1 -0
- data/lib/cimi/models/machine_configuration.rb +4 -4
- data/lib/cimi/models/schema.rb +17 -14
- data/lib/cimi/models/volume_image.rb +1 -1
- data/lib/cimi/server.rb +1 -1
- data/lib/deltacloud/api.rb +55 -3
- data/lib/deltacloud/collections/addresses.rb +1 -1
- data/lib/deltacloud/collections/buckets.rb +12 -10
- data/lib/deltacloud/collections/firewalls.rb +2 -1
- data/lib/deltacloud/collections/hardware_profiles.rb +1 -1
- data/lib/deltacloud/collections/images.rb +2 -2
- data/lib/deltacloud/collections/instance_states.rb +6 -3
- data/lib/deltacloud/collections/instances.rb +2 -1
- data/lib/deltacloud/collections/keys.rb +6 -2
- data/lib/deltacloud/collections/load_balancers.rb +8 -7
- data/lib/deltacloud/collections/metrics.rb +2 -1
- data/lib/deltacloud/collections/realms.rb +1 -1
- data/lib/deltacloud/collections/storage_snapshots.rb +2 -1
- data/lib/deltacloud/collections/storage_volumes.rb +2 -2
- data/lib/deltacloud/core_ext.rb +1 -7
- data/lib/deltacloud/core_ext/hash.rb +7 -5
- data/lib/deltacloud/core_ext/string.rb +1 -0
- data/lib/deltacloud/drivers/aruba/aruba_driver.rb +469 -0
- data/lib/deltacloud/drivers/base_driver.rb +12 -17
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +50 -22
- data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +1 -1
- data/lib/deltacloud/drivers/exceptions.rb +12 -2
- data/lib/deltacloud/drivers/features.rb +8 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +21 -6
- data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +169 -57
- data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +1 -1
- data/lib/deltacloud/drivers/mock/mock_client.rb +2 -0
- data/lib/deltacloud/drivers/mock/mock_driver.rb +101 -13
- data/lib/deltacloud/drivers/opennebula/occi_client.rb +12 -6
- data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +10 -18
- data/lib/deltacloud/drivers/openstack/openstack_driver.rb +46 -1
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +17 -17
- data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +4 -4
- data/lib/deltacloud/helpers.rb +4 -4
- data/lib/deltacloud/helpers/blob_stream_helper.rb +4 -6
- data/lib/deltacloud/helpers/deltacloud_helper.rb +17 -1
- data/lib/deltacloud/helpers/driver_helper.rb +7 -3
- data/lib/deltacloud/helpers/url_helper.rb +4 -4
- data/lib/deltacloud/models/address.rb +1 -1
- data/lib/deltacloud/models/base_model.rb +0 -14
- data/lib/deltacloud/models/bucket.rb +0 -10
- data/lib/deltacloud/models/hardware_profile.rb +5 -26
- data/lib/deltacloud/models/image.rb +0 -12
- data/lib/deltacloud/models/instance.rb +6 -22
- data/lib/deltacloud/models/key.rb +2 -2
- data/lib/deltacloud/models/metric.rb +1 -1
- data/lib/deltacloud/models/storage_snapshot.rb +4 -0
- data/lib/deltacloud/server.rb +8 -2
- data/lib/deltacloud_rack.rb +40 -10
- data/lib/ec2/query_parser.rb +9 -4
- data/lib/ec2/server.rb +1 -1
- data/lib/ec2/views/create_key_pair.haml +3 -0
- data/lib/ec2/views/delete_key_pair.haml +1 -0
- data/lib/ec2/views/describe_availability_zones.haml +6 -0
- data/lib/ec2/views/describe_images.haml +10 -0
- data/lib/ec2/views/describe_instance_set.haml +24 -0
- data/lib/ec2/views/describe_instances.haml +9 -0
- data/lib/ec2/views/describe_key_pairs.haml +5 -0
- data/lib/ec2/views/error.haml +4 -0
- data/lib/ec2/views/instance_action.haml +9 -0
- data/lib/ec2/views/reboot_instances.haml +1 -0
- data/lib/ec2/views/run_instances.haml +7 -0
- data/lib/ec2/views/start_instances.haml +1 -0
- data/lib/ec2/views/stop_instances.haml +1 -0
- data/lib/ec2/views/terminate_instances.haml +9 -0
- data/lib/sinatra.rb +0 -1
- data/lib/sinatra/rack_accept.rb +1 -1
- data/lib/sinatra/rack_driver_select.rb +2 -2
- data/lib/sinatra/rack_etag.rb +5 -1
- data/lib/sinatra/rack_logger.rb +127 -0
- data/lib/sinatra/rack_matrix_params.rb +1 -1
- data/tests/cimi/collections/cloud_entry_point_test.rb +46 -0
- data/tests/cimi/collections/common.rb +17 -0
- data/tests/cimi/collections/machine_images_test.rb +44 -0
- data/tests/cimi/collections/machines_test.rb +41 -0
- data/tests/cimi/spec/cimi/model/machine_admin_spec.rb +35 -0
- data/tests/cimi/spec/cimi/model/machine_configuration_spec.rb +31 -0
- data/tests/cimi/spec/cimi/model/machine_image_spec.rb +33 -0
- data/tests/cimi/spec/cimi/model/machine_spec.rb +32 -0
- data/tests/cimi/spec/cimi/model/machine_template_spec.rb +32 -0
- data/tests/cimi/spec/cimi/model/schema_spec.rb +245 -0
- data/tests/cimi/spec/cimi/model/volume_configuration_spec.rb +34 -0
- data/tests/cimi/spec/cimi/model/volume_image_spec.rb +33 -0
- data/tests/cimi/spec/cimi/model/volume_spec.rb +32 -0
- data/tests/cimi/spec/cimi/model/volume_template_spec.rb +32 -0
- data/tests/cimi/spec/spec_helper.rb +136 -0
- data/tests/deltacloud/base_collection_test.rb +30 -0
- data/tests/deltacloud/collections/buckets_collection_test.rb +65 -0
- data/tests/deltacloud/collections/drivers_collection_test.rb +37 -0
- data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +53 -0
- data/tests/deltacloud/collections/images_collection_test.rb +59 -0
- data/tests/deltacloud/collections/instance_states_collection_test.rb +34 -0
- data/tests/deltacloud/collections/instances_collection_test.rb +63 -0
- data/tests/deltacloud/collections/keys_collection_test.rb +63 -0
- data/tests/deltacloud/collections_test.rb +35 -0
- data/tests/deltacloud/common.rb +14 -0
- data/tests/deltacloud/deltacloud_helper_test.rb +55 -0
- data/tests/deltacloud/drivers_test.rb +73 -0
- data/tests/deltacloud/rack_test.rb +51 -0
- data/tests/deltacloud/server_test.rb +149 -0
- data/tests/{api → deprecated/api}/common.rb +0 -0
- data/tests/{api → deprecated/api}/driver_test.rb +0 -0
- data/tests/deprecated/api/library_test.rb +6 -0
- data/tests/{cimi → deprecated/cimi}/features/step_definitions/common_steps.rb +0 -0
- data/tests/{cimi → deprecated/cimi}/features/step_definitions/machine_images_steps.rb +0 -0
- data/tests/{cimi → deprecated/cimi}/features/step_definitions/machines_steps.rb +0 -0
- data/tests/{cimi → deprecated/cimi}/features/step_definitions/volumes_steps.rb +0 -0
- data/tests/{cimi → deprecated/cimi}/features/support/env.rb +0 -0
- data/tests/{common.rb → deprecated/common.rb} +0 -0
- data/tests/{core_ext → deprecated/core_ext}/string.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/ec2/api_test.rb +0 -0
- data/tests/deprecated/drivers/ec2/common.rb +23 -0
- data/tests/{drivers → deprecated/drivers}/ec2/drivers_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/ec2/hardware_profiles_test.rb +0 -0
- data/tests/deprecated/drivers/ec2/images_test.rb +230 -0
- data/tests/{drivers → deprecated/drivers}/ec2/instances_test.rb +0 -0
- data/tests/deprecated/drivers/ec2/keys_test.rb +181 -0
- data/tests/deprecated/drivers/ec2/realms_test.rb +146 -0
- data/tests/{drivers → deprecated/drivers}/fgcp/api_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/fgcp/hardware_profiles_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/fgcp/realms_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/fgcp/setup.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/google/api_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/google/buckets_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/google/common.rb +2 -2
- data/tests/{drivers → deprecated/drivers}/mock/api_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/mock/buckets_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/mock/common.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/mock/drivers_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/mock/hardware_profiles_test.rb +0 -0
- data/tests/deprecated/drivers/mock/images_test.rb +197 -0
- data/tests/deprecated/drivers/mock/instances_test.rb +343 -0
- data/tests/deprecated/drivers/mock/keys_test.rb +161 -0
- data/tests/deprecated/drivers/mock/realms_test.rb +132 -0
- data/tests/deprecated/drivers/mock/storage_snapshots_test.rb +114 -0
- data/tests/deprecated/drivers/mock/storage_volumes_test.rb +122 -0
- data/tests/{drivers → deprecated/drivers}/openstack/api_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/openstack/common.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/openstack/hardware_profiles_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/openstack/images_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/openstack/instances_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/openstack/realms_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/rackspace/api_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/rackspace/buckets_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/rackspace/common.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/rackspace/hardware_profiles_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/rackspace/images_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/rackspace/instances_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/rackspace/realms_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/rhevm/api_test.rb +0 -0
- data/tests/deprecated/drivers/rhevm/common.rb +21 -0
- data/tests/{drivers → deprecated/drivers}/rhevm/hardware_profiles_test.rb +0 -0
- data/tests/deprecated/drivers/rhevm/images_test.rb +48 -0
- data/tests/{drivers → deprecated/drivers}/rhevm/instances_test.rb +0 -0
- data/tests/deprecated/drivers/rhevm/realms_test.rb +40 -0
- data/tests/{minitest_common.rb → deprecated/minitest_common.rb} +0 -0
- data/tests/{minitest_common_api_test.rb → deprecated/minitest_common_api_test.rb} +0 -0
- data/tests/{rabbit_test.rb → deprecated/rabbit_test.rb} +0 -0
- data/tests/drivers/base/base_driver_test.rb +124 -0
- data/tests/{api → drivers/base}/library_test.rb +2 -8
- data/tests/drivers/ec2/common.rb +23 -15
- data/tests/drivers/ec2/images_test.rb +30 -211
- data/tests/drivers/ec2/instance_test.rb +104 -0
- data/tests/drivers/ec2/keys_test.rb +32 -161
- data/tests/drivers/ec2/realms_test.rb +26 -128
- data/tests/drivers/ec2/storage_snapshots_test.rb +54 -0
- data/tests/drivers/mock/images_test.rb +37 -179
- data/tests/drivers/mock/instances_test.rb +103 -340
- data/tests/drivers/mock/keys_test.rb +30 -145
- data/tests/drivers/mock/realms_test.rb +23 -118
- data/tests/drivers/mock/storage_snapshots_test.rb +23 -100
- data/tests/drivers/mock/storage_volumes_test.rb +41 -104
- data/tests/drivers/models/address_test.rb +18 -0
- data/tests/drivers/models/base_test.rb +33 -0
- data/tests/drivers/models/blob_test.rb +18 -0
- data/tests/drivers/models/hardware_profile_test.rb +52 -0
- data/tests/drivers/models/instance_address_test.rb +24 -0
- data/tests/drivers/models/instance_profile_test.rb +21 -0
- data/tests/drivers/models/instance_test.rb +29 -0
- data/tests/drivers/models/keys_test.rb +25 -0
- data/tests/drivers/models/metrics_test.rb +20 -0
- data/tests/drivers/rhevm/common.rb +15 -15
- data/tests/drivers/rhevm/images_test.rb +61 -36
- data/tests/drivers/rhevm/instance_test.rb +104 -0
- data/tests/drivers/rhevm/provider_test.rb +48 -0
- data/tests/drivers/rhevm/realms_test.rb +40 -37
- data/tests/ec2/common.rb +24 -0
- data/tests/ec2/query_parser_test.rb +98 -0
- data/tests/ec2/server_test.rb +45 -0
- data/tests/helpers/core_ext/array_test.rb +24 -0
- data/tests/helpers/core_ext/hash_test.rb +42 -0
- data/tests/helpers/core_ext/integer_test.rb +19 -0
- data/tests/helpers/core_ext/string_test.rb +74 -0
- data/tests/test_helper.rb +66 -0
- data/views/api/show.html.haml +1 -2
- data/views/api/show.xml.haml +1 -2
- data/views/blobs/show.xml.haml +1 -2
- data/views/keys/new.html.haml +9 -2
- data/views/load_balancers/new.html.haml +35 -34
- data/views/metrics/index.html.haml +1 -1
- data/views/metrics/show.html.haml +2 -2
- data/views/metrics/show.xml.haml +6 -2
- data/views/storage_volumes/attach.html.haml +1 -1
- data/views/storage_volumes/show.html.haml +1 -1
- metadata +853 -544
- data/lib/sinatra/accept_media_types.rb +0 -154
data/lib/ec2/query_parser.rb
CHANGED
@@ -31,6 +31,10 @@ module Deltacloud::EC2
|
|
31
31
|
:terminate_instances => { :method => :destroy_instance, :params => { 'InstanceId.1' => :id }},
|
32
32
|
}
|
33
33
|
|
34
|
+
def self.mappings
|
35
|
+
MAPPINGS
|
36
|
+
end
|
37
|
+
|
34
38
|
attr_reader :action
|
35
39
|
|
36
40
|
def initialize(action)
|
@@ -38,12 +42,13 @@ module Deltacloud::EC2
|
|
38
42
|
end
|
39
43
|
|
40
44
|
def deltacloud_method
|
41
|
-
|
45
|
+
self.class.mappings[action.action][:method]
|
42
46
|
end
|
43
47
|
|
44
48
|
def deltacloud_method_params
|
45
|
-
|
46
|
-
|
49
|
+
parameters = action.parameters.dup
|
50
|
+
self.class.mappings[action.action][:params].inject({}) do |result, p|
|
51
|
+
result[p.last] = parameters.delete(p.first)
|
47
52
|
result.delete_if { |k,v| v.nil? }
|
48
53
|
end
|
49
54
|
end
|
@@ -137,7 +142,7 @@ module Deltacloud::EC2
|
|
137
142
|
end
|
138
143
|
|
139
144
|
def valid_actions
|
140
|
-
ActionHandler::
|
145
|
+
ActionHandler::mappings.keys
|
141
146
|
end
|
142
147
|
|
143
148
|
def valid_action?
|
data/lib/ec2/server.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
%return true
|
@@ -0,0 +1,24 @@
|
|
1
|
+
%instanceSet
|
2
|
+
- object.each do |item|
|
3
|
+
%item
|
4
|
+
%instanceId=item.id
|
5
|
+
%imageId=item.image_id
|
6
|
+
%instanceType=item.instance_profile.name
|
7
|
+
%launchTime=item.launch_time || Time.now.to_s
|
8
|
+
- if item.public_addresses and not item.public_addresses.empty?
|
9
|
+
%ipAddress=item.public_addresses.first.address
|
10
|
+
%dnsName=item.public_addresses.first.address
|
11
|
+
- if item.private_addresses and not item.private_addresses.empty?
|
12
|
+
%privateIpAddress=item.private_addresses.first.address
|
13
|
+
%privateDnsName=item.private_addresses.first.address
|
14
|
+
%architecture=item.instance_profile.architecture || 'i386'
|
15
|
+
- if item.keyname
|
16
|
+
%keyName=item.keyname
|
17
|
+
- if item.state
|
18
|
+
%instanceState
|
19
|
+
%code=instance_state_code(item.state.downcase)
|
20
|
+
%name=item.state.downcase
|
21
|
+
%placement
|
22
|
+
%availabilityZone=item.realm_id
|
23
|
+
%groupName
|
24
|
+
%tenancy default
|
@@ -0,0 +1 @@
|
|
1
|
+
=render :instance_action, object
|
@@ -0,0 +1 @@
|
|
1
|
+
=render :instance_action, object
|
@@ -0,0 +1 @@
|
|
1
|
+
=render :instance_action, object
|
data/lib/sinatra.rb
CHANGED
data/lib/sinatra/rack_accept.rb
CHANGED
@@ -73,7 +73,7 @@ module Rack
|
|
73
73
|
self[type] = handler
|
74
74
|
end
|
75
75
|
yield wants
|
76
|
-
if
|
76
|
+
if Deltacloud.default_frontend.name == :cimi
|
77
77
|
@media_type = (accepting_formats.has_key?(:xml) ? [:xml, accepting_formats[:xml]] : nil)
|
78
78
|
end
|
79
79
|
@media_type ||= accepting_formats.to_a.sort { |a,b| a[1]<=>b[1] }.reverse.select do |format, priority|
|
@@ -31,10 +31,10 @@ module Rack
|
|
31
31
|
original_settings = { }
|
32
32
|
req = Rack::Request.new(env)
|
33
33
|
if req.params['api'] and req.params['api']['driver']
|
34
|
-
|
34
|
+
env['HTTP_X_DELTACLOUD_DRIVER'] = req.params['api']['driver']
|
35
35
|
end
|
36
36
|
if req.params['api'] and req.params['api']['provider']
|
37
|
-
|
37
|
+
env['HTTP_X_DELTACLOUD_PROVIDER'] = req.params['api']['provider']
|
38
38
|
end
|
39
39
|
HEADER_TO_ENV_MAP.each do |header, name|
|
40
40
|
original_settings[name] = Thread.current[name]
|
data/lib/sinatra/rack_etag.rb
CHANGED
@@ -68,7 +68,11 @@ module Rack
|
|
68
68
|
|
69
69
|
def digest_body(body)
|
70
70
|
parts = []
|
71
|
-
|
71
|
+
if RUBY_VERSION =~ /^1\.8/
|
72
|
+
body.each { |part, b| parts << part }
|
73
|
+
else
|
74
|
+
body.each { |part| parts << part }
|
75
|
+
end
|
72
76
|
string_body = parts.join
|
73
77
|
digest = Digest::MD5.hexdigest(string_body) unless string_body.empty?
|
74
78
|
[digest, parts]
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership. The
|
4
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
|
16
|
+
require_relative 'body_proxy'
|
17
|
+
|
18
|
+
# This module is based on Rack::CommonLogger[1]
|
19
|
+
# Copyright (C) 2007, 2008, 2009, 2010 Christian Neukirchen <purl.org/net/chneukirchen>
|
20
|
+
#
|
21
|
+
# [1] https://github.com/rack/rack/blob/master/lib/rack/commonlogger.rb
|
22
|
+
|
23
|
+
module Rack
|
24
|
+
# Rack::CommonLogger forwards every request to an +app+ given, and
|
25
|
+
# logs a line in the Apache common log format to the +logger+, or
|
26
|
+
# rack.errors by default.
|
27
|
+
class DeltacloudLogger
|
28
|
+
|
29
|
+
def self.log_path(path=nil)
|
30
|
+
@log_file ||= path
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.verbose?
|
34
|
+
@verbose
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.verbose(v=nil)
|
38
|
+
@verbose ||= v
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.setup(path, be_verbose=false)
|
42
|
+
verbose(be_verbose)
|
43
|
+
return self if path.nil?
|
44
|
+
dir = ::File.dirname(path)
|
45
|
+
if ::File.exists?(dir) and ::File.writable?(dir)
|
46
|
+
log_path(path)
|
47
|
+
else
|
48
|
+
warn "Warning: The log directory (#{dir}) is not writeable."
|
49
|
+
end
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
# Common Log Format: http://httpd.apache.org/docs/1.3/logs.html#common
|
54
|
+
# lilith.local - - [07/Aug/2006 23:58:02] "GET / HTTP/1.1" 500 -
|
55
|
+
# %{%s - %s [%s] "%s %s%s %s" %d %s\n} %
|
56
|
+
FORMAT = %{%s - %s [%s] "%s %s%s %s" %d %s %0.4f\n}
|
57
|
+
|
58
|
+
VERBOSE_FORMAT = %{%s - %s [%s] "%s %s%s%s %s" %s %s %d %s %0.4f\n}
|
59
|
+
|
60
|
+
def initialize(app, logger=nil)
|
61
|
+
@app = app
|
62
|
+
unless self.class.log_path.nil?
|
63
|
+
@logger = ::Logger.new(self.class.log_path)
|
64
|
+
else
|
65
|
+
@logger = logger
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def call(env)
|
70
|
+
began_at = Time.now
|
71
|
+
status, header, body = @app.call(env)
|
72
|
+
header = Utils::HeaderHash.new(header)
|
73
|
+
body = BodyProxy.new(body) do
|
74
|
+
self.class.verbose? ? verbose_log(env, status, header, began_at) : log(env, status, header, began_at)
|
75
|
+
end
|
76
|
+
[status, header, body]
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def verbose_log(env, status, header, began_at)
|
82
|
+
now = Time.now
|
83
|
+
length = extract_content_length(header)
|
84
|
+
params = env['rack.request.form_hash'].nil? ? '' : ' '+env['rack.request.form_hash'].to_json
|
85
|
+
|
86
|
+
logger = @logger || env['rack.errors']
|
87
|
+
logger << VERBOSE_FORMAT % [
|
88
|
+
env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-",
|
89
|
+
env["REMOTE_USER"] || "-",
|
90
|
+
now.strftime("%d/%b/%Y %H:%M:%S"),
|
91
|
+
env["REQUEST_METHOD"],
|
92
|
+
env["PATH_INFO"],
|
93
|
+
env["QUERY_STRING"].empty? ? '' : "?"+env["QUERY_STRING"],
|
94
|
+
params,
|
95
|
+
env["HTTP_VERSION"],
|
96
|
+
env['HTTP_X_DELTACLOUD_DRIVER'] || ENV['API_DRIVER'] || 'mock',
|
97
|
+
env['HTTP_X_DELTACLOUD_PROVIDER'] || ENV['API_PROVIDER'] || '-',
|
98
|
+
status.to_s[0..3],
|
99
|
+
length,
|
100
|
+
now - began_at ]
|
101
|
+
end
|
102
|
+
|
103
|
+
def log(env, status, header, began_at)
|
104
|
+
now = Time.now
|
105
|
+
length = extract_content_length(header)
|
106
|
+
|
107
|
+
logger = @logger || env['rack.errors']
|
108
|
+
logger << FORMAT % [
|
109
|
+
env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-",
|
110
|
+
env["REMOTE_USER"] || "-",
|
111
|
+
now.strftime("%d/%b/%Y %H:%M:%S"),
|
112
|
+
env["REQUEST_METHOD"],
|
113
|
+
env["PATH_INFO"],
|
114
|
+
env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"],
|
115
|
+
env["HTTP_VERSION"],
|
116
|
+
status.to_s[0..3],
|
117
|
+
length,
|
118
|
+
now - began_at ]
|
119
|
+
end
|
120
|
+
|
121
|
+
def extract_content_length(headers)
|
122
|
+
value = headers['Content-Length'] or return '-'
|
123
|
+
value.to_s == '0' ? '-' : value
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
@@ -92,7 +92,7 @@ module Rack
|
|
92
92
|
else
|
93
93
|
# For other methods it's more complicated
|
94
94
|
if env['REQUEST_METHOD']!='POST' and not matrix_params.keys.empty?
|
95
|
-
env['QUERY_STRING'].gsub
|
95
|
+
env['QUERY_STRING'] = env['QUERY_STRING'].gsub(/;([^\/]*)/, '')
|
96
96
|
new_params = matrix_params.collect do |component, params|
|
97
97
|
params.collect { |k,v| "#{component}[#{k}]=#{CGI::escape(v.to_s)}" }
|
98
98
|
end.flatten
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
3
|
+
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require_relative './common.rb'
|
6
|
+
|
7
|
+
describe CIMI::Collections::CloudEntryPoint do
|
8
|
+
|
9
|
+
before do
|
10
|
+
def app; CIMI::API; end
|
11
|
+
@collection = CIMI::Collections.collection(:cloudEntryPoint)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'has index operation' do
|
15
|
+
@collection.operation(:index).must_equal Sinatra::Rabbit::CloudentrypointCollection::IndexOperation
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'set the CIMI-Version header' do
|
19
|
+
get root_url
|
20
|
+
headers['X-CIMI-Specification-Version'].wont_be_nil
|
21
|
+
headers['X-CIMI-Specification-Version'].must_equal '1.0.0'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'advertise CIMI collections in XML format' do
|
25
|
+
get root_url + '/cloudEntryPoint'
|
26
|
+
xml.root.name.must_equal 'CloudEntryPoint'
|
27
|
+
(xml.root/'description').first.text.wont_be_empty
|
28
|
+
(xml.root/'id').first.text.wont_be_empty
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'advertise CIMI collections in JSON format' do
|
32
|
+
get root_url + '/cloudEntryPoint?format=json'
|
33
|
+
json.wont_be_empty
|
34
|
+
json['description'].wont_be_empty
|
35
|
+
json['id'].wont_be_empty
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'allow to force authentication using force_auth parameter in URI' do
|
39
|
+
get root_url + '/cloudEntryPoint?force_auth=1'
|
40
|
+
status.must_equal 401
|
41
|
+
authorize 'mockuser', 'mockpassword'
|
42
|
+
get root_url + '/cloudEntryPoint?force_auth=1'
|
43
|
+
status.must_equal 200
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative File.join('..', '..', '..', 'lib', 'deltacloud_rack.rb')
|
2
|
+
require_relative '../../test_helper.rb'
|
3
|
+
|
4
|
+
# Setup CIMI::API Sinatra instance
|
5
|
+
#
|
6
|
+
Deltacloud::configure(:cimi) do |server|
|
7
|
+
server.root_url '/cimi'
|
8
|
+
server.version '1.0.0'
|
9
|
+
server.klass 'CIMI::API'
|
10
|
+
server.default_driver :mock
|
11
|
+
server.logger Rack::DeltacloudLogger.setup(ENV['API_LOG'], ENV['API_VERBOSE'])
|
12
|
+
end
|
13
|
+
|
14
|
+
Deltacloud[:cimi].require!
|
15
|
+
Deltacloud[:cimi].default_frontend!
|
16
|
+
|
17
|
+
def formats; [ 'application/xml', 'application/json' ]; end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require_relative './common.rb'
|
5
|
+
|
6
|
+
describe CIMI::Collections::MachineImages do
|
7
|
+
|
8
|
+
before do
|
9
|
+
def app; CIMI::API; end
|
10
|
+
authorize 'mockuser', 'mockpassword'
|
11
|
+
@collection = CIMI::Collections.collection(:machine_images)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'has index operation' do
|
15
|
+
@collection.operation(:index).must_equal Sinatra::Rabbit::MachineImagesCollection::IndexOperation
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'has show operation' do
|
19
|
+
@collection.operation(:show).must_equal Sinatra::Rabbit::MachineImagesCollection::ShowOperation
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns list of images in various formats with index operation' do
|
23
|
+
formats.each do |format|
|
24
|
+
header 'Accept', format
|
25
|
+
get root_url + '/machine_images'
|
26
|
+
status.must_equal 200
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should allow to retrieve the single image' do
|
31
|
+
get root_url '/machine_images/img1'
|
32
|
+
status.must_equal 200
|
33
|
+
xml.root.name.must_equal 'MachineImage'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should allow to filter using CIMISelect' do
|
37
|
+
get root_url '/machine_images?CIMISelect=description'
|
38
|
+
status.must_equal 200
|
39
|
+
xml.root.name.must_equal 'MachineImageCollection'
|
40
|
+
(xml/'description').wont_be_empty
|
41
|
+
(xml/'id').must_be_empty
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|