deltacloud-core 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/Rakefile +2 -2
  2. data/config/drivers/aruba.yaml +3 -3
  3. data/deltacloud-core.gemspec +2 -2
  4. data/lib/cimi/collections/address_templates.rb +1 -2
  5. data/lib/cimi/collections/addresses.rb +1 -2
  6. data/lib/cimi/collections/base.rb +1 -1
  7. data/lib/cimi/collections/credentials.rb +2 -3
  8. data/lib/cimi/collections/forwarding_group_templates.rb +1 -2
  9. data/lib/cimi/collections/forwarding_groups.rb +1 -2
  10. data/lib/cimi/collections/machine_configurations.rb +1 -2
  11. data/lib/cimi/collections/machine_images.rb +1 -2
  12. data/lib/cimi/collections/machines.rb +9 -9
  13. data/lib/cimi/collections/network_configurations.rb +1 -2
  14. data/lib/cimi/collections/network_port_configurations.rb +1 -2
  15. data/lib/cimi/collections/network_port_templates.rb +1 -2
  16. data/lib/cimi/collections/network_ports.rb +1 -2
  17. data/lib/cimi/collections/network_templates.rb +1 -2
  18. data/lib/cimi/collections/networks.rb +2 -3
  19. data/lib/cimi/collections/volume_configurations.rb +1 -2
  20. data/lib/cimi/collections/volume_images.rb +1 -2
  21. data/lib/cimi/collections/volumes.rb +3 -4
  22. data/lib/cimi/helpers/cimi_helper.rb +7 -2
  23. data/lib/cimi/models.rb +6 -10
  24. data/lib/cimi/models/base.rb +48 -35
  25. data/lib/cimi/models/cloud_entry_point.rb +22 -1
  26. data/lib/cimi/models/collection.rb +42 -5
  27. data/lib/cimi/models/credential.rb +1 -1
  28. data/lib/cimi/models/disk.rb +39 -10
  29. data/lib/cimi/models/machine.rb +39 -22
  30. data/lib/cimi/models/machine_configuration.rb +4 -5
  31. data/lib/cimi/models/machine_image.rb +1 -1
  32. data/lib/cimi/models/machine_volume.rb +1 -1
  33. data/lib/cimi/models/network.rb +6 -3
  34. data/lib/cimi/models/network_port.rb +13 -2
  35. data/lib/cimi/models/schema.rb +66 -5
  36. data/lib/cimi/models/volume.rb +17 -16
  37. data/lib/cimi/models/volume_configuration.rb +7 -10
  38. data/lib/cimi/models/volume_image.rb +1 -1
  39. data/lib/deltacloud/collections/base.rb +1 -1
  40. data/lib/deltacloud/collections/firewalls.rb +2 -2
  41. data/lib/deltacloud/collections/load_balancers.rb +8 -2
  42. data/lib/deltacloud/core_ext.rb +1 -0
  43. data/lib/deltacloud/core_ext/base.rb +30 -0
  44. data/lib/deltacloud/drivers.rb +1 -1
  45. data/lib/deltacloud/drivers/base_driver.rb +1 -1
  46. data/lib/deltacloud/drivers/condor/condor_driver.rb +1 -1
  47. data/lib/deltacloud/drivers/exceptions.rb +24 -14
  48. data/lib/deltacloud/drivers/features.rb +3 -3
  49. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +163 -92
  50. data/lib/deltacloud/drivers/mock/data/images/img1.yml +1 -0
  51. data/lib/deltacloud/drivers/mock/data/images/img2.yml +1 -0
  52. data/lib/deltacloud/drivers/mock/data/images/img3.yml +1 -0
  53. data/lib/deltacloud/drivers/mock/mock_client.rb +4 -4
  54. data/lib/deltacloud/drivers/mock/mock_driver.rb +16 -16
  55. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +25 -9
  56. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +2 -1
  57. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +1 -1
  58. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +2 -0
  59. data/lib/deltacloud/helpers/deltacloud_helper.rb +29 -8
  60. data/lib/deltacloud/models/image.rb +1 -0
  61. data/lib/deltacloud/models/instance_profile.rb +4 -0
  62. data/lib/deltacloud/version.rb +1 -1
  63. data/lib/ec2/query_parser.rb +1 -1
  64. data/lib/sinatra/rack_accept.rb +5 -1
  65. data/lib/sinatra/rack_logger.rb +9 -2
  66. data/tests/cimi/collections/machine_images_test.rb +23 -6
  67. data/tests/cimi/collections/machines_test.rb +39 -0
  68. data/tests/cimi/model/collection_spec.rb +109 -0
  69. data/tests/cimi/{spec/cimi/model → model}/credential_spec.rb +1 -1
  70. data/tests/cimi/{spec/cimi/model → model}/machine_configuration_spec.rb +1 -1
  71. data/tests/cimi/{spec/cimi/model → model}/machine_image_spec.rb +1 -1
  72. data/tests/cimi/{spec/cimi/model → model}/machine_spec.rb +1 -1
  73. data/tests/cimi/{spec/cimi/model → model}/machine_template_spec.rb +1 -1
  74. data/tests/cimi/{spec/cimi/model → model}/schema_spec.rb +1 -1
  75. data/tests/cimi/{spec/cimi/model → model}/volume_configuration_spec.rb +1 -1
  76. data/tests/cimi/{spec/cimi/model → model}/volume_image_spec.rb +1 -1
  77. data/tests/cimi/{spec/cimi/model → model}/volume_spec.rb +1 -1
  78. data/tests/cimi/{spec/cimi/model → model}/volume_template_spec.rb +1 -1
  79. data/tests/cimi/{spec/spec_helper.rb → spec_helper.rb} +7 -4
  80. data/tests/drivers/base/exceptions_test.rb +8 -8
  81. data/tests/drivers/ec2/buckets_test.rb +1 -1
  82. data/tests/drivers/ec2/images_test.rb +1 -1
  83. data/tests/drivers/ec2/instance_test.rb +1 -1
  84. data/tests/drivers/ec2/keys_test.rb +2 -2
  85. data/tests/drivers/ec2/realms_test.rb +1 -1
  86. data/tests/drivers/ec2/storage_snapshots_test.rb +1 -1
  87. data/tests/drivers/gogrid/hardware_profiles_test.rb +1 -1
  88. data/tests/drivers/gogrid/images_test.rb +1 -1
  89. data/tests/drivers/gogrid/instances_test.rb +1 -1
  90. data/tests/drivers/gogrid/realms_test.rb +1 -1
  91. data/tests/drivers/mock/images_test.rb +7 -2
  92. data/tests/drivers/mock/instances_test.rb +1 -1
  93. data/tests/drivers/mock/keys_test.rb +2 -2
  94. data/tests/drivers/mock/realms_test.rb +1 -1
  95. data/tests/drivers/mock/storage_snapshots_test.rb +1 -1
  96. data/tests/drivers/mock/storage_volumes_test.rb +1 -1
  97. data/tests/drivers/openstack/hardware_profiles_test.rb +3 -3
  98. data/tests/drivers/openstack/images_test.rb +1 -1
  99. data/tests/drivers/openstack/instances_test.rb +1 -1
  100. data/tests/drivers/openstack/keys_test.rb +2 -2
  101. data/tests/drivers/openstack/realms_test.rb +1 -1
  102. data/tests/drivers/rhevm/common.rb +3 -3
  103. data/tests/drivers/rhevm/images_test.rb +13 -13
  104. data/tests/drivers/rhevm/instance_test.rb +22 -22
  105. data/tests/drivers/rhevm/provider_test.rb +3 -3
  106. data/tests/drivers/rhevm/realms_test.rb +7 -7
  107. data/tests/test_helper.rb +0 -5
  108. data/views/api/show.xml.haml +6 -3
  109. data/views/errors/401.html.haml +0 -16
  110. data/views/errors/404.html.haml +2 -3
  111. data/views/errors/500.html.haml +6 -5
  112. data/views/images/show.html.haml +5 -1
  113. data/views/images/show.xml.haml +8 -3
  114. data/views/instances/new.html.haml +1 -1
  115. data/views/instances/show.xml.haml +1 -1
  116. data/views/load_balancers/show.html.haml +1 -1
  117. metadata +761 -778
  118. data/lib/cimi/models/disk_collection.rb +0 -37
  119. data/lib/cimi/models/machine_volume_collection.rb +0 -34
  120. data/lib/cimi/models/network_port_collection.rb +0 -51
  121. data/lib/cimi/models/network_port_configuration_collection.rb +0 -35
  122. data/lib/cimi/models/network_port_template_collection.rb +0 -37
@@ -5,3 +5,4 @@
5
5
  :id: img1
6
6
  :name: img1
7
7
  :description: Fedora 10
8
+ :creation_time: "Thu Oct 25 14:27:53 CEST 2012"
@@ -5,3 +5,4 @@
5
5
  :id: img2
6
6
  :name: img2
7
7
  :description: Fedora 10
8
+ :creation_time: "Thu Oct 25 14:27:53 CEST 2012"
@@ -5,3 +5,4 @@
5
5
  :id: img3
6
6
  :name: img3
7
7
  :description: JBoss
8
+ :creation_time: "Thu Oct 25 14:27:53 CEST 2012"
@@ -56,10 +56,10 @@ module Deltacloud::Drivers::Mock
56
56
  files(collection).map { |f| File::basename(f, ".yml") }
57
57
  end
58
58
 
59
- def load(collection, id)
59
+ def load_collection(collection, id)
60
60
  fname = file(collection, id)
61
61
  begin
62
- YAML.load(File.read(fname))
62
+ YAML.load_file(fname)
63
63
  rescue Errno::ENOENT
64
64
  nil
65
65
  end
@@ -73,12 +73,12 @@ module Deltacloud::Drivers::Mock
73
73
  # Return the object with id +id+ of class +klass+ from the collection
74
74
  # derived from the classes name
75
75
  def build(klass, id)
76
- klass.new(load(collection_name(klass), id))
76
+ klass.new(load_collection(collection_name(klass), id))
77
77
  end
78
78
 
79
79
  # Return an array of hashes of all the resources in the collection
80
80
  def load_all(collection)
81
- members(collection).map { |id| load(collection, id) }
81
+ members(collection).map { |id| load_collection(collection, id) }
82
82
  end
83
83
 
84
84
  # Return an array of model objects of the resources in the collection
@@ -158,7 +158,7 @@ module Deltacloud::Drivers::Mock
158
158
 
159
159
  def instance(credentials, opts={})
160
160
  check_credentials( credentials )
161
- if instance = @client.load(:instances, opts[:id])
161
+ if instance = @client.load_collection(:instances, opts[:id])
162
162
  Instance.new(instance)
163
163
  end
164
164
  end
@@ -217,7 +217,7 @@ module Deltacloud::Drivers::Mock
217
217
  end
218
218
 
219
219
  def update_instance_state(credentials, id, state)
220
- instance = @client.load(:instances, id)
220
+ instance = @client.load_collection(:instances, id)
221
221
  instance[:state] = state
222
222
  instance[:actions] = instance_actions_for( instance[:state] )
223
223
  @client.store(:instances, instance)
@@ -325,7 +325,7 @@ module Deltacloud::Drivers::Mock
325
325
  :pem_rsa_key => Key::generate_mock_pem
326
326
  }
327
327
  safely do
328
- raise "KeyExist" if @client.load(:keys, key_hash[:id])
328
+ raise "KeyExist" if @client.load_collection(:keys, key_hash[:id])
329
329
  @client.store(:keys, key_hash)
330
330
  end
331
331
  return Key.new(key_hash)
@@ -351,16 +351,16 @@ module Deltacloud::Drivers::Mock
351
351
 
352
352
  def destroy_address(credentials, opts={})
353
353
  check_credentials(credentials)
354
- address = @client.load(:addresses, opts[:id])
354
+ address = @client.load_collection(:addresses, opts[:id])
355
355
  raise "AddressInUse" unless address[:instance_id].nil?
356
356
  @client.destroy(:addresses, opts[:id])
357
357
  end
358
358
 
359
359
  def associate_address(credentials, opts={})
360
360
  check_credentials(credentials)
361
- address = @client.load(:addresses, opts[:id])
361
+ address = @client.load_collection(:addresses, opts[:id])
362
362
  raise "AddressInUse" unless address[:instance_id].nil?
363
- instance = @client.load(:instances, opts[:instance_id])
363
+ instance = @client.load_collection(:instances, opts[:instance_id])
364
364
  address[:instance_id] = instance[:id]
365
365
  instance[:public_addresses] = [InstanceAddress.new(address[:id])]
366
366
  @client.store(:addresses, address)
@@ -369,9 +369,9 @@ module Deltacloud::Drivers::Mock
369
369
 
370
370
  def disassociate_address(credentials, opts={})
371
371
  check_credentials(credentials)
372
- address = @client.load(:addresses, opts[:id])
372
+ address = @client.load_collection(:addresses, opts[:id])
373
373
  raise "AddressNotInUse" unless address[:instance_id]
374
- instance = @client.load(:instances, address[:instance_id])
374
+ instance = @client.load_collection(:instances, address[:instance_id])
375
375
  address[:instance_id] = nil
376
376
  instance[:public_addresses] = [InstanceAddress.new("#{instance[:image_id]}.#{instance[:id]}.public.com", :type => :hostname)]
377
377
  @client.store(:addresses, address)
@@ -434,7 +434,7 @@ module Deltacloud::Drivers::Mock
434
434
  #--
435
435
  def blob_data(credentials, bucket_id, blob_id, opts = {})
436
436
  check_credentials(credentials)
437
- if blob = @client.load(:blobs, blob_id)
437
+ if blob = @client.load_collection(:blobs, blob_id)
438
438
  #give event machine a chance
439
439
  sleep 1
440
440
  blob[:content].split('').each {|part| yield part}
@@ -478,7 +478,7 @@ module Deltacloud::Drivers::Mock
478
478
  def delete_blob(credentials, bucket_id, blob_id, opts={})
479
479
  check_credentials(credentials)
480
480
  safely do
481
- raise "NotExistentBlob" unless @client.load(:blobs, blob_id)
481
+ raise "NotExistentBlob" unless @client.load_collection(:blobs, blob_id)
482
482
  @client.destroy(:blobs, blob_id)
483
483
  end
484
484
  end
@@ -488,7 +488,7 @@ module Deltacloud::Drivers::Mock
488
488
  #--
489
489
  def blob_metadata(credentials, opts={})
490
490
  check_credentials(credentials)
491
- if blob = @client.load(:blobs, opts[:id])
491
+ if blob = @client.load_collection(:blobs, opts[:id])
492
492
  blob[:user_metadata]
493
493
  else
494
494
  nil
@@ -501,7 +501,7 @@ module Deltacloud::Drivers::Mock
501
501
  def update_blob_metadata(credentials, opts={})
502
502
  check_credentials(credentials)
503
503
  safely do
504
- blob = @client.load(:blobs, opts[:id])
504
+ blob = @client.load_collection(:blobs, opts[:id])
505
505
  return false unless blob
506
506
  blob[:user_metadata] = BlobHelper::rename_metadata_headers(opts['meta_hash'], '')
507
507
  @client.store(:blobs, blob)
@@ -587,8 +587,8 @@ module Deltacloud::Drivers::Mock
587
587
  end
588
588
 
589
589
  def attach_volume_instance(volume_id, device, instance_id)
590
- volume = @client.load(:storage_volumes, volume_id)
591
- instance = @client.load(:instances, instance_id)
590
+ volume = @client.load_collection(:storage_volumes, volume_id)
591
+ instance = @client.load_collection(:instances, instance_id)
592
592
  volume[:instance_id] = instance_id
593
593
  volume[:device] = device
594
594
  volume[:state] = "IN-USE"
@@ -600,8 +600,8 @@ module Deltacloud::Drivers::Mock
600
600
  end
601
601
 
602
602
  def detach_volume_instance(volume_id, instance_id)
603
- volume = @client.load(:storage_volumes, volume_id)
604
- instance = @client.load(:instances, instance_id)
603
+ volume = @client.load_collection(:storage_volumes, volume_id)
604
+ instance = @client.load_collection(:instances, instance_id)
605
605
  volume[:instance_id] = nil
606
606
  device = volume[:device]
607
607
  volume[:device] = nil
@@ -16,6 +16,7 @@
16
16
 
17
17
  require 'openstack'
18
18
  require 'tempfile'
19
+ require 'base64'
19
20
 
20
21
  module Deltacloud
21
22
  module Drivers
@@ -26,6 +27,7 @@ module Deltacloud
26
27
  feature :instances, :authentication_key
27
28
  feature :instances, :authentication_password
28
29
  feature :instances, :user_files
30
+ feature :instances, :user_data
29
31
  feature :images, :user_name
30
32
  feature :keys, :import_key
31
33
 
@@ -44,8 +46,8 @@ module Deltacloud
44
46
  #get the collections as defined by 'capability' and 'respond_to?' blocks
45
47
  super_collections = super
46
48
  begin
47
- client = new_client(credentials, :buckets)
48
- rescue Deltacloud::ExceptionHandler::NotImplemented #OpenStack::Exception::NotImplemented...
49
+ new_client(credentials, :buckets)
50
+ rescue Deltacloud::Exceptions::NotImplemented #OpenStack::Exception::NotImplemented...
49
51
  return super_collections - [Sinatra::Rabbit::BucketsCollection]
50
52
  end
51
53
  super_collections
@@ -110,8 +112,8 @@ module Deltacloud
110
112
  begin
111
113
  image = os.get_image(image_id)
112
114
  image.delete!
113
- rescue => e
114
- raise Deltacloud::ExceptionHandler::BackendError.new(e, "ERROR: Cannot delete image with ID:#{image_id}.")
115
+ rescue
116
+ raise Deltacloud::Exceptions.exception_from_status(500, "Cannot delete image with id #{image_id}")
115
117
  end
116
118
  end
117
119
 
@@ -165,13 +167,16 @@ module Deltacloud
165
167
  params[:name] = (opts[:name] && opts[:name].length>0)? opts[:name] : "server#{Time.now.to_s}"
166
168
  params[:imageRef] = image_id
167
169
  params[:flavorRef] = (opts[:hwp_id] && opts[:hwp_id].length>0) ?
168
- opts[:hwp_id] : hardware_profiles(credentials).first.name
170
+ opts[:hwp_id] : hardware_profiles(credentials).first.id
169
171
  if opts[:password] && opts[:password].length > 0
170
172
  params[:adminPass]=opts[:password]
171
173
  end
172
174
  if opts[:keyname] && opts[:keyname].length > 0
173
175
  params[:key_name]=opts[:keyname]
174
- end
176
+ end
177
+ if opts[:user_data] && opts[:user_data].length > 0
178
+ params[:user_data]=Base64.encode64(opts[:user_data])
179
+ end
175
180
  safely do
176
181
  server = os.create_server(params)
177
182
  result = convert_from_server(server, os.connection.authuser)
@@ -190,11 +195,19 @@ module Deltacloud
190
195
 
191
196
  def destroy_instance(credentials, instance_id)
192
197
  os = new_client(credentials)
198
+ server = instance = nil
193
199
  safely do
194
200
  server = os.get_server(instance_id)
195
201
  server.delete!
196
- convert_from_server(server, os.connection.authuser)
197
202
  end
203
+ begin
204
+ server.populate
205
+ instance = convert_from_server(server, os.connection.authuser)
206
+ rescue OpenStack::Exception::ItemNotFound
207
+ instance = convert_from_server(server, os.connection.authuser)
208
+ instance.state = "STOPPED"
209
+ end
210
+ instance
198
211
  end
199
212
 
200
213
  alias_method :stop_instance, :destroy_instance
@@ -371,12 +384,14 @@ private
371
384
 
372
385
  def convert_from_flavor(flavor)
373
386
  op = (flavor.class == Hash)? :fetch : :send
374
- HardwareProfile.new(flavor.send(op, :id).to_s) do
387
+ hwp = HardwareProfile.new(flavor.send(op, :id).to_s) do
375
388
  architecture 'x86_64'
376
389
  memory flavor.send(op, :ram).to_i
377
390
  storage flavor.send(op, :disk).to_i
378
391
  cpu flavor.send(op, :vcpus).to_i
379
392
  end
393
+ hwp.name = flavor.send(op, :name)
394
+ return hwp
380
395
  end
381
396
 
382
397
  def convert_from_image(image, owner)
@@ -387,7 +402,8 @@ private
387
402
  :description => image.send(op, :name),
388
403
  :owner_id => owner,
389
404
  :state => image.send(op, :status),
390
- :architecture => 'x86_64'
405
+ :architecture => 'x86_64',
406
+ :creation_time => image.send(op, :created)
391
407
  })
392
408
  end
393
409
 
@@ -309,7 +309,8 @@ class RhevmDriver < Deltacloud::BaseDriver
309
309
  :owner_id => client.credentials[:username],
310
310
  :architecture => 'x86_64', # All RHEV-M VMs are x86_64
311
311
  :hardware_profiles => hardware_profiles(nil),
312
- :state => img.status.strip.upcase
312
+ :state => img.status.gsub('\\', '').strip.upcase,
313
+ :creation_time => img.creation_time
313
314
  )
314
315
  end
315
316
 
@@ -139,7 +139,7 @@ VAPP_STATE_MAP = { "0" => "PENDING", "1" => "PENDING", "2" => "STOPPED", "4"
139
139
  end
140
140
  unless ( (terremark_hwp.include?(:cpu, opts[:hwp_cpu].to_i)) &&
141
141
  (terremark_hwp.include?(:memory, opts[:hwp_memory].to_i)) ) then
142
- raise Deltacloud::ExceptionHandler::ValidationFailure.new(
142
+ raise Deltacloud::Exceptions::ValidationFailure.new(
143
143
  StandardError.new("Error with cpu and/or memory values. you said cpu->#{opts[:hwp_cpu]} and mem->#{opts[:hwp_memory]}")
144
144
  )
145
145
  end
@@ -104,6 +104,7 @@ module Deltacloud::Drivers::Vsphere
104
104
  :owner_id => credentials.user,
105
105
  :description => properties[:full_name],
106
106
  :state => image_state,
107
+ :creation_time => image.storage[:timestamp],
107
108
  :hardware_profiles => profiles
108
109
  )
109
110
  end
@@ -194,6 +195,7 @@ module Deltacloud::Drivers::Vsphere
194
195
  :private_addresses => [],
195
196
  :instance_profile => instance_profile,
196
197
  :actions => instance_actions_for( instance_state ),
198
+ :launch_time => vm.runtime.props[:bootTime],
197
199
  :create_image => true
198
200
  )
199
201
  end
@@ -18,6 +18,10 @@ module Deltacloud::Helpers
18
18
 
19
19
  require 'benchmark'
20
20
 
21
+ def request_headers
22
+ env.inject({}){|acc, (k,v)| acc[$1.downcase] = v if k =~ /^http_(.*)/i; acc}
23
+ end
24
+
21
25
  def auth_feature_name
22
26
  return 'key' if driver.class.has_feature?(:instances, :authentication_key)
23
27
  return 'password' if driver.class.has_feature?(:instances, :authentication_password)
@@ -77,15 +81,32 @@ module Deltacloud::Helpers
77
81
  end
78
82
  end
79
83
 
84
+ # Log errors to the same logger as we use for logging requests
85
+ def log
86
+ Deltacloud::Exceptions.logger(Deltacloud.default_frontend.logger)
87
+ end
88
+
80
89
  def report_error(code=nil)
81
- @error, @code = (request.env['sinatra.error'] || @exception), code
82
- @code = 500 if not @code and not @error.class.method_defined? :code
83
- response.status = @code || @error.code
84
- log = Deltacloud::ExceptionHandler.logger
85
- message = @error.respond_to?(:message) ? @error.message : translate_error_code(@code)
90
+
91
+ if !code.nil?
92
+ @error = Deltacloud::Exceptions.exception_from_status(code, translate_error_code(code)[:message])
93
+ @code = code
94
+ message = @error.message
95
+ else
96
+ @error = request.env['sinatra.error'] || @exception
97
+ @code = @error.respond_to?(:code) ? @error.code : 500
98
+ message = @error.respond_to?(:message) ? @error.message : translate_error_code(code)[:message]
99
+ end
100
+
101
+ response.status = @code
102
+
86
103
  backtrace = (@error.respond_to?(:backtrace) and !@error.backtrace.nil?) ?
87
104
  "\n\n#{@error.backtrace[0..10].join("\n")}\n\n" : ''
88
- log.error "[#{@code}] #{[@error.class.to_s, message].join(':')}#{backtrace}"
105
+
106
+ if @code.to_s =~ /5(\d+)/
107
+ log.error(@code.to_s) { "[#{@error.class.to_s}] #{message}#{backtrace}" }
108
+ end
109
+
89
110
  respond_to do |format|
90
111
  format.xml { haml :"errors/#{@code || @error.code}", :layout => false }
91
112
  format.json { xml_to_json("errors/#{@code || @error.code}") }
@@ -307,11 +328,11 @@ module Deltacloud::Helpers
307
328
  end
308
329
 
309
330
  def bt(trace)
331
+ return [] unless trace
310
332
  return trace.join("\n") if params['fulltrace']
311
333
  app_path = File::expand_path("../../..", __FILE__)
312
334
  dots = false
313
-
314
- trace = trace.map { |t| t.match(%r{^#{app_path}(.*)$}) ? "$app#{$1}" : "..." }.select do |t|
335
+ trace = trace.map { |t| t.match(%r{^#{app_path}(.*)$}) ? "$app#{$1}" : "..." }.select do |t|
315
336
  if t == "..."
316
337
  keep = ! dots
317
338
  dots = true
@@ -23,5 +23,6 @@ class Image < BaseModel
23
23
  attr_accessor :architecture
24
24
  attr_accessor :state
25
25
  attr_accessor :hardware_profiles
26
+ attr_accessor :creation_time
26
27
 
27
28
  end
@@ -40,6 +40,10 @@ class InstanceProfile < BaseModel
40
40
  name
41
41
  end
42
42
 
43
+ def override?(property)
44
+ overrides.find { |p, v| p == property }
45
+ end
46
+
43
47
  def overrides
44
48
  [:memory, :storage, :architecture, :cpu].inject({}) do |h, p|
45
49
  if v = instance_variable_get("@#{p}")
@@ -15,5 +15,5 @@
15
15
  # under the License.
16
16
 
17
17
  module Deltacloud
18
- API_VERSION = '1.0.4' unless defined?(API_VERSION)
18
+ API_VERSION = '1.0.5' unless defined?(API_VERSION)
19
19
  end
@@ -24,7 +24,7 @@ module Deltacloud::EC2
24
24
  :describe_key_pairs => { :method => :keys, :params => {} },
25
25
  :create_key_pair => { :method => :create_key, :params => { 'KeyName' => :key_name }},
26
26
  :delete_key_pair => { :method => :destroy_key, :params => { 'KeyName' => :id }},
27
- :run_instances => { :method => :create_instance, :params => { 'ImageId' => :image_id, 'InstanceType' => :hwp_id, 'Placement.AvailabilityZone' => :realm_id }},
27
+ :run_instances => { :method => :create_instance, :params => { 'ImageId' => :image_id, 'InstanceType' => :hwp_id, 'Placement.AvailabilityZone' => :realm_id, 'UserData' => :user_data }},
28
28
  :stop_instances => { :method => :stop_instance, :params => { 'InstanceId.1' => :id }},
29
29
  :start_instances => { :method => :start_instance, :params => { 'InstanceId.1' => :id }},
30
30
  :reboot_instances => { :method => :reboot_instance, :params => { 'InstanceId.1' => :id }},
@@ -79,7 +79,11 @@ module Rack
79
79
  end
80
80
  yield wants
81
81
 
82
- if Deltacloud.default_frontend.name == :cimi
82
+ if request.env["SCRIPT_NAME"].include?("cimi") || Deltacloud.default_frontend.name == :cimi
83
+ #when cimi and neither json or xml defined... default to _something_ - json?
84
+ if ([:json, :xml] & accepting_formats.keys).empty?
85
+ request.env['rack-accept.formats'] = {:json=>0}
86
+ end
83
87
  @media_type = (accepting_formats.has_key?(:xml) ? [:xml, accepting_formats[:xml]] : nil)
84
88
  end if Deltacloud.respond_to? :default_frontend
85
89
 
@@ -50,6 +50,11 @@ module Rack
50
50
  self
51
51
  end
52
52
 
53
+ def self.error(code, &block)
54
+ @logger ||= ::Logger.new(log_path || $stdout)
55
+ @logger.error(code, &block)
56
+ end
57
+
53
58
  # Common Log Format: http://httpd.apache.org/docs/1.3/logs.html#common
54
59
  # lilith.local - - [07/Aug/2006 23:58:02] "GET / HTTP/1.1" 500 -
55
60
  # %{%s - %s [%s] "%s %s%s %s" %d %s\n} %
@@ -84,7 +89,8 @@ module Rack
84
89
  params = env['rack.request.form_hash'].nil? ? '' : ' '+env['rack.request.form_hash'].to_json
85
90
 
86
91
  logger = @logger || env['rack.errors']
87
- logger << VERBOSE_FORMAT % [
92
+ logger_method = logger.respond_to?(:info) ? :info : :puts
93
+ logger.send logger_method, VERBOSE_FORMAT % [
88
94
  env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-",
89
95
  env["REMOTE_USER"] || "-",
90
96
  now.strftime("%d/%b/%Y %H:%M:%S"),
@@ -105,7 +111,8 @@ module Rack
105
111
  length = extract_content_length(header)
106
112
 
107
113
  logger = @logger || env['rack.errors']
108
- logger << FORMAT % [
114
+ logger_method = logger.respond_to?(:info) ? :info : :puts
115
+ logger.send logger_method, FORMAT % [
109
116
  env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-",
110
117
  env["REMOTE_USER"] || "-",
111
118
  now.strftime("%d/%b/%Y %H:%M:%S"),
@@ -33,12 +33,29 @@ describe CIMI::Collections::MachineImages do
33
33
  xml.root.name.must_equal 'MachineImage'
34
34
  end
35
35
 
36
- it 'should allow to filter using CIMISelect' do
37
- get root_url '/machine_images?CIMISelect=description'
38
- status.must_equal 200
39
- xml.root.name.must_equal 'Collection'
40
- (xml/'description').wont_be_empty
41
- (xml/'id').must_be_empty
36
+ describe "filtering with $select" do
37
+ def machines(*select)
38
+ url = "/machine_images"
39
+ url += "?$select=#{select.join(",")}" unless select.empty?
40
+ get root_url url
41
+ status.must_equal 200
42
+ end
43
+
44
+ it 'should filter collection members' do
45
+ machines :description
46
+ (xml/'id').wont_be_empty
47
+ nimages = (xml/'MachineImage').size
48
+ (xml/'MachineImage/description').size.must_equal nimages
49
+ (xml/'MachineImage/id').must_be_empty
50
+ end
51
+
52
+ it 'should filter by multiple attributes' do
53
+ machines :description, :id
54
+ (xml/'id').wont_be_empty
55
+ nimages = (xml/'MachineImage').size
56
+ (xml/'MachineImage/description').size.must_equal nimages
57
+ (xml/'MachineImage/id').size.must_equal nimages
58
+ end
42
59
  end
43
60
 
44
61
  end