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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1048 -11
- data/Rakefile +6 -4
- data/lib/fog/compute/ecloud.rb +18 -3
- data/lib/fog/compute/ecloud/errors.rb +91 -0
- data/lib/fog/compute/ecloud/models/admin_organizations.rb +2 -1
- data/lib/fog/compute/ecloud/models/api_keys.rb +2 -1
- data/lib/fog/compute/ecloud/models/associations.rb +2 -1
- data/lib/fog/compute/ecloud/models/authentication_levels.rb +2 -1
- data/lib/fog/compute/ecloud/models/backup_internet_services.rb +2 -1
- data/lib/fog/compute/ecloud/models/catalog.rb +3 -2
- data/lib/fog/compute/ecloud/models/catalog_configurations.rb +2 -1
- data/lib/fog/compute/ecloud/models/compute_pools.rb +2 -1
- data/lib/fog/compute/ecloud/models/cpu_usage_detail_summary.rb +2 -1
- data/lib/fog/compute/ecloud/models/detached_disks.rb +3 -2
- data/lib/fog/compute/ecloud/models/environments.rb +2 -1
- data/lib/fog/compute/ecloud/models/firewall_acls.rb +2 -1
- data/lib/fog/compute/ecloud/models/groups.rb +2 -1
- data/lib/fog/compute/ecloud/models/guest_processes.rb +2 -1
- data/lib/fog/compute/ecloud/models/hardware_configurations.rb +2 -1
- data/lib/fog/compute/ecloud/models/internet_services.rb +7 -6
- data/lib/fog/compute/ecloud/models/ip_addresses.rb +2 -1
- data/lib/fog/compute/ecloud/models/layouts.rb +2 -1
- data/lib/fog/compute/ecloud/models/locations.rb +2 -1
- data/lib/fog/compute/ecloud/models/login_banners.rb +2 -1
- data/lib/fog/compute/ecloud/models/memory_usage_detail_summary.rb +2 -1
- data/lib/fog/compute/ecloud/models/monitors.rb +2 -1
- data/lib/fog/compute/ecloud/models/networks.rb +3 -2
- data/lib/fog/compute/ecloud/models/nodes.rb +3 -2
- data/lib/fog/compute/ecloud/models/operating_system_families.rb +2 -1
- data/lib/fog/compute/ecloud/models/operating_systems.rb +2 -1
- data/lib/fog/compute/ecloud/models/organizations.rb +2 -1
- data/lib/fog/compute/ecloud/models/password_complexity_rules.rb +2 -1
- data/lib/fog/compute/ecloud/models/physical_devices.rb +2 -1
- data/lib/fog/compute/ecloud/models/public_ips.rb +3 -2
- data/lib/fog/compute/ecloud/models/rnats.rb +2 -1
- data/lib/fog/compute/ecloud/models/roles.rb +2 -1
- data/lib/fog/compute/ecloud/models/rows.rb +2 -1
- data/lib/fog/compute/ecloud/models/server.rb +40 -41
- data/lib/fog/compute/ecloud/models/server_configuration_options.rb +2 -1
- data/lib/fog/compute/ecloud/models/servers.rb +10 -9
- data/lib/fog/compute/ecloud/models/ssh_keys.rb +3 -2
- data/lib/fog/compute/ecloud/models/storage_usage_detail_summary.rb +2 -1
- data/lib/fog/compute/ecloud/models/support_tickets.rb +2 -1
- data/lib/fog/compute/ecloud/models/tags.rb +2 -1
- data/lib/fog/compute/ecloud/models/tasks.rb +2 -1
- data/lib/fog/compute/ecloud/models/templates.rb +2 -1
- data/lib/fog/compute/ecloud/models/trusted_network_groups.rb +2 -1
- data/lib/fog/compute/ecloud/models/users.rb +2 -1
- data/lib/fog/compute/ecloud/models/virtual_machine_assigned_ips.rb +5 -4
- data/lib/fog/compute/ecloud/requests/get_admin_organization.rb +4 -2
- data/lib/fog/compute/ecloud/requests/get_compute_pool.rb +4 -2
- data/lib/fog/compute/ecloud/requests/get_environment.rb +5 -3
- data/lib/fog/compute/ecloud/requests/get_ip_address.rb +5 -3
- data/lib/fog/compute/ecloud/requests/get_network.rb +4 -2
- data/lib/fog/compute/ecloud/requests/get_operating_system.rb +5 -3
- data/lib/fog/compute/ecloud/requests/get_ssh_key.rb +3 -1
- data/lib/fog/compute/ecloud/requests/get_template.rb +5 -3
- data/lib/fog/compute/ecloud/requests/ssh_key_edit.rb +2 -1
- data/lib/fog/ecloud/version.rb +1 -1
- data/tests/compute/livespec/auth_tests.rb +101 -0
- data/tests/compute/models/ssh_key_tests.rb +12 -11
- 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
|
12
|
-
|
13
|
-
|
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:
|
20
|
+
task :default => [ :test, 'test:mock', 'test:livespec' ]
|
data/lib/fog/compute/ecloud.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
@@ -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
|
33
|
+
rescue ServiceError => e
|
34
|
+
raise e unless e.status_code == 404
|
34
35
|
nil
|
35
36
|
end
|
36
37
|
end
|
@@ -10,14 +10,15 @@ module Fog
|
|
10
10
|
|
11
11
|
def all
|
12
12
|
data = service.get_detached_disks(href).body[:DetachedDisk]
|
13
|
-
|
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
|
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
|
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]
|
30
|
-
options[:enabled]
|
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
|
-
|
36
|
+
new(data)
|
36
37
|
end
|
37
38
|
|
38
39
|
def public_ip_id
|
@@ -9,7 +9,7 @@ module Fog
|
|
9
9
|
model Fog::Compute::Ecloud::Network
|
10
10
|
|
11
11
|
def all
|
12
|
-
body = service.get_networks(
|
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
|
26
|
+
rescue ServiceError => e
|
27
|
+
raise e unless e.status_code == 404
|
27
28
|
nil
|
28
29
|
end
|
29
30
|
end
|