fog-ecloud 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1048 -11
  3. data/Rakefile +6 -4
  4. data/lib/fog/compute/ecloud.rb +18 -3
  5. data/lib/fog/compute/ecloud/errors.rb +91 -0
  6. data/lib/fog/compute/ecloud/models/admin_organizations.rb +2 -1
  7. data/lib/fog/compute/ecloud/models/api_keys.rb +2 -1
  8. data/lib/fog/compute/ecloud/models/associations.rb +2 -1
  9. data/lib/fog/compute/ecloud/models/authentication_levels.rb +2 -1
  10. data/lib/fog/compute/ecloud/models/backup_internet_services.rb +2 -1
  11. data/lib/fog/compute/ecloud/models/catalog.rb +3 -2
  12. data/lib/fog/compute/ecloud/models/catalog_configurations.rb +2 -1
  13. data/lib/fog/compute/ecloud/models/compute_pools.rb +2 -1
  14. data/lib/fog/compute/ecloud/models/cpu_usage_detail_summary.rb +2 -1
  15. data/lib/fog/compute/ecloud/models/detached_disks.rb +3 -2
  16. data/lib/fog/compute/ecloud/models/environments.rb +2 -1
  17. data/lib/fog/compute/ecloud/models/firewall_acls.rb +2 -1
  18. data/lib/fog/compute/ecloud/models/groups.rb +2 -1
  19. data/lib/fog/compute/ecloud/models/guest_processes.rb +2 -1
  20. data/lib/fog/compute/ecloud/models/hardware_configurations.rb +2 -1
  21. data/lib/fog/compute/ecloud/models/internet_services.rb +7 -6
  22. data/lib/fog/compute/ecloud/models/ip_addresses.rb +2 -1
  23. data/lib/fog/compute/ecloud/models/layouts.rb +2 -1
  24. data/lib/fog/compute/ecloud/models/locations.rb +2 -1
  25. data/lib/fog/compute/ecloud/models/login_banners.rb +2 -1
  26. data/lib/fog/compute/ecloud/models/memory_usage_detail_summary.rb +2 -1
  27. data/lib/fog/compute/ecloud/models/monitors.rb +2 -1
  28. data/lib/fog/compute/ecloud/models/networks.rb +3 -2
  29. data/lib/fog/compute/ecloud/models/nodes.rb +3 -2
  30. data/lib/fog/compute/ecloud/models/operating_system_families.rb +2 -1
  31. data/lib/fog/compute/ecloud/models/operating_systems.rb +2 -1
  32. data/lib/fog/compute/ecloud/models/organizations.rb +2 -1
  33. data/lib/fog/compute/ecloud/models/password_complexity_rules.rb +2 -1
  34. data/lib/fog/compute/ecloud/models/physical_devices.rb +2 -1
  35. data/lib/fog/compute/ecloud/models/public_ips.rb +3 -2
  36. data/lib/fog/compute/ecloud/models/rnats.rb +2 -1
  37. data/lib/fog/compute/ecloud/models/roles.rb +2 -1
  38. data/lib/fog/compute/ecloud/models/rows.rb +2 -1
  39. data/lib/fog/compute/ecloud/models/server.rb +40 -41
  40. data/lib/fog/compute/ecloud/models/server_configuration_options.rb +2 -1
  41. data/lib/fog/compute/ecloud/models/servers.rb +10 -9
  42. data/lib/fog/compute/ecloud/models/ssh_keys.rb +3 -2
  43. data/lib/fog/compute/ecloud/models/storage_usage_detail_summary.rb +2 -1
  44. data/lib/fog/compute/ecloud/models/support_tickets.rb +2 -1
  45. data/lib/fog/compute/ecloud/models/tags.rb +2 -1
  46. data/lib/fog/compute/ecloud/models/tasks.rb +2 -1
  47. data/lib/fog/compute/ecloud/models/templates.rb +2 -1
  48. data/lib/fog/compute/ecloud/models/trusted_network_groups.rb +2 -1
  49. data/lib/fog/compute/ecloud/models/users.rb +2 -1
  50. data/lib/fog/compute/ecloud/models/virtual_machine_assigned_ips.rb +5 -4
  51. data/lib/fog/compute/ecloud/requests/get_admin_organization.rb +4 -2
  52. data/lib/fog/compute/ecloud/requests/get_compute_pool.rb +4 -2
  53. data/lib/fog/compute/ecloud/requests/get_environment.rb +5 -3
  54. data/lib/fog/compute/ecloud/requests/get_ip_address.rb +5 -3
  55. data/lib/fog/compute/ecloud/requests/get_network.rb +4 -2
  56. data/lib/fog/compute/ecloud/requests/get_operating_system.rb +5 -3
  57. data/lib/fog/compute/ecloud/requests/get_ssh_key.rb +3 -1
  58. data/lib/fog/compute/ecloud/requests/get_template.rb +5 -3
  59. data/lib/fog/compute/ecloud/requests/ssh_key_edit.rb +2 -1
  60. data/lib/fog/ecloud/version.rb +1 -1
  61. data/tests/compute/livespec/auth_tests.rb +101 -0
  62. data/tests/compute/models/ssh_key_tests.rb +12 -11
  63. metadata +4 -2
data/Rakefile CHANGED
@@ -8,11 +8,13 @@ Rake::TestTask.new do |t|
8
8
  end
9
9
 
10
10
  namespace :test do
11
- mock = ENV['FOG_MOCK'] || 'true'
12
- task :travis do
13
- sh("export FOG_MOCK=#{mock} && bundle exec shindont")
11
+ task :mock do
12
+ sh("export FOG_MOCK=true && bundle exec shindont -livespec")
13
+ end
14
+ task :livespec do
15
+ sh("export FOG_MOCK=false && bundle exec shindont +livespec")
14
16
  end
15
17
  end
16
18
 
17
19
  desc 'Default Task'
18
- task :default => [ :test, 'test:travis' ]
20
+ task :default => [ :test, 'test:mock', 'test:livespec' ]
@@ -1,5 +1,6 @@
1
1
  require File.expand_path("../ecloud/models/model", __FILE__)
2
2
  require File.expand_path("../ecloud/models/collection", __FILE__)
3
+ require File.expand_path("../ecloud/errors", __FILE__)
3
4
 
4
5
  module Fog
5
6
  module Compute
@@ -268,6 +269,9 @@ module Fog
268
269
 
269
270
  class Real
270
271
  include Shared
272
+ include Errors
273
+
274
+ class Fog::Compute::Ecloud::ServiceError < Fog::Ecloud::Errors::ServiceError; end
271
275
 
272
276
  class << self
273
277
  def basic_request(name, expects = [200], method = :get, headers = {}, body = "")
@@ -335,7 +339,13 @@ module Fog
335
339
  unless params[:body].nil? || params[:body].empty?
336
340
  options.merge!(:body => params[:body])
337
341
  end
338
- response = @connections[host_url].request(options)
342
+
343
+ begin
344
+ response = @connections[host_url].request(options)
345
+ rescue Excon::Errors::Error => error
346
+ raise ServiceError.slurp(error)
347
+ end
348
+
339
349
  # Parse the response body into a hash
340
350
  unless response.body.empty?
341
351
  if params[:parse]
@@ -387,7 +397,7 @@ module Fog
387
397
  end
388
398
 
389
399
  def cloud_api_signature(params)
390
- verb = params[:method].upcase
400
+ verb = params[:method].to_s.upcase
391
401
  headers = params[:headers]
392
402
  path = params[:uri].path
393
403
  canonicalized_headers = canonicalize_headers(headers)
@@ -426,6 +436,9 @@ module Fog
426
436
 
427
437
  class Mock
428
438
  include Shared
439
+ include Errors
440
+
441
+ class Fog::Compute::Ecloud::ServiceError < Fog::Ecloud::Errors::ServiceError; end
429
442
 
430
443
  def self.data
431
444
  @data ||= Hash.new do |hash, key|
@@ -828,7 +841,9 @@ module Fog
828
841
 
829
842
  response = Excon::Response.new(:body => body, :headers => headers, :status => status)
830
843
  if params.key?(:expects) && ![*params[:expects]].include?(response.status)
831
- raise(Excon::Errors.status_error(params, response))
844
+ e = Excon::Errors::NotFound.new("Expected([200]) <=> Actual(404 Not Found)", "404", response)
845
+ raise ServiceError.slurp(e)
846
+
832
847
  else response
833
848
  end
834
849
  end
@@ -0,0 +1,91 @@
1
+ module Fog
2
+ module Ecloud
3
+ # Custom errors specific to our implementation
4
+ module Errors
5
+ # The parent class for all errors in the Fog::Compute::Ecloud module.
6
+ class ServiceError < Fog::Errors::Error
7
+ # @!attribute [r] response_data
8
+ # @return [string] the response from the HTTP request
9
+
10
+ # @!attribute [r] status_code
11
+ # @return [Integer] the HTTP status code returned
12
+ attr_reader :response_data, :status_code, :minor_error_code
13
+
14
+ # Make the HTTP status code pretty
15
+ #
16
+ # @return [String] the cleaned up status code
17
+ def to_s
18
+ status = status_code ? "HTTP #{status_code}" : "HTTP <Unknown>"
19
+ minor_code = minor_error_code ? minor_error_code : "Unknown"
20
+ "[#{status} - #{minor_code}] #{super}"
21
+ end
22
+
23
+ # Parse the response from the HTTP request to create a user friendly
24
+ # message, including HTTP response code and error message (if any)
25
+ #
26
+ # @param [Object] error the error object from the rescue block
27
+ #
28
+ # @return [Object] the new error object
29
+ def self.slurp(error)
30
+ data = nil
31
+ message = nil
32
+ status_code = nil
33
+ minor_code = nil
34
+
35
+ if error.response
36
+ status_code = error.response.status
37
+ unless error.response.body.empty?
38
+ begin
39
+ document = Fog::ToHashDocument.new
40
+ parser = Nokogiri::XML::SAX::PushParser.new(document)
41
+ parser << error.response.body
42
+ parser.finish
43
+
44
+ data = document.body
45
+
46
+ message = extract_message(data)
47
+ minor_code = extract_minor_code(data)
48
+
49
+ rescue => e
50
+ Fog::Logger.warning("Received exception '#{e}' while decoding: #{error.response.body}")
51
+ message = error.response.body
52
+ data = error.response.body
53
+ end
54
+ end
55
+ end
56
+
57
+ new_error = super(error, message)
58
+ new_error.instance_variable_set(:@response_data, data)
59
+ new_error.instance_variable_set(:@status_code, status_code)
60
+ new_error.instance_variable_set(:@minor_error_code, minor_code)
61
+ new_error
62
+ end
63
+
64
+ # Parse the response body for an error message
65
+ #
66
+ # @param [Hash] data the decoded XML response
67
+ #
68
+ # @return [String] the error message, if found, otherwise the raw data
69
+ def self.extract_message(data)
70
+ if data.is_a?(Hash)
71
+ message = data[:message]
72
+ end
73
+ message || data.inspect
74
+ end
75
+
76
+ # Parse the response body for the minor error code
77
+ #
78
+ # @param [Hash] data the decoded XML response
79
+ #
80
+ # @return [String] the error minor error code, if found, otherwise nil
81
+ def self.extract_minor_code(data)
82
+ minor_code = nil
83
+ if data.is_a?(Hash)
84
+ minor_code = data[:minorErrorCode]
85
+ end
86
+ minor_code
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -12,7 +12,8 @@ module Fog
12
12
  if data = service.get_admin_organization(uri)
13
13
  new(data.body)
14
14
  end
15
- rescue Fog::Errors::NotFound
15
+ rescue ServiceError => e
16
+ raise e unless e.status_code == 404
16
17
  nil
17
18
  end
18
19
  end
@@ -17,7 +17,8 @@ module Fog
17
17
  if data = service.get_api_key(uri)
18
18
  new(data.body)
19
19
  end
20
- rescue Fog::Errors::NotFound
20
+ rescue ServiceError => e
21
+ raise e unless e.status_code == 404
21
22
  nil
22
23
  end
23
24
  end
@@ -25,7 +25,8 @@ module Fog
25
25
  if data = service.get_association(uri)
26
26
  new(data.body)
27
27
  end
28
- rescue Fog::Errors::NotFound
28
+ rescue ServiceError => e
29
+ raise e unless e.status_code == 404
29
30
  nil
30
31
  end
31
32
  end
@@ -17,7 +17,8 @@ module Fog
17
17
  if data = service.get_authentication_level(uri)
18
18
  new(data.body)
19
19
  end
20
- rescue Fog::Errors::NotFound
20
+ rescue ServiceError => e
21
+ raise e unless e.status_code == 404
21
22
  nil
22
23
  end
23
24
  end
@@ -17,7 +17,8 @@ module Fog
17
17
  if data = service.get_backup_internet_service(uri)
18
18
  new(data.body)
19
19
  end
20
- rescue Fog::Errors::NotFound
20
+ rescue ServiceError => e
21
+ raise e unless e.status_code == 404
21
22
  nil
22
23
  end
23
24
 
@@ -9,7 +9,7 @@ module Fog
9
9
  model Fog::Compute::Ecloud::CatalogItem
10
10
 
11
11
  def all
12
- data = service.get_catalog(href).body#[:Locations][:Location][:Catalog][:CatalogEntry]
12
+ data = service.get_catalog(href).body # [:Locations][:Location][:Catalog][:CatalogEntry]
13
13
  if data[:Locations][:Location].is_a?(Hash)
14
14
  data = [] if data[:Locations][:Location][:Catalog].is_a?(String) && data[:Locations][:Location][:Catalog].empty?
15
15
  load(data)
@@ -30,7 +30,8 @@ module Fog
30
30
  if data = service.get_catalog_item(uri)
31
31
  new(data.body)
32
32
  end
33
- rescue Fog::Errors::NotFound
33
+ rescue ServiceError => e
34
+ raise e unless e.status_code == 404
34
35
  nil
35
36
  end
36
37
  end
@@ -17,7 +17,8 @@ module Fog
17
17
  if data = service.get_catalog_configuration(uri)
18
18
  new(data.body)
19
19
  end
20
- rescue Fog::Errors::NotFound
20
+ rescue ServiceError => e
21
+ raise e unless e.status_code == 404
21
22
  nil
22
23
  end
23
24
  end
@@ -20,7 +20,8 @@ module Fog
20
20
  if data = service.get_compute_pool(uri)
21
21
  new(data.body)
22
22
  end
23
- rescue Fog::Errors::NotFound
23
+ rescue ServiceError => e
24
+ raise e unless e.status_code == 404
24
25
  nil
25
26
  end
26
27
 
@@ -17,7 +17,8 @@ module Fog
17
17
  if data = service.get_cpu_usage_detail(uri)
18
18
  new(data.body)
19
19
  end
20
- rescue Fog::Errors::NotFound
20
+ rescue ServiceError => e
21
+ raise e unless e.status_code == 404
21
22
  nil
22
23
  end
23
24
  end
@@ -10,14 +10,15 @@ module Fog
10
10
 
11
11
  def all
12
12
  data = service.get_detached_disks(href).body[:DetachedDisk]
13
- data = [] if data.nil?
13
+ data = [] if data.nil?
14
14
  load(data)
15
15
  end
16
16
 
17
17
  def get(uri)
18
18
  data = service.get_detached_disk(uri).body
19
19
  new(data)
20
- rescue Fog::Errors::NotFound
20
+ rescue ServiceError => e
21
+ raise e unless e.status_code == 404
21
22
  nil
22
23
  end
23
24
  end
@@ -38,7 +38,8 @@ module Fog
38
38
  if data = service.get_environment(uri)
39
39
  new(data.body)
40
40
  end
41
- rescue Fog::Errors::NotFound
41
+ rescue ServiceError => e
42
+ raise e unless e.status_code == 404
42
43
  nil
43
44
  end
44
45
 
@@ -18,7 +18,8 @@ module Fog
18
18
  if data = service.get_firewall_acl(uri)
19
19
  new(data.body)
20
20
  end
21
- rescue Fog::Errors::NotFound
21
+ rescue ServiceError => e
22
+ raise e unless e.status_code == 404
22
23
  nil
23
24
  end
24
25
  end
@@ -29,7 +29,8 @@ module Fog
29
29
  else
30
30
  new(data)
31
31
  end
32
- rescue Excon::Errors::NotFound
32
+ rescue ServiceError => e
33
+ raise e unless e.status_code == 404
33
34
  nil
34
35
  end
35
36
  end
@@ -17,7 +17,8 @@ module Fog
17
17
  if data = service.get_guest_process(uri)
18
18
  new(data.body)
19
19
  end
20
- rescue Fog::Errors::NotFound
20
+ rescue ServiceError => e
21
+ raise e unless e.status_code == 404
21
22
  nil
22
23
  end
23
24
  end
@@ -17,7 +17,8 @@ module Fog
17
17
  if data = service.get_hardware_configuration(uri)
18
18
  new(data.body)
19
19
  end
20
- rescue Fog::Errors::NotFound
20
+ rescue ServiceError => e
21
+ raise e unless e.status_code == 404
21
22
  nil
22
23
  end
23
24
  end
@@ -20,19 +20,20 @@ module Fog
20
20
  def get(uri)
21
21
  data = service.get_internet_service(uri).body
22
22
  new(data)
23
- rescue Fog::Errors::NotFound
23
+ rescue ServiceError => e
24
+ raise e unless e.status_code == 404
24
25
  nil
25
26
  end
26
27
 
27
28
  def create(options)
28
29
  options[:uri] = "#{service.base_path}/internetServices/publicIps/#{public_ip_id}/action/createInternetService"
29
- options[:protocol] ||= "TCP"
30
- options[:enabled] ||= true
31
- options[:description] ||= ""
32
- options[:persistence] ||= {}
30
+ options[:protocol] ||= "TCP"
31
+ options[:enabled] ||= true
32
+ options[:description] ||= ""
33
+ options[:persistence] ||= {}
33
34
  options[:persistence][:type] ||= "None"
34
35
  data = service.internet_service_create(options).body
35
- object = new(data)
36
+ new(data)
36
37
  end
37
38
 
38
39
  def public_ip_id
@@ -23,7 +23,8 @@ module Fog
23
23
  if data = service.get_ip_address(uri)
24
24
  new(data.body)
25
25
  end
26
- rescue Fog::Errors::NotFound
26
+ rescue ServiceError => e
27
+ raise e unless e.status_code == 404
27
28
  nil
28
29
  end
29
30
  end
@@ -17,7 +17,8 @@ module Fog
17
17
  if data = service.get_layout(uri)
18
18
  new(data.body)
19
19
  end
20
- rescue Fog::Errors::NotFound
20
+ rescue ServiceError => e
21
+ raise e unless e.status_code == 404
21
22
  nil
22
23
  end
23
24
  end
@@ -19,7 +19,8 @@ module Fog
19
19
  if data = service.get_location(uri)
20
20
  new(data.body)
21
21
  end
22
- rescue Fog::Errors::NotFound
22
+ rescue ServiceError => e
23
+ raise e unless e.status_code == 404
23
24
  nil
24
25
  end
25
26
  end
@@ -17,7 +17,8 @@ module Fog
17
17
  if data = service.get_login_banner(uri)
18
18
  new(data.body)
19
19
  end
20
- rescue Fog::Errors::NotFound
20
+ rescue ServiceError => e
21
+ raise e unless e.status_code == 404
21
22
  nil
22
23
  end
23
24
  end
@@ -17,7 +17,8 @@ module Fog
17
17
  if data = service.get_memory_usage_detail(uri)
18
18
  new(data.body)
19
19
  end
20
- rescue Fog::Errors::NotFound
20
+ rescue ServiceError => e
21
+ raise e unless e.status_code == 404
21
22
  nil
22
23
  end
23
24
  end
@@ -17,7 +17,8 @@ module Fog
17
17
  if data = service.get_monitor(uri)
18
18
  new(data.body)
19
19
  end
20
- rescue Fog::Errors::NotFound
20
+ rescue ServiceError => e
21
+ raise e unless e.status_code == 404
21
22
  nil
22
23
  end
23
24
 
@@ -9,7 +9,7 @@ module Fog
9
9
  model Fog::Compute::Ecloud::Network
10
10
 
11
11
  def all
12
- body = service.get_networks(self.href).body
12
+ body = service.get_networks(href).body
13
13
  body = body[:Networks] ? body[:Networks][:Network] : body[:Network]
14
14
  data = case body
15
15
  when NilClass then []
@@ -23,7 +23,8 @@ module Fog
23
23
  if data = service.get_network(uri)
24
24
  new(data.body)
25
25
  end
26
- rescue Fog::Errors::NotFound
26
+ rescue ServiceError => e
27
+ raise e unless e.status_code == 404
27
28
  nil
28
29
  end
29
30
  end