deltacloud-core 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/Rakefile +10 -2
  2. data/bin/deltacloudd +10 -10
  3. data/config.ru +2 -1
  4. data/config/drivers/digitalocean.yaml +3 -0
  5. data/deltacloud-core.gemspec +13 -6
  6. data/lib/cimi/collections.rb +1 -1
  7. data/lib/cimi/collections/address_templates.rb +27 -3
  8. data/lib/cimi/collections/addresses.rb +1 -1
  9. data/lib/cimi/collections/base.rb +1 -0
  10. data/lib/cimi/collections/cloud_entry_point.rb +4 -0
  11. data/lib/cimi/collections/credentials.rb +2 -2
  12. data/lib/cimi/collections/machine_images.rb +20 -0
  13. data/lib/cimi/collections/machine_templates.rb +72 -0
  14. data/lib/cimi/collections/machines.rb +50 -41
  15. data/lib/cimi/collections/network_ports.rb +3 -3
  16. data/lib/cimi/collections/networks.rb +4 -4
  17. data/lib/cimi/collections/resource_metadata.rb +1 -1
  18. data/lib/cimi/collections/volume_configurations.rb +25 -0
  19. data/lib/cimi/collections/volume_images.rb +21 -1
  20. data/lib/cimi/collections/volume_templates.rb +69 -0
  21. data/lib/cimi/collections/volumes.rb +5 -10
  22. data/lib/cimi/dependencies.rb +0 -1
  23. data/lib/cimi/helpers.rb +4 -1
  24. data/lib/cimi/helpers/cimi_helper.rb +62 -0
  25. data/lib/cimi/helpers/database_helper.rb +95 -0
  26. data/lib/cimi/models.rb +15 -1
  27. data/lib/cimi/models/address.rb +10 -5
  28. data/lib/cimi/models/address_template.rb +67 -3
  29. data/lib/cimi/models/base.rb +8 -5
  30. data/lib/cimi/models/cloud_entry_point.rb +6 -1
  31. data/lib/cimi/models/collection.rb +9 -4
  32. data/lib/cimi/models/disk.rb +6 -1
  33. data/lib/cimi/models/errors.rb +8 -0
  34. data/lib/cimi/models/machine.rb +68 -42
  35. data/lib/cimi/models/machine_configuration.rb +2 -2
  36. data/lib/cimi/models/machine_image.rb +41 -6
  37. data/lib/cimi/models/machine_template.rb +58 -0
  38. data/lib/cimi/models/machine_volume.rb +51 -3
  39. data/lib/cimi/models/resource_metadata.rb +88 -25
  40. data/lib/cimi/models/schema.rb +19 -5
  41. data/lib/cimi/models/volume.rb +66 -30
  42. data/lib/cimi/models/volume_configuration.rb +53 -21
  43. data/lib/cimi/models/volume_image.rb +24 -9
  44. data/lib/cimi/models/volume_template.rb +61 -0
  45. data/lib/cimi/server.rb +0 -6
  46. data/lib/db.rb +82 -0
  47. data/lib/db/address_template.rb +15 -0
  48. data/lib/db/entity.rb +22 -0
  49. data/lib/db/machine_template.rb +10 -0
  50. data/lib/db/provider.rb +13 -0
  51. data/lib/db/volume_configuration.rb +10 -0
  52. data/lib/db/volume_template.rb +10 -0
  53. data/lib/deltacloud/collections/addresses.rb +1 -1
  54. data/lib/deltacloud/collections/base.rb +12 -1
  55. data/lib/deltacloud/collections/buckets.rb +41 -8
  56. data/lib/deltacloud/collections/drivers.rb +1 -1
  57. data/lib/deltacloud/collections/firewalls.rb +2 -2
  58. data/lib/deltacloud/collections/images.rb +1 -1
  59. data/lib/deltacloud/collections/instances.rb +7 -1
  60. data/lib/deltacloud/collections/keys.rb +1 -1
  61. data/lib/deltacloud/collections/load_balancers.rb +4 -4
  62. data/lib/deltacloud/collections/storage_snapshots.rb +5 -1
  63. data/lib/deltacloud/collections/storage_volumes.rb +7 -3
  64. data/lib/deltacloud/drivers/base_driver.rb +10 -9
  65. data/lib/deltacloud/drivers/cimi_features.rb +42 -0
  66. data/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb +307 -0
  67. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +40 -14
  68. data/lib/deltacloud/drivers/exceptions.rb +8 -0
  69. data/lib/deltacloud/drivers/features.rb +19 -2
  70. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +11 -0
  71. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +83 -11
  72. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +1 -1
  73. data/lib/deltacloud/drivers/mock/mock_client.rb +2 -4
  74. data/lib/deltacloud/drivers/mock/mock_driver.rb +29 -0
  75. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +153 -36
  76. data/lib/deltacloud/drivers/rackspace/anti_cache_monkey_patch.rb +20 -0
  77. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +1 -0
  78. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +30 -12
  79. data/lib/deltacloud/drivers/sbc/sbc_client.rb +0 -1
  80. data/lib/deltacloud/drivers/sbc/sbc_driver.rb +5 -1
  81. data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +1 -1
  82. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +19 -9
  83. data/lib/deltacloud/helpers/blob_stream_helper.rb +42 -3
  84. data/lib/deltacloud/helpers/deltacloud_helper.rb +31 -14
  85. data/lib/deltacloud/models/address.rb +9 -0
  86. data/lib/deltacloud/models/base_model.rb +4 -0
  87. data/lib/deltacloud/models/blob.rb +12 -0
  88. data/lib/deltacloud/models/bucket.rb +9 -0
  89. data/lib/deltacloud/models/firewall.rb +13 -1
  90. data/lib/deltacloud/models/firewall_rule.rb +14 -0
  91. data/lib/deltacloud/models/hardware_profile.rb +14 -0
  92. data/lib/deltacloud/models/image.rb +15 -0
  93. data/lib/deltacloud/models/instance.rb +40 -1
  94. data/lib/deltacloud/models/instance_address.rb +9 -0
  95. data/lib/deltacloud/models/key.rb +15 -0
  96. data/lib/deltacloud/models/load_balancer.rb +20 -0
  97. data/lib/deltacloud/models/metric.rb +15 -0
  98. data/lib/deltacloud/models/provider.rb +8 -0
  99. data/lib/deltacloud/models/realm.rb +9 -0
  100. data/lib/deltacloud/models/state_machine.rb +8 -0
  101. data/lib/deltacloud/models/storage_snapshot.rb +11 -0
  102. data/lib/deltacloud/models/storage_volume.rb +24 -0
  103. data/lib/deltacloud/server.rb +1 -3
  104. data/lib/deltacloud/version.rb +2 -1
  105. data/lib/deltacloud_rack.rb +1 -1
  106. data/tests/cimi/db/database_helper_test.rb +190 -0
  107. data/tests/cimi/db/db_helper.rb +30 -0
  108. data/tests/cimi/db/schema_test.rb +94 -0
  109. data/tests/cimi/model/collection_spec.rb +0 -1
  110. data/tests/cimi/model/machine_spec.rb +17 -0
  111. data/tests/cimi/spec_helper.rb +3 -2
  112. data/tests/deltacloud/collections/buckets_collection_test.rb +3 -0
  113. data/tests/deltacloud/collections/drivers_collection_test.rb +10 -0
  114. data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +4 -0
  115. data/tests/deltacloud/collections/images_collection_test.rb +4 -0
  116. data/tests/deltacloud/collections/instances_collection_test.rb +14 -1
  117. data/tests/deltacloud/collections/keys_collection_test.rb +4 -0
  118. data/tests/deltacloud/collections/realms_collection_test.rb +47 -0
  119. data/tests/deltacloud/collections/storage_snapshots_collection_test.rb +47 -0
  120. data/tests/deltacloud/collections/storage_volumes_collection_test.rb +47 -0
  121. data/tests/deltacloud/common.rb +15 -0
  122. data/tests/deltacloud/deltacloud_helper_test.rb +0 -4
  123. data/tests/deltacloud/launcher_test.rb +108 -0
  124. data/tests/drivers/ec2/buckets_test.rb +2 -1
  125. data/tests/drivers/mock/buckets_test.rb +27 -0
  126. data/tests/drivers/mock/instances_test.rb +6 -0
  127. data/tests/drivers/openstack/common.rb +1 -1
  128. data/tests/drivers/openstack/hardware_profiles_test.rb +2 -1
  129. data/tests/drivers/openstack/instances_test.rb +18 -17
  130. data/tests/drivers/rhevm/common.rb +1 -0
  131. data/tests/drivers/rhevm/images_test.rb +1 -1
  132. data/tests/drivers/rhevm/instance_test.rb +7 -7
  133. data/tests/helpers/rack/rack_matrix_params_test.rb +0 -2
  134. data/tests/test_helper.rb +2 -1
  135. data/views/errors/403.xml.haml +6 -0
  136. data/views/errors/409.html.haml +47 -0
  137. data/views/errors/409.xml.haml +11 -0
  138. data/views/errors/502.html.haml +6 -5
  139. data/views/images/show.xml.haml +3 -2
  140. data/views/instances/new.html.haml +1 -1
  141. metadata +77 -30
@@ -25,35 +25,67 @@ class CIMI::Model::VolumeConfiguration < CIMI::Model::Base
25
25
  scalar :rel, :href
26
26
  end
27
27
 
28
+ def self.create_from_json(body, context)
29
+ json = JSON.parse(body)
30
+ new_config = current_db.add_volume_configuration(
31
+ :name => json['name'],
32
+ :description => json['description'],
33
+ :format => json['format'],
34
+ :capacity => json['capacity'],
35
+ :ent_properties => json['properties'].to_json
36
+ )
37
+ from_db(new_config, context)
38
+ end
39
+
40
+ def self.create_from_xml(body, context)
41
+ xml = XmlSimple.xml_in(body)
42
+ xml['property'] ||= []
43
+ new_config = current_db.add_volume_configuration(
44
+ :name => xml['name'].first,
45
+ :description => xml['description'].first,
46
+ :format => xml['format'].first,
47
+ :capacity => xml['capacity'].first,
48
+ :ent_properties => JSON::dump(xml['property'].inject({}) { |r, p| r[p['key']]=p['content']; r })
49
+ )
50
+ from_db(new_config, context)
51
+ end
52
+
53
+ def self.delete!(id, context)
54
+ current_db.volume_configurations.first(:id => id).destroy
55
+ end
56
+
28
57
  def self.find(id, context)
29
- volume_configs = []
30
- if id == :all
31
- #ec2 ebs volumes can 1gb..1tb
32
- (1..1000).each do |size|
33
- volume_configs << create(size, context)
58
+ if id==:all
59
+ if context.driver.respond_to? :volume_configurations
60
+ context.driver.volume_configurations(context.credentials, {:env=>context})
61
+ else
62
+ current_db.volume_configurations.map { |t| from_db(t, context) }
34
63
  end
35
64
  else
36
- volume_configs << create(id, context)
37
- return volume_configs.first
65
+ if context.driver.respond_to? :volume_configuration
66
+ context.driver.volume_configuration(context.credentials, id, :env=>context)
67
+ else
68
+ config = current_db.volume_configurations_dataset.first(:id => id)
69
+ raise CIMI::Model::NotFound unless config
70
+ from_db(config, context)
71
+ end
38
72
  end
39
- return volume_configs
40
73
  end
41
74
 
42
-
43
- def self.all(context); find(:all, context); end
44
-
45
75
  private
46
76
 
47
- def self.create(size, context)
48
- self.new( {
49
- :id => context.volume_configuration_url(size),
50
- :name => "volume-#{size}",
51
- :description => "Volume configuration with #{size} kilobytes",
52
- :created => Time.now.xmlschema,
53
- :capacity => context.to_kibibyte(size, "MB"),
54
- :supports_snapshots => "true"
55
- # FIXME :guest_interface => "NFS"
56
- } )
77
+ def self.from_db(model, context)
78
+ self.new(
79
+ :id => context.volume_configuration_url(model.id),
80
+ :name => model.name,
81
+ :description => model.description,
82
+ :format => model.format,
83
+ :capacity => context.to_kibibyte(model.capacity, "GB"),
84
+ :property => JSON::parse(model.ent_properties),
85
+ :operations => [
86
+ { :href => context.destroy_volume_configuration_url(model.id), :rel => 'http://schemas.dmtf.org/cimi/1/action/delete' }
87
+ ]
88
+ )
57
89
  end
58
90
 
59
91
  end
@@ -25,23 +25,38 @@ class CIMI::Model::VolumeImage < CIMI::Model::Base
25
25
  end
26
26
 
27
27
  def self.find(id, context)
28
- storage_snapshots = []
29
- opts = ( id==:all ) ? {} : { :id=>id }
30
- storage_snapshots = context.driver.storage_snapshots(context.credentials, opts)
31
- storage_snapshots.collect!{ |snapshot| from_storage_snapshot(snapshot, context) }
32
- return storage_snapshots.first unless storage_snapshots.length > 1
33
- return storage_snapshots
28
+ creds = context.credentials
29
+ if id == :all
30
+ snapshots = context.driver.storage_snapshots(creds)
31
+ snapshots.collect{ |snapshot| from_storage_snapshot(snapshot, context) }
32
+ else
33
+ snapshot = context.driver.storage_snapshots(creds, id => :id).first
34
+ raise CIMI::Model::NotFound unless snapshot
35
+ from_storage_snapshot(snapshot, context)
36
+ end
34
37
  end
35
38
 
36
39
  def self.all(context); find(:all, context); end
37
40
 
41
+ def self.create(request_body, context)
42
+ type = context.grab_content_type(context.request.content_type, request_body)
43
+ input = (type == :xml)? XmlSimple.xml_in(request_body.read, {"ForceArray"=>false,"NormaliseSpace"=>2}) : JSON.parse(request_body.read)
44
+ params = {:volume_id => context.href_id(input["imageLocation"]["href"], :volumes), :name=>input["name"], :description=>input["description"]}
45
+ vol_image = context.driver.create_storage_snapshot(context.credentials, params)
46
+ from_storage_snapshot(vol_image, context)
47
+ end
48
+
49
+ def self.delete!(vol_image_id, context)
50
+ context.driver.destroy_storage_snapshot(context.credentials, {:id=>vol_image_id})
51
+ end
52
+
38
53
  private
39
54
 
40
55
  def self.from_storage_snapshot(snapshot, context)
41
56
  self.new( {
42
- :name => snapshot.id,
43
- :description => snapshot.id,
44
- :created => Time.parse(snapshot.created).xmlschema,
57
+ :name => snapshot.name || snapshot.id,
58
+ :description => snapshot.description || snapshot.id,
59
+ :created => snapshot.created.nil? ? nil : Time.parse(snapshot.created).xmlschema,
45
60
  :id => context.volume_image_url(snapshot.id),
46
61
  :image_location => {:href=>context.volume_url(snapshot.storage_volume_id)},
47
62
  :bootable => "false" #FIXME
@@ -19,7 +19,68 @@ class CIMI::Model::VolumeTemplate < CIMI::Model::Base
19
19
 
20
20
  href :volume_config
21
21
  href :volume_image
22
+
23
+ array :meter_templates do
24
+ end
25
+
26
+ href :event_log_template
27
+
22
28
  array :operations do
23
29
  scalar :rel, :href
24
30
  end
31
+
32
+ def self.find(id, context)
33
+ if id==:all
34
+ if context.driver.respond_to? :volume_templates
35
+ context.driver.volume_templates(context.credentials, {:env=>context})
36
+ else
37
+ current_db.volume_templates.map { |t| from_db(t, context) }
38
+ end
39
+ else
40
+ if context.driver.respond_to? :volume_template
41
+ context.driver.volume_template(context.credentials, id, :env=>context)
42
+ else
43
+ template = current_db.volume_templates_dataset.first(:id => id)
44
+ raise CIMI::Model::NotFound unless template
45
+ from_db(template, context)
46
+ end
47
+ end
48
+ end
49
+
50
+ def self.create(body, context, type)
51
+ input = (type == :xml)? XmlSimple.xml_in(body, {"ForceArray"=>false,"NormaliseSpace"=>2}) : JSON.parse(body)
52
+ input['property'] ||= []
53
+ vol_image = input['volumeImage']['href'] if input['volumeImage']
54
+ new_template = current_db.add_volume_template(
55
+ :name => input['name'],
56
+ :description => input['description'],
57
+ :volume_config => input['volumeConfig']['href'],
58
+ :volume_image => vol_image,
59
+ :ent_properties => JSON::dump(input['property'].inject({}) { |r, p| r[p['key']]=p['content']; r })
60
+ )
61
+ from_db(new_template, context)
62
+ end
63
+
64
+ def self.delete!(id, context)
65
+ current_db.volume_templates.first(:id => id).destroy
66
+ end
67
+
68
+ private
69
+
70
+ def self.from_db(model, context)
71
+ self.new(
72
+ :id => context.volume_template_url(model.id),
73
+ :name => model.name,
74
+ :description => model.description,
75
+ :volume_config => {:href => model.volume_config},
76
+ :volume_image => {:href => model.volume_image},
77
+ :property => JSON::parse(model.ent_properties),
78
+ :operations => [
79
+ { :href => context.destroy_volume_template_url(model.id), :rel => 'http://schemas.dmtf.org/cimi/1/action/delete' }
80
+ ]
81
+ )
82
+ end
83
+
84
+
85
+
25
86
  end
@@ -14,8 +14,6 @@
14
14
  # under the License.
15
15
 
16
16
  require 'rubygems'
17
- require 'crack'
18
- require 'json'
19
17
  require 'yaml'
20
18
  require 'haml'
21
19
  require 'sinatra/base'
@@ -49,9 +47,5 @@ module CIMI
49
47
 
50
48
  helpers Sinatra::Rabbit::URLFor(CIMI.collections)
51
49
 
52
- get '/' do
53
- redirect url('/cloudEntryPoint'), 301
54
- end
55
-
56
50
  end
57
51
  end
@@ -0,0 +1,82 @@
1
+ module Deltacloud
2
+
3
+ def self.test_environment?
4
+ ENV['RACK_ENV'] == 'test'
5
+ end
6
+
7
+ unless test_environment?
8
+ require 'sequel'
9
+ require 'logger'
10
+ Sequel::Model.plugin :validation_class_methods
11
+ end
12
+
13
+ if RUBY_PLATFORM == 'java'
14
+ DATABASE_LOCATION = ENV['DATABASE_LOCATION'] ||
15
+ 'jdbc:sqlite:'+File.join('/', 'var', 'tmp', "deltacloud-mock-#{ENV['USER']}", 'db.sqlite')
16
+ else
17
+ DATABASE_LOCATION = ENV['DATABASE_LOCATION'] ||
18
+ 'sqlite://'+File.join('/', 'var', 'tmp', "deltacloud-mock-#{ENV['USER']}", 'db.sqlite')
19
+ end
20
+
21
+ def self.database(opts={})
22
+ opts[:logger] = ::Logger.new($stdout) if ENV['API_VERBOSE']
23
+ @db ||= Sequel.connect(DATABASE_LOCATION, opts)
24
+ end
25
+
26
+ def self.initialize_database
27
+ db = database
28
+
29
+ db.create_table?(:providers) {
30
+ primary_key :id
31
+
32
+ column :driver, :string, { :null => false }
33
+ column :url, :string
34
+ index [ :url, :driver ] if !db.table_exists?(:providers)
35
+ }
36
+
37
+ db.create_table?(:entities) {
38
+ primary_key :id
39
+
40
+ unless db.table_exists?(:entities)
41
+ foreign_key :provider_id, :providers, { :index => true, :null => false }
42
+ end
43
+
44
+ column :created_at, :timestamp
45
+
46
+ # Base
47
+ unless db.table_exists?(:entities)
48
+ column :model, :string, { :index => true, :null => false, :default => 'entity' }
49
+ end
50
+
51
+ # Map Entity to Deltacloud model
52
+ # (like: Machine => Instance)
53
+ column :be_kind, :string
54
+ column :be_id, :string
55
+
56
+ # Entity
57
+ column :name, :string
58
+ column :description, :string
59
+ column :ent_properties, :string, { :text => true }
60
+
61
+
62
+ column :machine_config, :string
63
+ column :machine_image, :string
64
+
65
+ column :network, :string
66
+ column :ip, :string
67
+ column :hostname, :string
68
+ column :allocation, :string
69
+ column :default_gateway, :string
70
+ column :dns, :string
71
+ column :protocol, :string
72
+ column :mask, :string
73
+
74
+ column :format, :string
75
+ column :capacity, :string
76
+
77
+ column :volume_config, :string
78
+ column :volume_image, :string
79
+ }
80
+ end
81
+
82
+ end
@@ -0,0 +1,15 @@
1
+ module Deltacloud
2
+ module Database
3
+
4
+ class AddressTemplate < Entity
5
+ validates_presence_of :ip
6
+ validates_presence_of :hostname
7
+ validates_presence_of :allocation
8
+ validates_presence_of :default_gateway
9
+ validates_presence_of :dns
10
+ validates_presence_of :protocol
11
+ validates_presence_of :mask
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ module Deltacloud
2
+ module Database
3
+
4
+ class Entity < Sequel::Model
5
+
6
+ many_to_one :provider
7
+
8
+ plugin :single_table_inheritance, :model
9
+ plugin :timestamps, :create => :created_at
10
+
11
+ def to_hash
12
+ retval = {}
13
+ retval.merge!(:name => self.name) if !self.name.nil?
14
+ retval.merge!(:description => self.description) if !self.description.nil?
15
+ retval.merge!(:property => JSON::parse(self.ent_properties)) if !self.ent_properties.nil?
16
+ retval
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ module Deltacloud
2
+ module Database
3
+
4
+ class MachineTemplate < Entity
5
+ validates_presence_of :machine_config
6
+ validates_presence_of :machine_image
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ module Deltacloud
2
+ module Database
3
+
4
+ class Provider < Sequel::Model
5
+ one_to_many :entities
6
+ one_to_many :machine_templates
7
+ one_to_many :address_templates
8
+ one_to_many :volume_templates
9
+ one_to_many :volume_configurations
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ module Deltacloud
2
+ module Database
3
+
4
+ class VolumeConfiguration < Entity
5
+ validates_presence_of :format
6
+ validates_presence_of :capacity
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Deltacloud
2
+ module Database
3
+
4
+ class VolumeTemplate < Entity
5
+ validates_presence_of :volume_config
6
+ validates_presence_of :volume_Image
7
+ end
8
+
9
+ end
10
+ end
@@ -41,7 +41,7 @@ module Deltacloud::Collections
41
41
  respond_to do |format|
42
42
  format.xml { haml :"addresses/show", :ugly => true }
43
43
  format.html { haml :"addresses/_address", :layout => false }
44
- format.json { xml_to_json("addresses/show") }
44
+ format.json { JSON::dump(:address => @address.to_hash(self)) }
45
45
  end
46
46
  end
47
47
  end
@@ -43,7 +43,18 @@ module Deltacloud::Collections
43
43
  report_error
44
44
  end
45
45
 
46
- error Deltacloud::Exceptions::ValidationFailure do
46
+ # error Deltacloud::Exceptions::ObjectNotFound do
47
+ # report_error
48
+ # end
49
+
50
+ error Deltacloud::Exceptions::AcceptedButNotCompletedError,
51
+ Deltacloud::Exceptions::ValidationFailure,
52
+ Deltacloud::Exceptions::AuthenticationFailure,
53
+ Deltacloud::Exceptions::ForbiddenError,
54
+ Deltacloud::Exceptions::ObjectNotFound,
55
+ Deltacloud::Exceptions::MethodNotAllowed,
56
+ Deltacloud::Exceptions::UnknownMediaTypeError,
57
+ Deltacloud::Exceptions::Conflict do
47
58
  report_error
48
59
  end
49
60
 
@@ -49,8 +49,41 @@ module Deltacloud::Collections
49
49
  end
50
50
  end
51
51
 
52
+ put "/segmented_blob_operation/:bucket/:blob" do
53
+ case BlobHelper.segmented_blob_op_type(request)
54
+ when "init" then
55
+ segmented_blob_id = driver.init_segmented_blob(credentials, {:id => params[:blob],
56
+ :bucket => params[:bucket]})
57
+ headers["X-Deltacloud-SegmentedBlob"] = segmented_blob_id
58
+ status 204
59
+ when "segment" then
60
+ if env["BLOB_SUCCESS"] # set by blob_stream_helper after succesful stream PUT
61
+ #segment already uploaded by blob_streaming_patch - setting blob_segment-id from the response
62
+ headers["X-Deltacloud-BlobSegmentId"] = request.env["BLOB_SEGMENT_ID"] # set in blob_stream_helper: 203
63
+ status 204
64
+ else
65
+ report_error(400) # likely blob size < 112 KB (didn't hit streaming patch)
66
+ end
67
+ when "finalize" then
68
+ bucket_id = params[:bucket]
69
+ blob_id = params[:blob]
70
+ segmented_blob_manifest = BlobHelper.extract_segmented_blob_manifest(request)
71
+ segmented_blob_id = BlobHelper.segmented_blob_id(request)
72
+ @blob = driver.create_blob(credentials, params[:bucket], params[:blob], nil, {:segment_manifest=>segmented_blob_manifest, :segmented_blob_id=>segmented_blob_id})
73
+ respond_to do |format|
74
+ format.xml { haml :"blobs/show" }
75
+ format.html { haml :"blobs/show" }
76
+ format.json { xml_to_json 'blobs/show' }
77
+ end
78
+ else
79
+ report_error(500)
80
+ end
81
+ end
82
+
52
83
  put "/buckets/:bucket/:blob" do
53
- if(env["BLOB_SUCCESS"]) #ie got a 200ok after putting blob
84
+ if BlobHelper.segmented_blob(request)
85
+ status, headers, body = call!(env.merge("PATH_INFO" => "/segmented_blob_operation/#{params[:bucket]}/#{params[:blob]}"))
86
+ elsif(env["BLOB_SUCCESS"]) #ie got a 200ok after putting blob
54
87
  content_type = env["CONTENT_TYPE"]
55
88
  content_type ||= ""
56
89
  @blob = driver.blob(credentials, {:id => params[:blob],
@@ -58,7 +91,7 @@ module Deltacloud::Collections
58
91
  respond_to do |format|
59
92
  format.xml { haml :"blobs/show" }
60
93
  format.html { haml :"blobs/show" }
61
- format.json { xml_to_json 'blobs/show' }
94
+ format.json { JSON::dump(:blob => @blob.to_hash(self) ) }
62
95
  end
63
96
  elsif(env["BLOB_FAIL"])
64
97
  report_error(500) #OK?
@@ -77,7 +110,7 @@ module Deltacloud::Collections
77
110
  respond_to do |format|
78
111
  format.xml { haml :"blobs/show" }
79
112
  format.html { haml :"blobs/show" }
80
- format.json { xml_to_json 'blobs/show' }
113
+ format.json { JSON::dump(:blob => @blob.to_hash(self)) }
81
114
  end
82
115
  end
83
116
  end
@@ -96,7 +129,7 @@ module Deltacloud::Collections
96
129
  response['Location'] = bucket_url(@bucket.id)
97
130
  respond_to do |format|
98
131
  format.xml { haml :"buckets/show" }
99
- format.json { xml_to_json('buckets/show') }
132
+ format.json { JSON::dump(:bucket => @bucket.to_hash(self)) }
100
133
  format.html do
101
134
  redirect bucket_url(@bucket.id) if @bucket and @bucket.id
102
135
  redirect buckets_url
@@ -127,7 +160,7 @@ module Deltacloud::Collections
127
160
  respond_to do |format|
128
161
  format.xml { haml :"blobs/show" }
129
162
  format.html { haml :"blobs/show" }
130
- format.json { xml_to_json 'blobs/show' }
163
+ format.json { JSON::dump(:blob => @blob.to_hash(self)) }
131
164
  end
132
165
  else
133
166
  report_error(404)
@@ -161,7 +194,7 @@ module Deltacloud::Collections
161
194
  respond_to do |format|
162
195
  format.xml { haml :"blobs/show" }
163
196
  format.html { haml :"blobs/show"}
164
- format.json { xml_to_json 'blobs/show' }
197
+ format.json { JSON::dump(:blob => @blob.to_hash(self)) }
165
198
  end
166
199
  end
167
200
  end
@@ -194,7 +227,7 @@ module Deltacloud::Collections
194
227
  respond_to do |format|
195
228
  format.xml { haml :"blobs/show" }
196
229
  format.html { haml :"blobs/show" }
197
- format.json { xml_to_json 'blobs/show' }
230
+ format.json { JSON::dump(@blob.to_hash(self)) }
198
231
  end
199
232
  elsif(env["BLOB_FAIL"])
200
233
  report_error(500) #OK?
@@ -213,7 +246,7 @@ module Deltacloud::Collections
213
246
  respond_to do |format|
214
247
  format.xml { haml :"blobs/show" }
215
248
  format.html { haml :"blobs/show" }
216
- format.json { xml_to_json 'blobs/show' }
249
+ format.json { JSON::dump(@blob.to_hash(self)) }
217
250
  end
218
251
  end
219
252
  end