deltacloud-core 0.1.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/DISCLAIMER +8 -0
  2. data/{COPYING → LICENSE} +0 -0
  3. data/NOTICE +13 -0
  4. data/Rakefile +50 -51
  5. data/bin/deltacloudd +8 -1
  6. data/config.ru +0 -2
  7. data/config/drivers.yaml +48 -0
  8. data/deltacloud-core.gemspec +75 -0
  9. data/deltacloud.rb +3 -2
  10. data/lib/deltacloud/backend_capability.rb +15 -3
  11. data/lib/deltacloud/base_driver.rb +0 -2
  12. data/lib/deltacloud/base_driver/base_driver.rb +85 -89
  13. data/lib/deltacloud/base_driver/features.rb +61 -7
  14. data/lib/deltacloud/base_driver/mock_driver.rb +42 -43
  15. data/lib/deltacloud/core_ext.rb +18 -0
  16. data/lib/deltacloud/core_ext/integer.rb +31 -0
  17. data/lib/deltacloud/core_ext/string.rb +50 -0
  18. data/lib/deltacloud/drivers/azure/azure_driver.rb +71 -22
  19. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +641 -584
  20. data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +0 -2
  21. data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +167 -0
  22. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +39 -1
  23. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +41 -25
  24. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob1.yml +6 -3
  25. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob2.yml +6 -3
  26. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob3.yml +4 -2
  27. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob4.yml +5 -2
  28. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob5.yml +4 -2
  29. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +1 -0
  30. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +1 -0
  31. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +1 -0
  32. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol1.yml +1 -0
  33. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol2.yml +1 -0
  34. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol3.yml +1 -0
  35. data/lib/deltacloud/drivers/mock/mock_driver.rb +138 -30
  36. data/lib/deltacloud/drivers/opennebula/cloud_client.rb +13 -15
  37. data/lib/deltacloud/drivers/opennebula/occi_client.rb +13 -15
  38. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +13 -15
  39. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +224 -113
  40. data/lib/deltacloud/drivers/rhevm/rhevm_client.rb +332 -0
  41. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +221 -170
  42. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +0 -1
  43. data/lib/deltacloud/drivers/sbc/sbc_client.rb +247 -0
  44. data/lib/deltacloud/drivers/sbc/sbc_driver.rb +297 -0
  45. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +0 -2
  46. data/lib/deltacloud/hardware_profile.rb +1 -3
  47. data/lib/deltacloud/helpers.rb +0 -2
  48. data/lib/deltacloud/helpers/application_helper.rb +86 -12
  49. data/lib/deltacloud/helpers/blob_stream.rb +19 -2
  50. data/lib/deltacloud/helpers/conversion_helper.rb +0 -2
  51. data/lib/deltacloud/helpers/hardware_profiles_helper.rb +0 -2
  52. data/lib/deltacloud/method_serializer.rb +0 -2
  53. data/lib/deltacloud/models/base_model.rb +0 -2
  54. data/lib/deltacloud/models/blob.rb +1 -2
  55. data/lib/deltacloud/models/bucket.rb +0 -2
  56. data/lib/deltacloud/models/image.rb +0 -2
  57. data/lib/deltacloud/models/instance.rb +19 -2
  58. data/lib/deltacloud/models/instance_profile.rb +4 -2
  59. data/lib/deltacloud/models/key.rb +0 -2
  60. data/lib/deltacloud/models/load_balancer.rb +0 -2
  61. data/lib/deltacloud/models/realm.rb +0 -2
  62. data/lib/deltacloud/models/storage_snapshot.rb +0 -2
  63. data/lib/deltacloud/models/storage_volume.rb +4 -2
  64. data/lib/deltacloud/runner.rb +132 -0
  65. data/lib/deltacloud/state_machine.rb +0 -2
  66. data/lib/deltacloud/validation.rb +9 -7
  67. data/lib/drivers.rb +36 -48
  68. data/lib/sinatra/accept_media_types.rb +26 -0
  69. data/lib/sinatra/lazy_auth.rb +16 -0
  70. data/lib/sinatra/rabbit.rb +112 -54
  71. data/lib/sinatra/rack_driver_select.rb +50 -16
  72. data/lib/sinatra/rack_etag.rb +79 -0
  73. data/lib/sinatra/rack_matrix_params.rb +84 -0
  74. data/lib/sinatra/rack_runtime.rb +47 -0
  75. data/lib/sinatra/static_assets.rb +16 -0
  76. data/lib/sinatra/url_for.rb +31 -4
  77. data/public/favicon.ico +0 -0
  78. data/public/images/bread-bg.png +0 -0
  79. data/public/images/error.png +0 -0
  80. data/public/images/pending.png +0 -0
  81. data/public/images/running.png +0 -0
  82. data/public/images/stopped.png +0 -0
  83. data/public/javascripts/application.js +35 -0
  84. data/public/stylesheets/compiled/application.css +59 -5
  85. data/public/stylesheets/compiled/screen.css +1 -1
  86. data/server.rb +293 -29
  87. data/support/fedora/deltacloud-core +78 -0
  88. data/support/fedora/deltacloud-core.spec +143 -0
  89. data/support/fedora/deltacloudd +78 -18
  90. data/support/fedora/rubygem-deltacloud-core.spec +76 -40
  91. data/tests/common.rb +172 -0
  92. data/tests/drivers/mock/api_test.rb +133 -0
  93. data/tests/drivers/mock/hardware_profiles_test.rb +134 -0
  94. data/tests/drivers/mock/images_test.rb +126 -0
  95. data/tests/drivers/mock/instance_states_test.rb +71 -0
  96. data/tests/drivers/mock/instances_test.rb +236 -0
  97. data/tests/drivers/mock/realms_test.rb +93 -0
  98. data/tests/drivers/mock/setup.rb +3 -0
  99. data/tests/drivers/mock/url_for_test.rb +67 -0
  100. data/tests/drivers/rackspace/api_test.rb +41 -0
  101. data/tests/drivers/rackspace/hardware_profiles_test.rb +53 -0
  102. data/tests/drivers/rackspace/images_test.rb +40 -0
  103. data/tests/drivers/rackspace/instances_test.rb +161 -0
  104. data/tests/drivers/rackspace/realms_test.rb +36 -0
  105. data/tests/drivers/rackspace/setup.rb +14 -0
  106. data/tests/drivers/rhevm/api_test.rb +39 -0
  107. data/tests/drivers/rhevm/hardware_profiles_test.rb +53 -0
  108. data/tests/drivers/rhevm/images_test.rb +42 -0
  109. data/tests/drivers/rhevm/instances_test.rb +179 -0
  110. data/tests/drivers/rhevm/realms_test.rb +35 -0
  111. data/tests/drivers/rhevm/setup.rb +14 -0
  112. data/tests/rabbit_test.rb +52 -0
  113. data/views/api/show.html.haml +2 -5
  114. data/views/blobs/new.html.haml +17 -1
  115. data/views/blobs/show.html.haml +6 -0
  116. data/views/blobs/show.xml.haml +5 -1
  117. data/views/buckets/index.html.haml +1 -12
  118. data/views/buckets/index.xml.haml +3 -5
  119. data/views/docs/operation.html.haml +23 -11
  120. data/views/drivers/index.html.haml +15 -0
  121. data/views/drivers/index.xml.haml +7 -0
  122. data/views/drivers/show.html.haml +20 -0
  123. data/views/drivers/show.xml.haml +7 -0
  124. data/views/error.html.haml +31 -0
  125. data/views/errors/auth_exception.xml.haml +2 -1
  126. data/views/errors/backend_capability_failure.xml.haml +2 -1
  127. data/views/errors/backend_error.html.haml +3 -0
  128. data/views/errors/backend_error.xml.haml +2 -2
  129. data/views/errors/validation_failure.xml.haml +3 -2
  130. data/views/images/index.html.haml +1 -6
  131. data/views/images/index.xml.haml +2 -0
  132. data/views/images/new.html.haml +14 -0
  133. data/views/images/show.xml.haml +2 -0
  134. data/views/instances/index.html.haml +8 -6
  135. data/views/instances/index.xml.haml +4 -0
  136. data/views/instances/new.html.haml +40 -11
  137. data/views/instances/run.html.haml +9 -0
  138. data/views/instances/run.xml.haml +7 -0
  139. data/views/instances/run_command.html.haml +16 -0
  140. data/views/instances/show.html.haml +14 -0
  141. data/views/instances/show.xml.haml +12 -4
  142. data/views/layout.html.haml +7 -2
  143. data/views/load_balancers/index.html.haml +1 -1
  144. data/views/load_balancers/new.html.haml +2 -2
  145. data/views/load_balancers/show.html.haml +1 -1
  146. data/views/storage_snapshots/index.html.haml +3 -0
  147. data/views/storage_snapshots/new.html.haml +9 -0
  148. data/views/storage_volumes/attach.html.haml +20 -0
  149. data/views/storage_volumes/index.html.haml +16 -1
  150. data/views/storage_volumes/index.xml.haml +1 -10
  151. data/views/storage_volumes/new.html.haml +17 -0
  152. data/views/storage_volumes/show.html.haml +8 -0
  153. data/views/storage_volumes/show.xml.haml +25 -3
  154. metadata +197 -127
  155. data/lib/deltacloud/drivers/rackspace/rackspace_client.rb +0 -130
  156. data/parse.rb +0 -7
  157. data/test.rb +0 -3
  158. data/views/api/drivers.xml.haml +0 -6
@@ -1,3 +1,19 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one or more
3
+ # contributor license agreements. See the NOTICE file distributed with
4
+ # this work for additional information regarding copyright ownership. The
5
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance with the
7
+ # License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations
15
+ # under the License.
16
+
1
17
  require 'deltacloud/validation'
2
18
 
3
19
  # Add advertising of optional features to the base driver
@@ -39,13 +55,19 @@ module Deltacloud
39
55
  @description
40
56
  end
41
57
 
42
- # Add a new operation or modify an existing one through BLOCK
58
+ # Add/modify an operation or look up an existing one. If +block+ is
59
+ # provided, create a new operation if none exists with name
60
+ # +name+. Evaluate the +block+ against this instance. If no +block+
61
+ # is provided, look up the operation with name +name+
43
62
  def operation(name, &block)
44
- unless op = @operations.find { |op| op.name == name }
45
- op = Operation.new(name, &block)
46
- @operations << op
47
- else
48
- op.instance_eval(&block) if block_given?
63
+ op = @operations.find { |op| op.name == name }
64
+ if block_given?
65
+ if op.nil?
66
+ op = Operation.new(name, &block)
67
+ @operations << op
68
+ else
69
+ op.instance_eval(&block)
70
+ end
49
71
  end
50
72
  op
51
73
  end
@@ -94,7 +116,7 @@ module Deltacloud
94
116
  end
95
117
 
96
118
  def self.features
97
- @@features ||= {}
119
+ @features ||= {}
98
120
  end
99
121
 
100
122
  # Declare in a driver that it supports a specific feature
@@ -117,6 +139,12 @@ module Deltacloud
117
139
  self.class.features[collection] || []
118
140
  end
119
141
 
142
+ def features_for_operation(collection, operation)
143
+ features(collection).select do |f|
144
+ f.operations.detect { |o| o.name == operation }
145
+ end
146
+ end
147
+
120
148
  #
121
149
  # Declaration of optional features
122
150
  #
@@ -143,6 +171,18 @@ module Deltacloud
143
171
  end
144
172
  end
145
173
 
174
+ declare_feature :instances, :user_files do
175
+ description "Accept up to 5 files to be placed into the instance before launch."
176
+ operation :create do
177
+ 1.upto(5) do |i|
178
+ param :"path#{i}", :string, :optional, nil,
179
+ "Path where to place the #{i.ordinalize} file, up to 255 characters"
180
+ param :"content#{i}", :string, :optional, nil,
181
+ "Contents for the #{i.ordinalize} file, up to 10 kB, Base64 encoded"
182
+ end
183
+ end
184
+ end
185
+
146
186
  declare_feature :instances, :security_group do
147
187
  description "Put instance in one or more security groups on launch"
148
188
  operation :create do
@@ -185,5 +225,19 @@ module Deltacloud
185
225
  end
186
226
  end
187
227
 
228
+ declare_feature :instances, :instance_count do
229
+ description "Number of instances to be launch with at once"
230
+ operation :create do
231
+ param :instance_count, :string, :optional
232
+ end
233
+ end
234
+
235
+ declare_feature :instances, :sandboxing do
236
+ description "Allow lanuching sandbox images"
237
+ operation :create do
238
+ param :sandbox, :string, :optional
239
+ end
240
+ end
241
+
188
242
  end
189
243
  end
@@ -1,78 +1,77 @@
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
+
1
16
  require 'deltacloud/method_serializer'
2
17
 
3
18
  # Create 'mock' version of original driver client/gem:
4
19
 
5
- module Mock
6
-
7
- class S3 < RightAws::S3
8
- include MethodSerializer::Cache
20
+ # Initialize driver and include Deltacloud
21
+ include Deltacloud
22
+ driver
9
23
 
10
- def self.cached_methods
11
- [
12
- :buckets
13
- ]
14
- end
15
-
16
- MethodSerializer::Cache::wrap_methods(self, :cache_dir => File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'tests', 'ec2', 'support'))
17
- end
18
-
19
- class ELB < AWS::ELB::Base
20
- include MethodSerializer::Cache
21
-
22
- def self.cached_methods
23
- [
24
- :describe_load_balancers
25
- ]
26
- end
27
-
28
- MethodSerializer::Cache::wrap_methods(self, :cache_dir => File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'tests', 'ec2', 'support'))
29
-
30
- end
24
+ module Mock
31
25
 
32
- class EC2 < AWS::EC2::Base
26
+ class Ec2 < Aws::Ec2
33
27
 
34
28
  include MethodSerializer::Cache
35
29
 
36
30
  def self.cached_methods
37
31
  [
38
32
  :describe_images,
33
+ :describe_images_by_owner,
39
34
  :describe_availability_zones,
40
- :describe_keypairs,
41
- :create_keypair,
42
- :run_instances,
35
+ :launch_instances,
43
36
  :describe_instances,
44
37
  :reboot_instances,
38
+ :create_tag,
39
+ :delete_tag,
40
+ :describe_tags,
45
41
  :terminate_instances,
46
- :delete_keypair
42
+ :describe_key_pairs,
43
+ :create_key_pair,
44
+ :delete_key_pair,
45
+ :create_volume,
46
+ :describe_volumes,
47
+ :delete_volume,
48
+ :attach_volume,
49
+ :detach_volume,
50
+ :describe_snapshots,
51
+ :associate_address,
52
+ :try_create_snapshot,
47
53
  ]
48
54
  end
49
55
 
50
56
  MethodSerializer::Cache::wrap_methods(self, :cache_dir => File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'tests', 'ec2', 'support'))
51
57
  end
58
+
52
59
  end
53
60
 
54
61
 
55
62
  # Replace original client with mock client
56
63
  Deltacloud::Drivers::EC2::EC2Driver.class_eval do
57
64
  alias_method :original_new_client, :new_client
58
- alias_method :original_s3_client, :s3_client
59
65
 
60
66
  def new_client(credentials, provider = :ec2)
67
+ auth_credentials = { :access_key_id => credentials.user, :secret_access_key => credentials.password}
61
68
  if provider == :elb
62
- Mock::ELB.new(
63
- :access_key_id => credentials.user,
64
- :secret_access_key => credentials.password
65
- )
69
+ Mock::ELB.new(auth_credentials)
70
+ elsif provider == :s3
71
+ Mock::S3.new(auth_credentials)
66
72
  else
67
- Mock::EC2.new(
68
- :access_key_id => credentials.user,
69
- :secret_access_key => credentials.password
70
- )
73
+ Mock::Ec2.new(auth_credentials[:access_key_id], auth_credentials[:secret_access_key])
71
74
  end
72
75
  end
73
76
 
74
- def s3_client(credentials)
75
- Mock::S3.new(credentials.user, credentials.password)
76
- end
77
-
78
77
  end
@@ -0,0 +1,18 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one or more
3
+ # contributor license agreements. See the NOTICE file distributed with
4
+ # this work for additional information regarding copyright ownership. The
5
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance with the
7
+ # License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations
15
+ # under the License.
16
+
17
+ require 'deltacloud/core_ext/string'
18
+ require 'deltacloud/core_ext/integer'
@@ -0,0 +1,31 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one or more
3
+ # contributor license agreements. See the NOTICE file distributed with
4
+ # this work for additional information regarding copyright ownership. The
5
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance with the
7
+ # License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations
15
+ # under the License.
16
+
17
+ class Integer
18
+ # Turn integers into strings +1st+, +2nd+, +3rd+ etc.
19
+ def ordinalize
20
+ if (11..13).include?(self % 100)
21
+ "#{self}th"
22
+ else
23
+ case self % 10
24
+ when 1; "#{self}st"
25
+ when 2; "#{self}nd"
26
+ when 3; "#{self}rd"
27
+ else "#{self}th"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,50 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one or more
3
+ # contributor license agreements. See the NOTICE file distributed with
4
+ # this work for additional information regarding copyright ownership. The
5
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance with the
7
+ # License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations
15
+ # under the License.
16
+
17
+ class String
18
+ # Rails defines this for a number of other classes, including Object
19
+ # see activesupport/lib/active_support/core_ext/object/blank.rb
20
+ def blank?
21
+ self !~ /\S/
22
+ end
23
+
24
+ # Title case.
25
+ #
26
+ # "this is a string".titlecase
27
+ # => "This Is A String"
28
+ #
29
+ # CREDIT: Eliazar Parra
30
+ # Copied from facets
31
+ def titlecase
32
+ gsub(/\b\w/){ $`[-1,1] == "'" ? $& : $&.upcase }
33
+ end
34
+
35
+ def pluralize
36
+ self + "s"
37
+ end
38
+
39
+ def singularize
40
+ self.gsub(/s$/, '')
41
+ end
42
+
43
+ def underscore
44
+ gsub(/::/, '/').
45
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
46
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
47
+ tr("-", "_").
48
+ downcase
49
+ end
50
+ end
@@ -1,6 +1,4 @@
1
1
  #
2
- # Copyright (C) 2010 Red Hat, Inc.
3
- #
4
2
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
3
  # contributor license agreements. See the NOTICE file distributed with
6
4
  # this work for additional information regarding copyright ownership. The
@@ -32,21 +30,26 @@ class AzureDriver < Deltacloud::BaseDriver
32
30
  #--
33
31
  # Buckets
34
32
  #--
35
- def buckets(credentials, opts)
33
+ def buckets(credentials, opts={})
36
34
  buckets = []
37
35
  azure_connect(credentials)
38
36
  safely do
39
- WAZ::Blobs::Container.list.each do |waz_container|
40
- buckets << convert_container(waz_container)
41
- end
42
- end
37
+ unless (opts[:id].nil?)
38
+ waz_bucket = WAZ::Blobs::Container.find(opts[:id])
39
+ buckets << convert_container(waz_bucket)
40
+ else
41
+ WAZ::Blobs::Container.list.each do |waz_container|
42
+ buckets << Bucket.new({:id =>waz_container.name, :name => waz_container.name})
43
+ end #container.list.each
44
+ end #unless
45
+ end #safely
43
46
  buckets = filter_on(buckets, :id, opts)
44
47
  end
45
48
 
46
49
  #--
47
50
  # Create bucket
48
51
  #--
49
- def create_bucket(credentials, name, opts)
52
+ def create_bucket(credentials, name, opts={})
50
53
  #for whatever reason, bucket names MUST be lowercase...
51
54
  #http://msdn.microsoft.com/en-us/library/dd135715.aspx
52
55
  name.downcase!
@@ -62,7 +65,7 @@ class AzureDriver < Deltacloud::BaseDriver
62
65
  #--
63
66
  # Delete bucket
64
67
  #--
65
- def delete_bucket(credentials, name, opts)
68
+ def delete_bucket(credentials, name, opts={})
66
69
  azure_connect(credentials)
67
70
  safely do
68
71
  WAZ::Blobs::Container.find(name).destroy!
@@ -72,20 +75,25 @@ class AzureDriver < Deltacloud::BaseDriver
72
75
  #--
73
76
  # Blobs
74
77
  #--
75
- def blobs(credentials, opts)
78
+ def blobs(credentials, opts={})
76
79
  blob_list = []
77
80
  azure_connect(credentials)
78
81
  safely do
79
82
  the_bucket = WAZ::Blobs::Container.find(opts['bucket'])
80
- the_bucket.blobs.each do |waz_blob|
81
- blob_list << convert_blob(waz_blob)
82
- end
83
- end
83
+ if(opts[:id])
84
+ the_blob = the_bucket[opts[:id]]
85
+ blob_list << convert_blob(the_blob) unless the_blob.nil?
86
+ else
87
+ the_bucket.blobs.each do |waz_blob|
88
+ blob_list << convert_blob(waz_blob)
89
+ end #each.do
90
+ end #if
91
+ end #safely do
84
92
  blob_list = filter_on(blob_list, :id, opts)
85
93
  blob_list
86
94
  end
87
95
 
88
- def blob_data(credentials, bucket_id, blob_id, opts)
96
+ def blob_data(credentials, bucket_id, blob_id, opts={})
89
97
  azure_connect(credentials)
90
98
  # WAZ get blob data methods cant accept blocks for 'streaming'... FIXME
91
99
  yield WAZ::Blobs::Container.find(bucket_id)[blob_id].value
@@ -94,23 +102,28 @@ class AzureDriver < Deltacloud::BaseDriver
94
102
  #--
95
103
  # Create Blob
96
104
  #--
97
- def create_blob(credentials, bucket_id, blob_id, blob_data, opts=nil)
105
+ def create_blob(credentials, bucket_id, blob_id, blob_data, opts={})
98
106
  azure_connect(credentials)
99
- #get a handle to the bucket in order to put there
100
- the_bucket = WAZ::Blobs::Container.find(bucket_id)
101
- the_bucket.store(blob_id, blob_data[:tempfile], blob_data[:type])
107
+ #insert azure-specific header for user metadata ... x-ms-meta-kEY = VALUE
108
+ opts.gsub_keys("HTTP_X_Deltacloud_Blobmeta_", "x-ms-meta-")
109
+ safely do
110
+ #get a handle to the bucket in order to put there
111
+ the_bucket = WAZ::Blobs::Container.find(bucket_id)
112
+ the_bucket.store(blob_id, blob_data[:tempfile], blob_data[:type], opts)
113
+ end
102
114
  Blob.new( { :id => blob_id,
103
115
  :bucket => bucket_id,
104
116
  :content_lengh => blob_data[:tempfile].length,
105
117
  :content_type => blob_data[:type],
106
- :last_modified => ''
118
+ :last_modified => '',
119
+ :user_metadata => opts.gsub_keys('x-ms-meta-','')
107
120
  } )
108
121
  end
109
122
 
110
123
  #--
111
124
  # Delete Blob
112
125
  #--
113
- def delete_blob(credentials, bucket_id, blob_id, opts=nil)
126
+ def delete_blob(credentials, bucket_id, blob_id, opts={})
114
127
  azure_connect(credentials)
115
128
  #get a handle to bucket and blob, and destroy!
116
129
  the_bucket = WAZ::Blobs::Container.find(bucket_id)
@@ -118,6 +131,36 @@ class AzureDriver < Deltacloud::BaseDriver
118
131
  the_blob.destroy!
119
132
  end
120
133
 
134
+ #-
135
+ # Blob Metadada
136
+ #-
137
+ def blob_metadata(credentials, opts = {})
138
+ azure_connect(credentials)
139
+ all_meta = nil
140
+ safely do
141
+ blob = WAZ::Blobs::Container.find(opts['bucket'])[opts[:id]]
142
+ return nil unless blob
143
+ all_meta = blob.metadata
144
+ end
145
+ user_meta = {}
146
+ all_meta.inject({}){|result_hash, (k,v)| user_meta[k]=v if k.to_s.match(/x_ms_meta/i)}
147
+ user_meta.gsub_keys('x_ms_meta_','')
148
+ end
149
+
150
+ #-
151
+ # Update Blob Metadata
152
+ #-
153
+ def update_blob_metadata(credentials, opts={})
154
+ azure_connect(credentials)
155
+ meta_hash = opts['meta_hash']
156
+ meta_hash.gsub_keys("HTTP_X_Deltacloud_Blobmeta_", "x-ms-meta-")
157
+ safely do
158
+ the_blob = WAZ::Blobs::Container.find(opts['bucket'])[opts[:id]]
159
+ the_blob.put_metadata!(meta_hash)
160
+ end
161
+ end
162
+
163
+
121
164
  private
122
165
 
123
166
  def azure_connect(credentials)
@@ -142,11 +185,17 @@ class AzureDriver < Deltacloud::BaseDriver
142
185
  def convert_blob(waz_blob)
143
186
  url = waz_blob.url.split('/')
144
187
  bucket = url[url.length-2] #FIXME
188
+ #get only user defined metadata
189
+ blob_metadata = {}
190
+ waz_blob.metadata.inject({}) { |result_hash, (k,v)| blob_metadata[k]=v if k.to_s.match(/x_ms_meta/i)}
191
+ #strip off the x_ms_meta_ from each key
192
+ blob_metadata.gsub_keys('x_ms_meta_', '')
145
193
  Blob.new({ :id => waz_blob.name,
146
194
  :bucket => bucket,
147
195
  :content_length => waz_blob.metadata[:content_length],
148
196
  :content_type => waz_blob.metadata[:content_type],
149
- :last_modified => waz_blob.metadata[:last_modified]
197
+ :last_modified => waz_blob.metadata[:last_modified],
198
+ :user_metadata => blob_metadata
150
199
  })
151
200
  end
152
201