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
@@ -13,11 +13,13 @@
|
|
13
13
|
# License for the specific language governing permissions and limitations
|
14
14
|
# under the License.
|
15
15
|
|
16
|
-
class CIMI::Model::
|
16
|
+
class CIMI::Model::NetworkPortTemplate < CIMI::Model::Base
|
17
|
+
|
18
|
+
acts_as_root_entity
|
17
19
|
|
18
20
|
href :network
|
19
21
|
|
20
|
-
href :
|
22
|
+
href :network_port_config
|
21
23
|
|
22
24
|
array :operations do
|
23
25
|
scalar :rel, :href
|
@@ -25,9 +27,9 @@ class CIMI::Model::VSPTemplate < CIMI::Model::Base
|
|
25
27
|
|
26
28
|
def self.find(id, context)
|
27
29
|
if id==:all
|
28
|
-
context.driver.
|
30
|
+
context.driver.network_port_templates(context.credentials, {:env=>context})
|
29
31
|
else
|
30
|
-
context.driver.
|
32
|
+
context.driver.network_port_templates(context.credentials, {:env=>context, :id=>id})
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
@@ -13,22 +13,24 @@
|
|
13
13
|
# License for the specific language governing permissions and limitations
|
14
14
|
# under the License.
|
15
15
|
|
16
|
+
class CIMI::Model::NetworkPortTemplateCollection < CIMI::Model::Base
|
16
17
|
|
17
|
-
|
18
|
+
CIMI::Model.register_as_root_entity! "NetworkPortTemplates"
|
18
19
|
|
19
|
-
|
20
|
+
text :count
|
20
21
|
|
21
|
-
array :
|
22
|
-
|
23
|
-
end
|
22
|
+
#add array of network_port_templates:
|
23
|
+
self << CIMI::Model::NetworkPortTemplate
|
24
24
|
|
25
25
|
def self.default(context)
|
26
|
+
network_port_templates = CIMI::Model::NetworkPortTemplate.all(context)
|
26
27
|
self.new(
|
27
|
-
:id => context.
|
28
|
+
:id => context.network_port_templates_url,
|
28
29
|
:name => 'default',
|
29
30
|
:created => Time.now,
|
30
|
-
:description => "#{context.driver.name.capitalize}
|
31
|
-
:
|
31
|
+
:description => "#{context.driver.name.capitalize} NetworkPortTemplateCollection",
|
32
|
+
:count => network_port_templates.size,
|
33
|
+
:network_port_templates => network_port_templates
|
32
34
|
)
|
33
35
|
end
|
34
36
|
|
@@ -14,7 +14,9 @@
|
|
14
14
|
# under the License.
|
15
15
|
|
16
16
|
|
17
|
-
class CIMI::Model::
|
17
|
+
class CIMI::Model::ResourceMetadata < CIMI::Model::Base
|
18
|
+
|
19
|
+
acts_as_root_entity
|
18
20
|
|
19
21
|
text :type_uri
|
20
22
|
|
@@ -36,25 +38,24 @@ class CIMI::Model::EntityMetadata < CIMI::Model::Base
|
|
36
38
|
end
|
37
39
|
|
38
40
|
def self.find(id, context)
|
39
|
-
|
41
|
+
resource_metadata = []
|
40
42
|
if id == :all
|
41
|
-
CIMI::Model.root_entities.each do |
|
42
|
-
|
43
|
-
entity_metadata << entity_class.create_entity_metadata(context) if entity_class.respond_to?(:create_entity_metadata)
|
43
|
+
CIMI::Model.root_entities.each do |resource_class|
|
44
|
+
resource_metadata << resource_class.create_resource_metadata(context) if resource_class.respond_to?(:create_resource_metadata)
|
44
45
|
end
|
45
|
-
return
|
46
|
+
return resource_metadata
|
46
47
|
else
|
47
|
-
|
48
|
-
if
|
49
|
-
|
48
|
+
resource_class = CIMI::Model.const_get("#{id.camelize}")
|
49
|
+
if resource_class.respond_to?(:create_resource_metadata)
|
50
|
+
resource_class.create_resource_metadata(context)
|
50
51
|
end
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
54
|
-
def self.metadata_from_deltacloud_features(
|
55
|
-
deltacloud_features = context.driver.class.features[
|
55
|
+
def self.metadata_from_deltacloud_features(cimi_resource, dcloud_resource, context)
|
56
|
+
deltacloud_features = context.driver.class.features[dcloud_resource]
|
56
57
|
metadata_attributes = deltacloud_features.map{|f| attributes_from_feature(f)}
|
57
|
-
from_feature(
|
58
|
+
from_feature(cimi_resource, context, metadata_attributes.flatten!)
|
58
59
|
end
|
59
60
|
|
60
61
|
def includes_attribute?(attribute)
|
@@ -75,9 +76,9 @@ class CIMI::Model::EntityMetadata < CIMI::Model::Base
|
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
78
|
-
def self.from_feature(
|
79
|
-
self.new(:name =>
|
80
|
-
:type_uri=> context.send("#{
|
79
|
+
def self.from_feature(cimi_resource, context, metadata_attributes)
|
80
|
+
self.new(:name => cimi_resource, :uri=>"#{context.resource_metadata_url}/#{cimi_resource.underscore}",
|
81
|
+
:type_uri=> context.send("#{cimi_resource.pluralize.underscore}_url"),
|
81
82
|
:attributes => metadata_attributes)
|
82
83
|
end
|
83
84
|
|
data/lib/cimi/models/schema.rb
CHANGED
@@ -87,9 +87,16 @@ class CIMI::Model::Schema
|
|
87
87
|
def initialize(name, opts, &block)
|
88
88
|
content = opts[:content]
|
89
89
|
super(name, opts)
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
if opts[:schema]
|
91
|
+
if block_given?
|
92
|
+
raise "Cannot provide :schema option and a block"
|
93
|
+
end
|
94
|
+
@schema = opts[:schema]
|
95
|
+
else
|
96
|
+
@schema = CIMI::Model::Schema.new
|
97
|
+
@schema.instance_eval(&block) if block_given?
|
98
|
+
@schema.scalar(content, :text => :direct) if content
|
99
|
+
end
|
93
100
|
end
|
94
101
|
|
95
102
|
def from_xml(xml, model)
|
@@ -138,13 +145,7 @@ class CIMI::Model::Schema
|
|
138
145
|
|
139
146
|
private
|
140
147
|
def struct
|
141
|
-
|
142
|
-
if ::Struct.const_defined?(cname)
|
143
|
-
::Struct.const_get(cname)
|
144
|
-
else
|
145
|
-
::Struct.new("CIMI_#{json_name.upcase_first}",
|
146
|
-
*@schema.attribute_names)
|
147
|
-
end
|
148
|
+
@struct_class ||= ::Struct.new(nil, *@schema.attribute_names)
|
148
149
|
end
|
149
150
|
end
|
150
151
|
|
@@ -233,7 +234,8 @@ class CIMI::Model::Schema
|
|
233
234
|
model
|
234
235
|
end
|
235
236
|
|
236
|
-
def to_xml(model, xml =
|
237
|
+
def to_xml(model, xml = nil)
|
238
|
+
xml ||= OrderedHash.new
|
237
239
|
@attributes.freeze
|
238
240
|
@attributes.each { |attr| attr.to_xml(model, xml) }
|
239
241
|
xml
|
@@ -265,7 +267,8 @@ class CIMI::Model::Schema
|
|
265
267
|
# +add_attributes!+ method
|
266
268
|
module DSL
|
267
269
|
def href(*args)
|
268
|
-
args.
|
270
|
+
opts = args.extract_opts!
|
271
|
+
args.each { |arg| struct(arg, opts) { scalar :href } }
|
269
272
|
end
|
270
273
|
|
271
274
|
def text(*args)
|
@@ -288,6 +291,14 @@ class CIMI::Model::Schema
|
|
288
291
|
def hash(name)
|
289
292
|
add_attributes!([name, {}], Hash)
|
290
293
|
end
|
294
|
+
|
295
|
+
def collection(name, opts={})
|
296
|
+
text :count
|
297
|
+
|
298
|
+
array :operations do
|
299
|
+
scalar :rel, :href
|
300
|
+
end
|
301
|
+
end
|
291
302
|
end
|
292
303
|
|
293
304
|
include DSL
|
data/lib/cimi/models/volume.rb
CHANGED
data/lib/cimi/server.rb
CHANGED
@@ -25,7 +25,7 @@ require_relative '../sinatra'
|
|
25
25
|
require_relative './helpers'
|
26
26
|
require_relative './collections'
|
27
27
|
|
28
|
-
CMWG_NAMESPACE = "http://
|
28
|
+
CMWG_NAMESPACE = "http://schemas.dmtf.org/cimi/1"
|
29
29
|
|
30
30
|
module CIMI
|
31
31
|
class API < Collections::Base
|
@@ -36,17 +36,21 @@ module CIMI
|
|
36
36
|
use Rack::ETag
|
37
37
|
use Rack::MatrixParams
|
38
38
|
use Rack::DriverSelect
|
39
|
-
use Rack::Accept
|
40
|
-
use Rack::MediaType
|
41
39
|
|
42
|
-
helpers
|
40
|
+
helpers CIMI::Helper
|
43
41
|
|
44
42
|
include Deltacloud::Helpers
|
45
43
|
include CIMI::Collections
|
46
44
|
include CIMI::Model
|
47
45
|
|
48
|
-
|
49
|
-
|
46
|
+
enable :method_override
|
47
|
+
disable :show_exceptions
|
48
|
+
disable :dump_errors
|
49
|
+
|
50
|
+
helpers Sinatra::Rabbit::URLFor(CIMI.collections)
|
51
|
+
|
52
|
+
get '/' do
|
53
|
+
redirect url('/cloudEntryPoint'), 301
|
50
54
|
end
|
51
55
|
|
52
56
|
end
|
@@ -14,6 +14,8 @@
|
|
14
14
|
# License for the specific language governing permissions and limitations
|
15
15
|
# under the License.
|
16
16
|
|
17
|
+
require_relative './collections/base'
|
18
|
+
|
17
19
|
module Deltacloud
|
18
20
|
|
19
21
|
def self.collection_names
|
@@ -35,8 +37,9 @@ module Deltacloud
|
|
35
37
|
end
|
36
38
|
|
37
39
|
Dir[File.join(File::dirname(__FILE__), "collections", "*.rb")].each do |collection|
|
38
|
-
require collection
|
39
40
|
base_collection_name = File.basename(collection).gsub('.rb', '')
|
41
|
+
next if base_collection_name == 'base'
|
42
|
+
require collection
|
40
43
|
deltacloud_module_class = Deltacloud::Collections.const_get(base_collection_name.camelize)
|
41
44
|
deltacloud_modules << deltacloud_module_class
|
42
45
|
deltacloud_module_class.collections.each do |c|
|
@@ -46,7 +49,9 @@ module Deltacloud
|
|
46
49
|
|
47
50
|
def self.included(klass)
|
48
51
|
klass.class_eval do
|
49
|
-
Deltacloud::Collections.deltacloud_modules.each
|
52
|
+
Deltacloud::Collections.deltacloud_modules.each do |collection_class|
|
53
|
+
use collection_class
|
54
|
+
end
|
50
55
|
end
|
51
56
|
end
|
52
57
|
|
@@ -18,7 +18,7 @@ module Deltacloud::Collections
|
|
18
18
|
|
19
19
|
set :capability, lambda { |m| driver.respond_to? m }
|
20
20
|
|
21
|
-
get
|
21
|
+
get '/addresses/:id/associate' do
|
22
22
|
@address = driver.address(credentials, params )
|
23
23
|
@instances = driver.instances(credentials)
|
24
24
|
respond_to do |format|
|
@@ -60,6 +60,7 @@ module Deltacloud::Collections
|
|
60
60
|
|
61
61
|
action :associate, :with_capability => :associate_address do
|
62
62
|
description "Associate an IP address to an instance"
|
63
|
+
param :id, :string, :required
|
63
64
|
param :instance_id, :string, :required
|
64
65
|
control do
|
65
66
|
driver.associate_address(credentials, { :id => params[:id], :instance_id => params[:instance_id]})
|
@@ -74,6 +75,7 @@ module Deltacloud::Collections
|
|
74
75
|
|
75
76
|
action :disassociate, :with_capability => :associate_address do
|
76
77
|
description "Disassociate an IP address from an instance"
|
78
|
+
param :id, :string, :required
|
77
79
|
control do
|
78
80
|
driver.disassociate_address(credentials, { :id => params[:id] })
|
79
81
|
status 202 # Accepted
|
@@ -0,0 +1,64 @@
|
|
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
|
+
module Deltacloud::Collections
|
17
|
+
class Base < Sinatra::Base
|
18
|
+
|
19
|
+
include Sinatra::Rabbit
|
20
|
+
include Sinatra::Rabbit::Features
|
21
|
+
|
22
|
+
helpers Deltacloud::Helpers::Drivers
|
23
|
+
helpers Sinatra::AuthHelper
|
24
|
+
helpers Deltacloud::Helpers::Application
|
25
|
+
helpers Sinatra::Rabbit::URLHelper
|
26
|
+
register Rack::RespondTo
|
27
|
+
|
28
|
+
enable :method_override
|
29
|
+
disable :show_exceptions
|
30
|
+
disable :dump_errors
|
31
|
+
|
32
|
+
set :config, Deltacloud[:deltacloud]
|
33
|
+
set :root_url, config.root_url
|
34
|
+
set :root_path, config.root_url
|
35
|
+
set :version, config.version
|
36
|
+
set :root, File.join(File.dirname(__FILE__), '..', '..', '..')
|
37
|
+
set :views, File.join(settings.root, 'views')
|
38
|
+
set :public_folder, root + '/public'
|
39
|
+
# A class where the Rabbit will look up for 'collections'
|
40
|
+
set :documentation_class, Deltacloud
|
41
|
+
|
42
|
+
error do
|
43
|
+
report_error
|
44
|
+
end
|
45
|
+
|
46
|
+
error Deltacloud::ExceptionHandler::ValidationFailure do
|
47
|
+
report_error
|
48
|
+
end
|
49
|
+
|
50
|
+
before do
|
51
|
+
# Respond with 400, If we don't get a http Host header,
|
52
|
+
halt 400, "Unable to find HTTP Host header" if @env['HTTP_HOST'] == nil
|
53
|
+
end
|
54
|
+
|
55
|
+
after do
|
56
|
+
headers 'Server' => 'Apache-Deltacloud/' + settings.version
|
57
|
+
headers 'X-Deltacloud-Driver' => driver_name
|
58
|
+
if provider_name
|
59
|
+
headers 'X-Deltacloud-Provider' => provider_name
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
@@ -24,7 +24,7 @@ module Deltacloud::Collections
|
|
24
24
|
|
25
25
|
new_route_for :buckets
|
26
26
|
|
27
|
-
get
|
27
|
+
get '/buckets/:bucket/%s' % NEW_BLOB_FORM_ID do
|
28
28
|
@bucket_id = params[:bucket]
|
29
29
|
respond_to do |format|
|
30
30
|
format.html {haml :"blobs/new"}
|
@@ -32,7 +32,7 @@ module Deltacloud::Collections
|
|
32
32
|
end
|
33
33
|
|
34
34
|
|
35
|
-
head
|
35
|
+
head '/buckets/:bucket/:blob' do
|
36
36
|
@blob_id = params[:blob]
|
37
37
|
@blob_metadata = driver.blob_metadata(credentials, {:id => params[:blob], 'bucket' => params[:bucket]})
|
38
38
|
if @blob_metadata
|
@@ -49,7 +49,7 @@ module Deltacloud::Collections
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
put
|
52
|
+
put "/buckets/:bucket/:blob" do
|
53
53
|
if(env["BLOB_SUCCESS"]) #ie got a 200ok after putting blob
|
54
54
|
content_type = env["CONTENT_TYPE"]
|
55
55
|
content_type ||= ""
|
@@ -120,6 +120,7 @@ module Deltacloud::Collections
|
|
120
120
|
collection :blobs, :with_id => :blob_id, :no_member => true do
|
121
121
|
|
122
122
|
operation :show, :with_capability => :blob do
|
123
|
+
param :blob_id, :string, :required
|
123
124
|
control do
|
124
125
|
@blob = driver.blob(credentials, { :id => params[:blob_id], 'bucket' => params[:id]} )
|
125
126
|
if @blob
|
@@ -137,6 +138,7 @@ module Deltacloud::Collections
|
|
137
138
|
|
138
139
|
operation :create, :with_capability => :create_blob do
|
139
140
|
description "Create new blob"
|
141
|
+
param :id, :string, :required, 'The bucket ID'
|
140
142
|
param :blob_id, :string, :required
|
141
143
|
param :blob_data, :hash, :required
|
142
144
|
control do
|
@@ -165,6 +167,7 @@ module Deltacloud::Collections
|
|
165
167
|
end
|
166
168
|
|
167
169
|
operation :destroy, :with_capability => :delete_blob do
|
170
|
+
param :blob_id, :string, :required, 'The id of the blob to destroy'
|
168
171
|
control do
|
169
172
|
bucket_id = params[:id]
|
170
173
|
blob_id = params[:blob_id]
|
@@ -180,6 +183,8 @@ module Deltacloud::Collections
|
|
180
183
|
|
181
184
|
action :stream, :http_method => :put, :with_capability => :create_blob do
|
182
185
|
description "Stream new blob data into the blob"
|
186
|
+
param :id, :string, :required
|
187
|
+
param :blob_id, :string, :required
|
183
188
|
control do
|
184
189
|
if(env["BLOB_SUCCESS"]) #ie got a 200ok after putting blob
|
185
190
|
content_type = env["CONTENT_TYPE"]
|
@@ -215,6 +220,8 @@ module Deltacloud::Collections
|
|
215
220
|
end
|
216
221
|
|
217
222
|
action :metadata, :http_method => :head, :with_capability => :blob_metadata do
|
223
|
+
param :id, :string, :required
|
224
|
+
param :blob_id, :string, :required
|
218
225
|
control do
|
219
226
|
@blob_id = params[:blob_id]
|
220
227
|
@blob_metadata = driver.blob_metadata(credentials, {:id => params[:blob_id], 'bucket' => params[:id]})
|
@@ -234,10 +241,11 @@ module Deltacloud::Collections
|
|
234
241
|
end
|
235
242
|
|
236
243
|
action :update, :http_method => :post, :with_capability => :update_blob_metadata do
|
244
|
+
param :blob_id, :string, :required
|
237
245
|
control do
|
238
246
|
meta_hash = BlobHelper::extract_blob_metadata_hash(request.env)
|
239
247
|
success = driver.update_blob_metadata(credentials, {'bucket'=>params[:id], :id =>params[:blob_id], 'meta_hash' => meta_hash})
|
240
|
-
|
248
|
+
if(success)
|
241
249
|
meta_hash.each do |k,v|
|
242
250
|
headers["X-Deltacloud-Blobmeta-#{k}"] = v
|
243
251
|
end
|
@@ -254,6 +262,8 @@ module Deltacloud::Collections
|
|
254
262
|
|
255
263
|
action :content, :http_method => :get, :with_capability => :blob do
|
256
264
|
description "Download blob content"
|
265
|
+
param :id, :string, :required
|
266
|
+
param :blob_id, :string, :required
|
257
267
|
control do
|
258
268
|
@blob = driver.blob(credentials, { :id => params[:blob_id], 'bucket' => params[:id]})
|
259
269
|
if @blob
|