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.
Files changed (180) hide show
  1. data/LICENSE +23 -0
  2. data/NOTICE +3 -0
  3. data/Rakefile +32 -20
  4. data/bin/deltacloudd +1 -1
  5. data/config.ru +25 -32
  6. data/deltacloud-core.gemspec +1 -1
  7. data/lib/cimi/collections.rb +4 -1
  8. data/lib/cimi/collections/address_templates.rb +2 -2
  9. data/lib/cimi/collections/addresses.rb +1 -1
  10. data/lib/cimi/collections/base.rb +64 -0
  11. data/lib/cimi/collections/{machine_admins.rb → credentials.rb} +12 -12
  12. data/lib/cimi/collections/{vsp_templates.rb → forwarding_group_templates.rb} +12 -16
  13. data/lib/cimi/collections/{vsp_configurations.rb → forwarding_groups.rb} +12 -13
  14. data/lib/cimi/collections/machine_configurations.rb +2 -2
  15. data/lib/cimi/collections/machine_images.rb +1 -1
  16. data/lib/cimi/collections/machines.rb +8 -2
  17. data/lib/cimi/collections/network_configurations.rb +2 -2
  18. data/lib/cimi/collections/{routing_groups.rb → network_port_configurations.rb} +12 -12
  19. data/lib/cimi/collections/{routing_group_templates.rb → network_port_templates.rb} +15 -12
  20. data/lib/cimi/collections/{vsps.rb → network_ports.rb} +33 -32
  21. data/lib/cimi/collections/network_templates.rb +2 -2
  22. data/lib/cimi/collections/networks.rb +17 -2
  23. data/lib/cimi/collections/{entity_metadata.rb → resource_metadata.rb} +10 -10
  24. data/lib/cimi/collections/volume_configurations.rb +1 -1
  25. data/lib/cimi/collections/volume_images.rb +1 -1
  26. data/lib/cimi/collections/volumes.rb +1 -2
  27. data/lib/cimi/dependencies.rb +1 -1
  28. data/lib/cimi/helpers.rb +3 -84
  29. data/lib/cimi/helpers/cimi_helper.rb +15 -14
  30. data/lib/cimi/models.rb +20 -36
  31. data/lib/cimi/models/address.rb +32 -4
  32. data/lib/cimi/models/address_template.rb +2 -2
  33. data/lib/cimi/models/base.rb +24 -5
  34. data/lib/cimi/models/cloud_entry_point.rb +4 -9
  35. data/lib/cimi/models/collection.rb +101 -0
  36. data/lib/cimi/models/{machine_admin.rb → credential.rb} +6 -4
  37. data/lib/cimi/models/disk_collection.rb +1 -2
  38. data/lib/cimi/models/{routing_group_template.rb → forwarding_group.rb} +5 -3
  39. data/lib/cimi/models/{routing_group.rb → forwarding_group_template.rb} +5 -3
  40. data/lib/cimi/models/machine.rb +9 -7
  41. data/lib/cimi/models/machine_configuration.rb +2 -0
  42. data/lib/cimi/models/machine_image.rb +2 -0
  43. data/lib/cimi/models/machine_template.rb +3 -1
  44. data/lib/cimi/models/machine_volume_collection.rb +1 -1
  45. data/lib/cimi/models/network.rb +2 -0
  46. data/lib/cimi/models/network_configuration.rb +4 -8
  47. data/lib/cimi/models/{vsp.rb → network_port.rb} +7 -11
  48. data/lib/cimi/models/{network_configuration_collection.rb → network_port_collection.rb} +25 -8
  49. data/lib/cimi/models/{vsp_configuration.rb → network_port_configuration.rb} +6 -10
  50. data/lib/cimi/models/{network_collection.rb → network_port_configuration_collection.rb} +9 -9
  51. data/lib/cimi/models/{vsp_template.rb → network_port_template.rb} +6 -4
  52. data/lib/cimi/models/{network_template_collection.rb → network_port_template_collection.rb} +10 -8
  53. data/lib/cimi/models/network_template.rb +3 -1
  54. data/lib/cimi/models/{entity_metadata.rb → resource_metadata.rb} +16 -15
  55. data/lib/cimi/models/schema.rb +23 -12
  56. data/lib/cimi/models/volume.rb +2 -0
  57. data/lib/cimi/models/volume_configuration.rb +2 -0
  58. data/lib/cimi/models/volume_image.rb +2 -0
  59. data/lib/cimi/models/volume_template.rb +2 -0
  60. data/lib/cimi/server.rb +10 -6
  61. data/lib/deltacloud/collections.rb +7 -2
  62. data/lib/deltacloud/collections/addresses.rb +3 -1
  63. data/lib/deltacloud/collections/base.rb +64 -0
  64. data/lib/deltacloud/collections/buckets.rb +14 -4
  65. data/lib/deltacloud/collections/drivers.rb +1 -1
  66. data/lib/deltacloud/collections/firewalls.rb +1 -1
  67. data/lib/deltacloud/collections/instances.rb +5 -1
  68. data/lib/deltacloud/collections/keys.rb +1 -1
  69. data/lib/deltacloud/collections/load_balancers.rb +2 -0
  70. data/lib/deltacloud/collections/storage_volumes.rb +3 -5
  71. data/lib/deltacloud/core_ext.rb +1 -0
  72. data/lib/deltacloud/core_ext/hash.rb +8 -0
  73. data/lib/deltacloud/core_ext/ordered_hash.rb +222 -0
  74. data/lib/deltacloud/core_ext/string.rb +9 -0
  75. data/lib/deltacloud/drivers/aruba/aruba_driver.rb +0 -9
  76. data/lib/deltacloud/drivers/base_driver.rb +22 -4
  77. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +0 -4
  78. data/lib/deltacloud/drivers/exceptions.rb +30 -13
  79. data/lib/deltacloud/drivers/features.rb +7 -0
  80. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +1 -9
  81. data/lib/deltacloud/drivers/google/google_driver.rb +13 -0
  82. data/lib/deltacloud/drivers/mock/data/addresses/192.168.0.1.yml +3 -0
  83. data/lib/deltacloud/drivers/mock/data/addresses/192.168.0.2.yml +3 -0
  84. data/lib/deltacloud/drivers/mock/data/addresses/192.168.0.3.yml +3 -0
  85. data/lib/deltacloud/drivers/mock/data/addresses/192.168.0.4.yml +3 -0
  86. data/lib/deltacloud/drivers/mock/mock_driver.rb +65 -1
  87. data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +55 -32
  88. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +18 -6
  89. data/lib/deltacloud/helpers.rb +0 -75
  90. data/lib/deltacloud/helpers/deltacloud_helper.rb +66 -28
  91. data/lib/deltacloud/helpers/driver_helper.rb +7 -0
  92. data/lib/deltacloud/helpers/rabbit_helper.rb +51 -0
  93. data/lib/deltacloud/server.rb +12 -14
  94. data/lib/deltacloud/version.rb +1 -1
  95. data/lib/deltacloud_rack.rb +26 -2
  96. data/lib/ec2/query_parser.rb +18 -3
  97. data/lib/sinatra/rack_accept.rb +7 -2
  98. data/lib/sinatra/rack_matrix_params.rb +14 -14
  99. data/public/javascripts/cmwgapp.js +2 -2
  100. data/tests/cimi/collections/cloud_entry_point_test.rb +3 -3
  101. data/tests/cimi/collections/machine_images_test.rb +2 -2
  102. data/tests/cimi/collections/machines_test.rb +1 -1
  103. data/tests/cimi/collections/url_helper_test.rb +31 -0
  104. data/tests/cimi/spec/cimi/model/{machine_admin_spec.rb → credential_spec.rb} +4 -4
  105. data/tests/deltacloud/base_collection_test.rb +0 -5
  106. data/tests/deltacloud/collections/buckets_collection_test.rb +1 -1
  107. data/tests/deltacloud/collections/drivers_collection_test.rb +1 -1
  108. data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +1 -1
  109. data/tests/deltacloud/collections/images_collection_test.rb +1 -1
  110. data/tests/deltacloud/collections/instance_states_collection_test.rb +1 -1
  111. data/tests/deltacloud/collections/instances_collection_test.rb +1 -1
  112. data/tests/deltacloud/collections/keys_collection_test.rb +1 -4
  113. data/tests/deltacloud/deltacloud_helper_test.rb +0 -9
  114. data/tests/deltacloud/server_test.rb +1 -1
  115. data/tests/drivers/base/base_driver_test.rb +30 -0
  116. data/tests/drivers/base/common.rb +14 -0
  117. data/tests/drivers/base/exceptions_test.rb +64 -0
  118. data/tests/drivers/ec2/buckets_test.rb +45 -0
  119. data/tests/drivers/ec2/keys_test.rb +1 -1
  120. data/tests/drivers/google/buckets_test.rb +2 -2
  121. data/tests/drivers/google/common.rb +3 -3
  122. data/tests/test_helper.rb +28 -0
  123. data/views/api/show.html.haml +2 -2
  124. data/views/api/show.xml.haml +1 -1
  125. data/views/buckets/index.html.haml +1 -1
  126. data/views/cimi/cloudEntryPoint/index.xml.haml +1 -1
  127. data/views/cimi/collection/index.html.haml +3 -3
  128. data/views/cimi/collection/response.xml.haml +1 -1
  129. data/views/cimi/error.html.haml +1 -1
  130. data/views/cimi/errors/500.xml.haml +1 -1
  131. data/views/cimi/layout.html.haml +1 -1
  132. data/views/cimi/machine_configurations/show.html.haml +2 -2
  133. data/views/cimi/machine_configurations/show.xml.haml +1 -1
  134. data/views/cimi/machine_images/show.html.haml +2 -2
  135. data/views/cimi/machine_images/show.xml.haml +1 -1
  136. data/views/cimi/machines/show.html.haml +2 -2
  137. data/views/cimi/machines/show.xml.haml +1 -1
  138. data/views/cimi/volumes/show.html.haml +2 -2
  139. data/views/cimi/volumes/show.xml.haml +1 -1
  140. data/views/docs/collection.html.haml +1 -1
  141. data/views/docs/collection.xml.haml +2 -2
  142. data/views/docs/index.html.haml +1 -1
  143. data/views/docs/index.xml.haml +1 -1
  144. data/views/docs/operation.xml.haml +1 -1
  145. data/views/error.html.haml +1 -1
  146. data/views/errors/500.html.haml +7 -4
  147. data/views/firewalls/index.html.haml +1 -1
  148. data/views/firewalls/show.html.haml +1 -1
  149. data/views/images/show.html.haml +2 -2
  150. data/views/index.html.haml +9 -0
  151. data/views/instance_states/show.html.haml +1 -1
  152. data/views/instances/run_command.html.haml +1 -1
  153. data/views/instances/show.html.haml +2 -2
  154. data/views/keys/index.html.haml +1 -1
  155. data/views/layout.html.haml +1 -1
  156. data/views/load_balancers/index.html.haml +1 -1
  157. data/views/load_balancers/show.html.haml +3 -3
  158. data/views/storage_snapshots/show.html.haml +1 -1
  159. data/views/storage_volumes/attach.html.haml +1 -1
  160. data/views/storage_volumes/index.html.haml +1 -1
  161. data/views/storage_volumes/show.html.haml +4 -4
  162. metadata +40 -43
  163. data/lib/cimi/models/address_collection.rb +0 -34
  164. data/lib/cimi/models/address_template_collection.rb +0 -34
  165. data/lib/cimi/models/entity_metadata_collection.rb +0 -31
  166. data/lib/cimi/models/machine_admin_collection.rb +0 -34
  167. data/lib/cimi/models/machine_collection.rb +0 -37
  168. data/lib/cimi/models/machine_configuration_collection.rb +0 -36
  169. data/lib/cimi/models/machine_image_collection.rb +0 -36
  170. data/lib/cimi/models/machine_template_collection.rb +0 -36
  171. data/lib/cimi/models/routing_group_collection.rb +0 -34
  172. data/lib/cimi/models/routing_group_template_collection.rb +0 -35
  173. data/lib/cimi/models/volume_collection.rb +0 -36
  174. data/lib/cimi/models/volume_configuration_collection.rb +0 -36
  175. data/lib/cimi/models/volume_image_collection.rb +0 -36
  176. data/lib/cimi/models/volume_template_collection.rb +0 -36
  177. data/lib/cimi/models/vsp_collection.rb +0 -34
  178. data/lib/cimi/models/vsp_configuration_collection.rb +0 -34
  179. data/lib/cimi/models/vsp_template_collection.rb +0 -34
  180. data/lib/deltacloud/helpers/url_helper.rb +0 -115
@@ -131,7 +131,7 @@ module Deltacloud
131
131
 
132
132
  # Condition can be class or regexp
133
133
  #
134
- def match?(e)
134
+ def any?(e)
135
135
  @conditions.each do |c|
136
136
  return true if c.class == Class && e.class == c
137
137
  return true if c.class == Regexp && (e.class.name =~ c or e.message =~ c)
@@ -172,27 +172,44 @@ module Deltacloud
172
172
  end
173
173
 
174
174
  def self.exceptions(&block)
175
+ @definitions ||= []
175
176
  @definitions = Exceptions.new(&block).exception_definitions if block_given?
176
177
  @definitions
177
178
  end
178
179
 
180
+ module DSL
181
+ def exceptions(&block)
182
+ @definitions = Exceptions.new(&block).exception_definitions if block_given?
183
+ @definitions ||= []
184
+ @definitions
185
+ end
186
+ end
187
+
188
+ def self.logger(logger=nil)
189
+ @logger = logger
190
+ @logger ||= ::Logger.new($stderr)
191
+ end
192
+
193
+ def self.included(klass)
194
+ klass.extend(DSL)
195
+ end
196
+
179
197
  def safely(&block)
180
198
  begin
181
199
  block.call
182
- rescue
183
- report_method = $stderr.respond_to?(:err) ? :err : :puts
184
- Deltacloud::ExceptionHandler::exceptions.each do |exdef|
185
- if exdef.match?($!)
186
- new_exception = exdef.handler($!)
187
- m = (new_exception && !new_exception.message.nil?) ? new_exception.message : $!.message
188
- unless ENV['RACK_ENV'] == 'test'
189
- $stderr.send(report_method, "#{[$!.class.to_s, m].join(':')}\n#{$!.backtrace[0..10].join("\n")}")
190
- end
191
- raise exdef.handler($!) unless new_exception.nil?
200
+ rescue => e
201
+ log = ExceptionHandler.logger
202
+ self.class.exceptions.each do |definitions|
203
+ next unless definitions.any? e
204
+ if (new_exception = definitions.handler(e)) and new_exception.message
205
+ message = new_exception.message
192
206
  end
207
+ message ||= e.message
208
+ log.error "#{[e.class.to_s, message].join(':')}\n#{e.backtrace[0..10].join("\n")}" unless ENV['RACK_ENV'] == 'test'
209
+ raise definitions.handler(e) unless new_exception.nil?
193
210
  end
194
- $stderr.send(report_method, "[NO HANDLED] #{[$!.class.to_s, $!.message].join(': ')}\n#{$!.backtrace.join("\n")}")
195
- raise Deltacloud::ExceptionHandler::BackendError.new($!, "Unhandled exception or status code (#{$!.message})")
211
+ log.error "[NO HANDLED] #{[e.class.to_s, e.message].join(': ')}\n#{e.backtrace.join("\n")}" unless ENV['RACK_ENV'] == 'test'
212
+ raise BackendError.new(e, "Unhandled exception or status code (#{e.message})")
196
213
  end
197
214
  end
198
215
 
@@ -65,6 +65,13 @@ module Deltacloud
65
65
  end
66
66
  end
67
67
 
68
+ feature :realm_filter, :for => :instances do
69
+ description "Filter instances by realm"
70
+ operation :index do
71
+ param :realm_id, :string, :optional
72
+ end
73
+ end
74
+
68
75
  feature :user_name, :for => :instances do
69
76
  description "Allow to set user-defined name for the instance"
70
77
  operation :create do
@@ -25,11 +25,7 @@ module Deltacloud
25
25
  module Fgcp
26
26
  class FgcpDriver < Deltacloud::BaseDriver
27
27
 
28
- CERT_DIR = ENV['FGCP_CERT_DIR'] || File::expand_path('~/.deltacloud/config/fgcp')
29
-
30
- def supported_collections
31
- DEFAULT_COLLECTIONS + [ :addresses, :load_balancers, :firewalls ]
32
- end
28
+ CERT_DIR = ENV['FGCP_CERT_DIR'] || File::expand_path('~/.deltacloud/drivers/fgcp')
33
29
 
34
30
  feature :instances, :user_name
35
31
  feature :instances, :metrics
@@ -678,10 +674,6 @@ class FgcpDriver < Deltacloud::BaseDriver
678
674
  addresses
679
675
  end
680
676
 
681
- def address(credentials, opts={})
682
- addresses(credentials, opts).first
683
- end
684
-
685
677
  def create_address(credentials, opts={})
686
678
  safely do
687
679
  client = new_client(credentials)
@@ -202,6 +202,19 @@ class GoogleDriver < Deltacloud::BaseDriver
202
202
  return true
203
203
  end
204
204
 
205
+ exceptions do
206
+
207
+ on /(InvalidAccessKeyId|InvalidSecurity)/ do
208
+ status 401
209
+ end
210
+
211
+ on /BucketNameUnavailable/ do
212
+ message "Bucket name already taken"
213
+ status 409
214
+ end
215
+
216
+ end
217
+
205
218
  private
206
219
 
207
220
  def new_client(credentials)
@@ -0,0 +1,3 @@
1
+ ---
2
+ :id: 192.168.0.1
3
+ :instance_id:
@@ -0,0 +1,3 @@
1
+ ---
2
+ :id: 192.168.0.2
3
+ :instance_id:
@@ -0,0 +1,3 @@
1
+ ---
2
+ :id: "192.168.0.3"
3
+ :instance_id:
@@ -0,0 +1,3 @@
1
+ ---
2
+ :id: "192.168.0.4"
3
+ :instance_id:
@@ -17,6 +17,7 @@
17
17
  require 'yaml'
18
18
  require 'base64'
19
19
  require 'etc'
20
+ require 'ipaddr'
20
21
 
21
22
  require_relative 'mock_client'
22
23
  require_relative 'mock_driver_cimi_methods'
@@ -79,6 +80,7 @@ module Deltacloud::Drivers::Mock
79
80
  feature :instances, :user_data
80
81
  feature :instances, :authentication_key
81
82
  feature :instances, :metrics
83
+ feature :instances, :realm_filter
82
84
  feature :images, :user_name
83
85
  feature :images, :user_description
84
86
 
@@ -161,12 +163,13 @@ module Deltacloud::Drivers::Mock
161
163
  end
162
164
  end
163
165
 
164
- def instances(credentials, opts=nil)
166
+ def instances(credentials, opts={})
165
167
  check_credentials( credentials )
166
168
  instances = @client.build_all(Instance)
167
169
  instances = filter_on( instances, :owner_id, :owner_id => credentials.user )
168
170
  instances = filter_on( instances, :id, opts )
169
171
  instances = filter_on( instances, :state, opts )
172
+ instances = filter_on( instances, :realm_id, opts)
170
173
  instances
171
174
  end
172
175
 
@@ -333,6 +336,48 @@ module Deltacloud::Drivers::Mock
333
336
  @client.destroy(:keys, key.id)
334
337
  end
335
338
 
339
+ def addresses(credentials, opts={})
340
+ check_credentials(credentials)
341
+ addresses = @client.build_all(Address)
342
+ addresses = filter_on( addresses, :id, opts )
343
+ end
344
+
345
+ def create_address(credentials, opts={})
346
+ check_credentials(credentials)
347
+ address = {:id => allocate_mock_address.to_s, :instance_id=>nil}
348
+ @client.store(:addresses, address)
349
+ Address.new(address)
350
+ end
351
+
352
+ def destroy_address(credentials, opts={})
353
+ check_credentials(credentials)
354
+ address = @client.load(:addresses, opts[:id])
355
+ raise "AddressInUse" unless address[:instance_id].nil?
356
+ @client.destroy(:addresses, opts[:id])
357
+ end
358
+
359
+ def associate_address(credentials, opts={})
360
+ check_credentials(credentials)
361
+ address = @client.load(:addresses, opts[:id])
362
+ raise "AddressInUse" unless address[:instance_id].nil?
363
+ instance = @client.load(:instances, opts[:instance_id])
364
+ address[:instance_id] = instance[:id]
365
+ instance[:public_addresses] = [InstanceAddress.new(address[:id])]
366
+ @client.store(:addresses, address)
367
+ @client.store(:instances, instance)
368
+ end
369
+
370
+ def disassociate_address(credentials, opts={})
371
+ check_credentials(credentials)
372
+ address = @client.load(:addresses, opts[:id])
373
+ raise "AddressNotInUse" unless address[:instance_id]
374
+ instance = @client.load(:instances, address[:instance_id])
375
+ address[:instance_id] = nil
376
+ instance[:public_addresses] = [InstanceAddress.new("#{instance[:image_id]}.#{instance[:id]}.public.com", :type => :hostname)]
377
+ @client.store(:addresses, address)
378
+ @client.store(:instances, instance)
379
+ end
380
+
336
381
  #--
337
382
  # Buckets
338
383
  #--
@@ -530,6 +575,17 @@ module Deltacloud::Drivers::Mock
530
575
  end
531
576
  end
532
577
 
578
+ #Mock allocation of 'new' address
579
+ #There is a synchronization problem (but it's the mock driver,
580
+ #mutex seemed overkill)
581
+ def allocate_mock_address
582
+ addresses = []
583
+ @client.members(:addresses).each do |addr|
584
+ addresses << IPAddr.new("#{addr}").to_i
585
+ end
586
+ IPAddr.new(addresses.sort.pop+1, Socket::AF_INET)
587
+ end
588
+
533
589
  def attach_volume_instance(volume_id, device, instance_id)
534
590
  volume = @client.load(:storage_volumes, volume_id)
535
591
  instance = @client.load(:instances, instance_id)
@@ -597,6 +653,14 @@ module Deltacloud::Drivers::Mock
597
653
  message "Key with same name already exists"
598
654
  end
599
655
 
656
+ on /AddressInUse/ do
657
+ status 403
658
+ end
659
+
660
+ on /AddressNotInUse/ do
661
+ status 403
662
+ end
663
+
600
664
  on /BucketNotExist/ do
601
665
  status 404
602
666
  end
@@ -20,7 +20,6 @@
20
20
  module Deltacloud::Drivers::Mock
21
21
 
22
22
  class MockDriver < Deltacloud::BaseDriver
23
-
24
23
  def networks(credentials, opts={})
25
24
  check_credentials(credentials)
26
25
  if opts[:id].nil?
@@ -54,58 +53,69 @@ module Deltacloud::Drivers::Mock
54
53
  end
55
54
  end
56
55
 
57
- def routing_groups(credentials, opts={})
56
+ def forwarding_groups(credentials, opts={})
58
57
  check_credentials(credentials)
59
58
  if opts[:id].nil?
60
- routing_groups = @client.load_all_cimi(:routing_group).map{|rg| CIMI::Model::RoutingGroup.from_json(rg)}
61
- routing_groups.map{|rg|convert_cimi_mock_urls(:routing_group, rg, opts[:env])}.flatten
59
+ forwarding_groups = @client.load_all_cimi(:forwarding_group).map{|fg| CIMI::Model::ForwardingGroup.from_json(fg)}
60
+ forwarding_groups.map{|fg|convert_cimi_mock_urls(:forwarding_group, fg, opts[:env])}.flatten
62
61
  else
63
- routing_group = CIMI::Model::RoutingGroup.from_json(@client.load_cimi(:routing_group, opts[:id]))
64
- convert_cimi_mock_urls(:routing_group, routing_group, opts[:env])
62
+ forwarding_group = CIMI::Model::ForwardingGroup.from_json(@client.load_cimi(:forwarding_group, opts[:id]))
63
+ convert_cimi_mock_urls(:forwarding_group, forwarding_group, opts[:env])
65
64
  end
66
65
  end
67
66
 
68
- def routing_group_templates(credentials, opts={})
67
+ def forwarding_group_templates(credentials, opts={})
69
68
  check_credentials(credentials)
70
69
  if opts[:id].nil?
71
- routing_group_templates = @client.load_all_cimi(:routing_group_template).map{|rg_templ| CIMI::Model::RoutingGroupTemplate.from_json(rg_templ)}
72
- routing_group_templates.map{|rg_templ|convert_cimi_mock_urls(:routing_group_template, rg_templ, opts[:env])}.flatten
70
+ forwarding_group_templates = @client.load_all_cimi(:forwarding_group_template).map{|fg_templ| CIMI::Model::ForwardingGroupTemplate.from_json(fg_templ)}
71
+ forwarding_group_templates.map{|fg_templ|convert_cimi_mock_urls(:forwarding_group_template, fg_templ, opts[:env])}.flatten
73
72
  else
74
- routing_group_template = CIMI::Model::RoutingGroupTemplate.from_json(@client.load_cimi(:routing_group_template, opts[:id]))
75
- convert_cimi_mock_urls(:routing_group_template, routing_group_template, opts[:env])
73
+ forwarding_group_template = CIMI::Model::ForwardingGroupTemplate.from_json(@client.load_cimi(:forwarding_group_template, opts[:id]))
74
+ convert_cimi_mock_urls(:forwarding_group_template, forwarding_group_template, opts[:env])
76
75
  end
77
76
  end
78
77
 
79
- def vsps(credentials, opts={})
78
+ def network_ports(credentials, opts={})
80
79
  check_credentials(credentials)
81
80
  if opts[:id].nil?
82
- vsps = @client.load_all_cimi(:vsp).map{|vsp| CIMI::Model::VSP.from_json(vsp)}
83
- vsps.map{|vsp|convert_cimi_mock_urls(:vsp, vsp, opts[:env])}.flatten
81
+ ports = @client.load_all_cimi(:network_port).map{|net_port| CIMI::Model::NetworkPort.from_json(net_port)}
82
+ ports.map{|net_port|convert_cimi_mock_urls(:network_port, net_port, opts[:env])}.flatten
84
83
  else
85
- vsp = CIMI::Model::VSP.from_json(@client.load_cimi(:vsp, opts[:id]))
86
- convert_cimi_mock_urls(:vsp, vsp, opts[:env])
84
+ port = CIMI::Model::NetworkPort.from_json(@client.load_cimi(:network_port, opts[:id]))
85
+ convert_cimi_mock_urls(:network_port, port, opts[:env])
87
86
  end
88
87
  end
89
88
 
90
- def vsp_configurations(credentials, opts={})
89
+ def network_port_configurations(credentials, opts={})
91
90
  check_credentials(credentials)
92
91
  if opts[:id].nil?
93
- vsp_configurations = @client.load_all_cimi(:vsp_configuration).map{|vsp_config| CIMI::Model::VSPConfiguration.from_json(vsp_config)}
94
- vsp_configurations.map{|vsp_config|convert_cimi_mock_urls(:vsp_configuration, vsp_config, opts[:env])}.flatten
92
+ network_port_configurations = @client.load_all_cimi(:network_port_configuration).map{|network_port_config| CIMI::Model::NetworkPortConfiguration.from_json(network_port_config)}
93
+ network_port_configurations.map{|network_port_config|convert_cimi_mock_urls(:network_port_configuration, network_port_config, opts[:env])}.flatten
95
94
  else
96
- vsp_configuration = CIMI::Model::VSPConfiguration.from_json(@client.load_cimi(:vsp_configuration, opts[:id]))
97
- convert_cimi_mock_urls(:vsp_configuration, vsp_configuration, opts[:env])
95
+ network_port_configuration = CIMI::Model::NetworkPortConfiguration.from_json(@client.load_cimi(:network_port_configuration, opts[:id]))
96
+ convert_cimi_mock_urls(:network_port_configuration, network_port_configuration, opts[:env])
98
97
  end
99
98
  end
100
99
 
101
- def vsp_templates(credentials, opts={})
100
+ def network_port_templates(credentials, opts={})
102
101
  check_credentials(credentials)
103
102
  if opts[:id].nil?
104
- vsp_templates = @client.load_all_cimi(:vsp_template).map{|vsp_templ| CIMI::Model::VSPTemplate.from_json(vsp_templ)}
105
- vsp_templates.map{|vsp_templ|convert_cimi_mock_urls(:vsp_template, vsp_templ, opts[:env])}.flatten
103
+ network_port_templates = @client.load_all_cimi(:network_port_template).map{|net_port_templ| CIMI::Model::NetworkPortTemplate.from_json(net_port_templ)}
104
+ network_port_templates.map{|net_port_templ|convert_cimi_mock_urls(:network_port_template, net_port_templ, opts[:env])}.flatten
106
105
  else
107
- vsp_template = CIMI::Model::VSPTemplate.from_json(@client.load_cimi(:vsp_template, opts[:id]))
108
- convert_cimi_mock_urls(:vsp_template, vsp_template, opts[:env])
106
+ network_port_template = CIMI::Model::NetworkPortTemplate.from_json(@client.load_cimi(:network_port_template, opts[:id]))
107
+ convert_cimi_mock_urls(:network_port_template, network_port_template, opts[:env])
108
+ end
109
+ end
110
+
111
+ def address_templates(credentials, opts={})
112
+ check_credentials(credentials)
113
+ if opts[:id].nil?
114
+ address_templates = @client.load_all_cimi(:address_template).map{|addr_templ| CIMI::Model::AddressTemplate.from_json(addr_templ)}
115
+ address_templates.map{|addr_templ|convert_cimi_mock_urls(:address_template, addr_templ, opts[:env])}.flatten
116
+ else
117
+ address_template = CIMI::Model::AddressTemplate.from_json(@client.load_cimi(:address_template, opts[:id]))
118
+ convert_cimi_mock_urls(:address_template, address_template, opts[:env])
109
119
  end
110
120
  end
111
121
 
@@ -120,7 +130,11 @@ module Deltacloud::Drivers::Mock
120
130
  convert_struct_urls(item, k.to_s.singularize.to_sym, context)
121
131
  end
122
132
  else
123
- convert_struct_urls(v, k, context)
133
+ opts = nil
134
+ if is_subcollection?(v, cimi_object.id)
135
+ opts = {:parent_model_name => model_name, :parent_item_name => cimi_object.name}
136
+ end
137
+ convert_struct_urls(v, k, context, opts)
124
138
  end
125
139
  end
126
140
  end
@@ -130,13 +144,22 @@ module Deltacloud::Drivers::Mock
130
144
  cimi_object
131
145
  end
132
146
 
133
- def convert_struct_urls(struct, cimi_name, context)
147
+ def is_subcollection?(struct, cimi_object_id)
148
+ return false if struct.href.nil?
149
+ struct.href.include?(cimi_object_id)
150
+ end
151
+
152
+ def convert_struct_urls(struct, cimi_name, context, opts = nil)
134
153
  return unless (struct.respond_to?(:href) && (not struct.href.nil?) && (not cimi_name == :operation ))
135
- obj_name = struct.href.split("/").last
136
- if cimi_name.to_s.end_with?("config")
137
- struct.href = context.send(:"#{cimi_name}uration_url", obj_name)
154
+ if opts
155
+ struct.href = context.send(:"#{opts[:parent_model_name]}_url", opts[:parent_item_name]) + "/#{cimi_name}"
138
156
  else
139
- struct.href = context.send(:"#{cimi_name}_url", obj_name)
157
+ obj_name = struct.href.split("/").last
158
+ if cimi_name.to_s.end_with?("config")
159
+ struct.href = context.send(:"#{cimi_name}uration_url", obj_name)
160
+ else
161
+ struct.href = context.send(:"#{cimi_name}_url", obj_name)
162
+ end
140
163
  end
141
164
  end
142
165
 
@@ -40,6 +40,17 @@ module Deltacloud
40
40
 
41
41
  define_hardware_profile('default')
42
42
 
43
+ def supported_collections(credentials)
44
+ #get the collections as defined by 'capability' and 'respond_to?' blocks
45
+ super_collections = super
46
+ begin
47
+ client = new_client(credentials, :buckets)
48
+ rescue Deltacloud::ExceptionHandler::NotImplemented #OpenStack::Exception::NotImplemented...
49
+ return super_collections - [Sinatra::Rabbit::BucketsCollection]
50
+ end
51
+ super_collections
52
+ end
53
+
43
54
  def hardware_profiles(credentials, opts = {})
44
55
  os = new_client(credentials)
45
56
  results = []
@@ -333,6 +344,9 @@ private
333
344
  #for v2 authentication credentials.name == "username+tenant_name"
334
345
  def new_client(credentials, type = :compute)
335
346
  tokens = credentials.user.split("+")
347
+ if credentials.user.empty?
348
+ raise AuthenticationFailure.new(Exception.new("Error: you must supply the username"))
349
+ end
336
350
  if (tokens.size != 2 && api_v2)
337
351
  raise ValidationFailure.new(Exception.new("Error: expected \"username+tenantname\" as username, you provided: #{credentials.user}"))
338
352
  else
@@ -351,12 +365,6 @@ private
351
365
  end
352
366
  end
353
367
 
354
- def cloudfiles_client(credentials)
355
- safely do
356
- CloudFiles::Connection.new(:username => credentials.user, :api_key => credentials.password)
357
- end
358
- end
359
-
360
368
  #NOTE: for the convert_from_foo methods below... openstack-compute
361
369
  #gives Hash for 'flavors' but OpenStack::Compute::Flavor for 'flavor'
362
370
  #hence the use of 'send' to deal with both cases and save duplication
@@ -500,6 +508,10 @@ private
500
508
  status 400
501
509
  end
502
510
 
511
+ on /Must supply a :username/ do
512
+ status 401
513
+ end
514
+
503
515
  on /OpenStack::Exception::Authentication/ do
504
516
  status 401
505
517
  end