fog-core 1.24.0 → 1.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/.rubocop.yml +20 -0
- data/changelog.md +17 -0
- data/fog-core.gemspec +2 -1
- data/lib/fog/account.rb +3 -5
- data/lib/fog/billing.rb +3 -4
- data/lib/fog/cdn.rb +3 -5
- data/lib/fog/compute.rb +17 -20
- data/lib/fog/compute/models/server.rb +21 -26
- data/lib/fog/core.rb +61 -60
- data/lib/fog/core/association.rb +15 -0
- data/lib/fog/core/associations/default.rb +21 -3
- data/lib/fog/core/associations/many_identities.rb +8 -2
- data/lib/fog/core/associations/many_models.rb +7 -2
- data/lib/fog/core/associations/one_identity.rb +6 -1
- data/lib/fog/core/associations/one_model.rb +5 -1
- data/lib/fog/core/attributes.rb +41 -44
- data/lib/fog/core/attributes/array.rb +5 -1
- data/lib/fog/core/attributes/boolean.rb +5 -1
- data/lib/fog/core/attributes/default.rb +12 -2
- data/lib/fog/core/attributes/float.rb +5 -1
- data/lib/fog/core/attributes/integer.rb +5 -1
- data/lib/fog/core/attributes/string.rb +5 -1
- data/lib/fog/core/attributes/time.rb +5 -1
- data/lib/fog/core/attributes/timestamp.rb +5 -1
- data/lib/fog/core/collection.rb +22 -27
- data/lib/fog/core/connection.rb +5 -6
- data/lib/fog/core/credentials.rb +7 -7
- data/lib/fog/core/current_machine.rb +10 -8
- data/lib/fog/core/deprecated_connection_accessors.rb +0 -1
- data/lib/fog/core/deprecation.rb +0 -2
- data/lib/fog/core/errors.rb +3 -5
- data/lib/fog/core/hmac.rb +4 -6
- data/lib/fog/core/logger.rb +10 -11
- data/lib/fog/core/mock.rb +19 -25
- data/lib/fog/core/model.rb +9 -20
- data/lib/fog/core/provider.rb +6 -9
- data/lib/fog/core/scp.rb +14 -24
- data/lib/fog/core/service.rb +28 -31
- data/lib/fog/core/ssh.rb +16 -24
- data/lib/fog/core/stringify_keys.rb +7 -9
- data/lib/fog/core/time.rb +5 -7
- data/lib/fog/core/utils.rb +24 -20
- data/lib/fog/core/uuid.rb +2 -3
- data/lib/fog/core/version.rb +3 -1
- data/lib/fog/core/wait_for.rb +2 -2
- data/lib/fog/core/wait_for_defaults.rb +13 -10
- data/lib/fog/core/whitelist_keys.rb +1 -1
- data/lib/fog/dns.rb +6 -8
- data/lib/fog/identity.rb +5 -6
- data/lib/fog/image.rb +3 -5
- data/lib/fog/metering.rb +3 -6
- data/lib/fog/monitoring.rb +3 -5
- data/lib/fog/network.rb +4 -6
- data/lib/fog/orchestration.rb +3 -5
- data/lib/fog/schema/data_validator.rb +17 -22
- data/lib/fog/storage.rb +22 -16
- data/lib/fog/support.rb +3 -6
- data/lib/fog/test_helpers.rb +10 -10
- data/lib/fog/test_helpers/collection_helper.rb +23 -43
- data/lib/fog/test_helpers/compute/flavors_helper.rb +4 -10
- data/lib/fog/test_helpers/compute/server_helper.rb +3 -9
- data/lib/fog/test_helpers/compute/servers_helper.rb +0 -4
- data/lib/fog/test_helpers/formats_helper.rb +13 -14
- data/lib/fog/test_helpers/helper.rb +9 -4
- data/lib/fog/test_helpers/mock_helper.rb +92 -94
- data/lib/fog/test_helpers/model_helper.rb +7 -15
- data/lib/fog/test_helpers/responds_to_helper.rb +1 -3
- data/lib/fog/test_helpers/succeeds_helper.rb +1 -3
- data/lib/fog/volume.rb +3 -6
- data/lib/fog/vpn.rb +3 -5
- data/lib/tasks/test_task.rb +2 -6
- data/spec/compute_spec.rb +11 -13
- data/spec/connection_spec.rb +24 -14
- data/spec/credentials_spec.rb +23 -23
- data/spec/current_machine_spec.rb +6 -6
- data/spec/fake_app/fake_service.rb +18 -0
- data/spec/fake_app/models/collection.rb +5 -0
- data/spec/fake_app/models/model.rb +2 -0
- data/spec/fake_app/requests/request.rb +11 -0
- data/spec/fog_attribute_spec.rb +178 -136
- data/spec/identity_spec.rb +11 -13
- data/spec/mocking_spec.rb +7 -8
- data/spec/service_spec.rb +21 -7
- data/spec/spec_helper.rb +14 -8
- data/spec/storage_spec.rb +25 -13
- data/spec/test_helpers/formats_helper_spec.rb +52 -52
- data/spec/test_helpers/schema_validator_spec.rb +45 -45
- data/spec/timeout_spec.rb +1 -2
- data/spec/utils_spec.rb +2 -2
- data/spec/uuid_spec.rb +1 -1
- data/spec/wait_for_spec.rb +7 -4
- metadata +57 -33
data/lib/fog/core/time.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require "time"
|
2
2
|
|
3
3
|
module Fog
|
4
4
|
class Time < ::Time
|
5
|
-
|
6
|
-
|
7
|
-
MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
5
|
+
DAYS = %w(Sun Mon Tue Wed Thu Fri Sat)
|
6
|
+
MONTHS = %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
|
8
7
|
|
9
8
|
def self.now
|
10
9
|
at((::Time.now - offset).to_i)
|
@@ -21,12 +20,11 @@ module Fog
|
|
21
20
|
end
|
22
21
|
|
23
22
|
def to_date_header
|
24
|
-
|
23
|
+
utc.strftime("#{DAYS[utc.wday]}, %d #{MONTHS[utc.month - 1]} %Y %H:%M:%S +0000")
|
25
24
|
end
|
26
25
|
|
27
26
|
def to_iso8601_basic
|
28
|
-
|
27
|
+
utc.strftime("%Y%m%dT%H%M%SZ")
|
29
28
|
end
|
30
|
-
|
31
29
|
end
|
32
30
|
end
|
data/lib/fog/core/utils.rb
CHANGED
@@ -1,24 +1,28 @@
|
|
1
|
-
module Fog
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
1
|
+
module Fog
|
2
|
+
module Core
|
3
|
+
module Utils
|
4
|
+
# This helper prepares a Hash of settings for passing into {Fog::Service.new}.
|
5
|
+
#
|
6
|
+
# The only special consideration is if +:header+ key is passed in the contents are unchanged. This
|
7
|
+
# allows the headers to be passed through to requests to customise HTTP headers without them being
|
8
|
+
# broken by the +#to_sym+ calls.
|
9
|
+
#
|
10
|
+
# @param [Hash] settings The String based Hash to prepare
|
11
|
+
# @option settings [Hash] :headers Passed to the underlying {Fog::Core::Connection} unchanged
|
12
|
+
# @return [Hash]
|
13
|
+
#
|
14
|
+
def self.prepare_service_settings(settings)
|
15
|
+
if settings.is_a? Hash
|
16
|
+
copy = []
|
17
|
+
settings.each do |key, value|
|
18
|
+
obj = ![:headers].include?(key) ? prepare_service_settings(value) : value
|
19
|
+
copy.push(key.to_sym, obj)
|
20
|
+
end
|
21
|
+
Hash[*copy]
|
22
|
+
else
|
23
|
+
settings
|
24
|
+
end
|
18
25
|
end
|
19
|
-
Hash[*copy]
|
20
|
-
else
|
21
|
-
settings
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
data/lib/fog/core/uuid.rb
CHANGED
data/lib/fog/core/version.rb
CHANGED
data/lib/fog/core/wait_for.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Fog
|
2
|
-
def self.wait_for(timeout=Fog.timeout, interval=Fog.interval, &
|
2
|
+
def self.wait_for(timeout = Fog.timeout, interval = Fog.interval, &_block)
|
3
3
|
duration = 0
|
4
4
|
start = Time.now
|
5
5
|
retries = 0
|
@@ -8,7 +8,7 @@ module Fog
|
|
8
8
|
duration = Time.now - start
|
9
9
|
end
|
10
10
|
if duration > timeout
|
11
|
-
raise Errors::TimeoutError
|
11
|
+
raise Errors::TimeoutError, "The specified wait_for timeout (#{timeout} seconds) was exceeded"
|
12
12
|
else
|
13
13
|
{ :duration => duration }
|
14
14
|
end
|
@@ -1,31 +1,34 @@
|
|
1
1
|
module Fog
|
2
|
-
@interval = lambda { |retries| [2
|
3
|
-
|
4
|
-
|
2
|
+
@interval = lambda { |retries| [2**(retries - 1), @max_interval].min }
|
3
|
+
|
4
|
+
class << self
|
5
|
+
attr_reader :interval
|
5
6
|
end
|
6
7
|
|
7
8
|
def self.interval=(interval)
|
8
|
-
if interval.
|
9
|
+
if interval.is_a?(Proc)
|
9
10
|
raise ArgumentError, "interval proc must return a positive" unless interval.call(1) >= 0
|
10
11
|
else
|
11
12
|
raise ArgumentError, "interval must be non-negative" unless interval >= 0
|
12
13
|
end
|
13
14
|
@interval = interval
|
14
15
|
end
|
15
|
-
|
16
|
+
|
16
17
|
@timeout = 600
|
17
|
-
|
18
|
-
|
18
|
+
|
19
|
+
class << self
|
20
|
+
attr_reader :timeout
|
19
21
|
end
|
20
22
|
|
21
23
|
def self.timeout=(timeout)
|
22
24
|
raise ArgumentError, "timeout must be non-negative" unless timeout >= 0
|
23
25
|
@timeout = timeout
|
24
26
|
end
|
25
|
-
|
27
|
+
|
26
28
|
@max_interval = 60
|
27
|
-
|
28
|
-
|
29
|
+
|
30
|
+
class << self
|
31
|
+
attr_reader :max_interval
|
29
32
|
end
|
30
33
|
|
31
34
|
def self.max_interval=(interval)
|
data/lib/fog/dns.rb
CHANGED
@@ -1,26 +1,25 @@
|
|
1
1
|
module Fog
|
2
2
|
module DNS
|
3
|
-
|
4
3
|
def self.[](provider)
|
5
|
-
|
4
|
+
new(:provider => provider)
|
6
5
|
end
|
7
6
|
|
8
7
|
def self.new(attributes)
|
9
8
|
attributes = attributes.dup # prevent delete from having side effects
|
10
9
|
case provider = attributes.delete(:provider).to_s.downcase.to_sym
|
11
10
|
when :stormondemand
|
12
|
-
require
|
11
|
+
require "fog/storm_on_demand/dns"
|
13
12
|
Fog::DNS::StormOnDemand.new(attributes)
|
14
13
|
else
|
15
|
-
if
|
14
|
+
if providers.include?(provider)
|
16
15
|
require "fog/#{provider}/dns"
|
17
16
|
begin
|
18
17
|
Fog::DNS.const_get(Fog.providers[provider])
|
19
18
|
rescue
|
20
|
-
Fog
|
19
|
+
Fog.const_get(Fog.providers[provider])::DNS
|
21
20
|
end.new(attributes)
|
22
21
|
else
|
23
|
-
raise ArgumentError
|
22
|
+
raise ArgumentError, "#{provider} is not a recognized dns provider"
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
@@ -31,7 +30,7 @@ module Fog
|
|
31
30
|
|
32
31
|
def self.zones
|
33
32
|
zones = []
|
34
|
-
|
33
|
+
providers.each do |provider|
|
35
34
|
begin
|
36
35
|
zones.concat(self[provider].zones)
|
37
36
|
rescue # ignore any missing credentials/etc
|
@@ -39,6 +38,5 @@ module Fog
|
|
39
38
|
end
|
40
39
|
zones
|
41
40
|
end
|
42
|
-
|
43
41
|
end
|
44
42
|
end
|
data/lib/fog/identity.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module Fog
|
2
2
|
module Identity
|
3
|
-
|
4
3
|
def self.[](provider)
|
5
|
-
|
4
|
+
new(:provider => provider)
|
6
5
|
end
|
7
6
|
|
8
7
|
def self.new(attributes)
|
@@ -10,15 +9,15 @@ module Fog
|
|
10
9
|
provider = attributes.delete(:provider).to_s.downcase.to_sym
|
11
10
|
|
12
11
|
unless providers.include?(provider)
|
13
|
-
raise ArgumentError
|
12
|
+
raise ArgumentError, "#{provider} has no identity service"
|
14
13
|
end
|
15
14
|
|
16
15
|
require "fog/#{provider}/identity"
|
17
16
|
begin
|
18
|
-
Fog::Identity.const_get(Fog.providers[provider])
|
17
|
+
Fog::Identity.const_get(Fog.providers[provider])
|
19
18
|
rescue
|
20
|
-
Fog
|
21
|
-
end
|
19
|
+
Fog.const_get(Fog.providers[provider])::Identity
|
20
|
+
end.new(attributes)
|
22
21
|
end
|
23
22
|
|
24
23
|
def self.providers
|
data/lib/fog/image.rb
CHANGED
@@ -1,23 +1,21 @@
|
|
1
1
|
module Fog
|
2
2
|
module Image
|
3
|
-
|
4
3
|
def self.[](provider)
|
5
|
-
|
4
|
+
new(:provider => provider)
|
6
5
|
end
|
7
6
|
|
8
7
|
def self.new(attributes)
|
9
8
|
attributes = attributes.dup # Prevent delete from having side effects
|
10
9
|
provider = attributes.delete(:provider).to_s.downcase.to_sym
|
11
|
-
if
|
10
|
+
if providers.include?(provider)
|
12
11
|
require "fog/#{provider}/image"
|
13
12
|
return Fog::Image.const_get(Fog.providers[provider]).new(attributes)
|
14
13
|
end
|
15
|
-
raise ArgumentError
|
14
|
+
raise ArgumentError, "#{provider} has no image service"
|
16
15
|
end
|
17
16
|
|
18
17
|
def self.providers
|
19
18
|
Fog.services[:image]
|
20
19
|
end
|
21
|
-
|
22
20
|
end
|
23
21
|
end
|
data/lib/fog/metering.rb
CHANGED
@@ -1,25 +1,22 @@
|
|
1
1
|
module Fog
|
2
2
|
module Metering
|
3
|
-
|
4
3
|
def self.[](provider)
|
5
|
-
|
4
|
+
new(:provider => provider)
|
6
5
|
end
|
7
6
|
|
8
7
|
def self.new(attributes)
|
9
8
|
attributes = attributes.dup # Prevent delete from having side effects
|
10
9
|
provider = attributes.delete(:provider).to_s.downcase.to_sym
|
11
|
-
if
|
10
|
+
if providers.include?(provider)
|
12
11
|
require "fog/#{provider}/metering"
|
13
12
|
return Fog::Metering.const_get(Fog.providers[provider]).new(attributes)
|
14
13
|
end
|
15
14
|
|
16
|
-
raise ArgumentError
|
15
|
+
raise ArgumentError, "#{provider} has no identity service"
|
17
16
|
end
|
18
17
|
|
19
18
|
def self.providers
|
20
19
|
Fog.services[:metering]
|
21
20
|
end
|
22
|
-
|
23
21
|
end
|
24
22
|
end
|
25
|
-
|
data/lib/fog/monitoring.rb
CHANGED
@@ -1,24 +1,22 @@
|
|
1
1
|
module Fog
|
2
2
|
module Monitoring
|
3
|
-
|
4
3
|
def self.[](provider)
|
5
|
-
|
4
|
+
new(:provider => provider)
|
6
5
|
end
|
7
6
|
|
8
7
|
def self.new(attributes)
|
9
8
|
attributes = attributes.dup
|
10
9
|
provider = attributes.delete(:provider).to_s.downcase.to_sym
|
11
10
|
if provider == :stormondemand
|
12
|
-
require
|
11
|
+
require "fog/storm_on_demand/billing"
|
13
12
|
Fog::Monitoring::StormOnDemand.new(attributes)
|
14
13
|
else
|
15
|
-
raise ArgumentError
|
14
|
+
raise ArgumentError, "#{provider} has no monitoring service"
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
19
18
|
def self.providers
|
20
19
|
Fog.services[:monitoring]
|
21
20
|
end
|
22
|
-
|
23
21
|
end
|
24
22
|
end
|
data/lib/fog/network.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module Fog
|
2
2
|
module Network
|
3
|
-
|
4
3
|
def self.[](provider)
|
5
|
-
|
4
|
+
new(:provider => provider)
|
6
5
|
end
|
7
6
|
|
8
7
|
def self.new(attributes)
|
@@ -12,17 +11,16 @@ module Fog
|
|
12
11
|
if provider == :stormondemand
|
13
12
|
require "fog/storm_on_demand/network"
|
14
13
|
return Fog::Network::StormOnDemand.new(attributes)
|
15
|
-
elsif
|
14
|
+
elsif providers.include?(provider)
|
16
15
|
require "fog/#{provider}/network"
|
17
16
|
return Fog::Network.const_get(Fog.providers[provider]).new(attributes)
|
18
17
|
end
|
19
18
|
|
20
|
-
raise ArgumentError
|
19
|
+
raise ArgumentError, "#{provider} has no network service"
|
21
20
|
end
|
22
21
|
|
23
22
|
def self.providers
|
24
23
|
Fog.services[:network]
|
25
24
|
end
|
26
|
-
|
27
25
|
end
|
28
|
-
end
|
26
|
+
end
|
data/lib/fog/orchestration.rb
CHANGED
@@ -1,25 +1,23 @@
|
|
1
1
|
module Fog
|
2
2
|
module Orchestration
|
3
|
-
|
4
3
|
def self.[](provider)
|
5
|
-
|
4
|
+
new(:provider => provider)
|
6
5
|
end
|
7
6
|
|
8
7
|
def self.new(attributes)
|
9
8
|
attributes = attributes.dup # Prevent delete from having side effects
|
10
9
|
provider = attributes.delete(:provider).to_s.downcase.to_sym
|
11
10
|
|
12
|
-
if
|
11
|
+
if providers.include?(provider)
|
13
12
|
require "fog/#{provider}/network"
|
14
13
|
return Fog::Orchestration.const_get(Fog.providers[provider]).new(attributes)
|
15
14
|
end
|
16
15
|
|
17
|
-
raise ArgumentError
|
16
|
+
raise ArgumentError, "#{provider} has no orchestration service"
|
18
17
|
end
|
19
18
|
|
20
19
|
def self.providers
|
21
20
|
Fog.services[:orchestration]
|
22
21
|
end
|
23
|
-
|
24
22
|
end
|
25
23
|
end
|
@@ -61,6 +61,10 @@ module Fog
|
|
61
61
|
# }
|
62
62
|
#
|
63
63
|
class DataValidator
|
64
|
+
# This returns the last message set by the validator
|
65
|
+
#
|
66
|
+
# @return [String]
|
67
|
+
attr_reader :message
|
64
68
|
|
65
69
|
def initialize
|
66
70
|
@message = nil
|
@@ -89,14 +93,7 @@ module Fog
|
|
89
93
|
valid
|
90
94
|
end
|
91
95
|
|
92
|
-
|
93
|
-
#
|
94
|
-
# @return [String]
|
95
|
-
def message
|
96
|
-
@message
|
97
|
-
end
|
98
|
-
|
99
|
-
private
|
96
|
+
private
|
100
97
|
|
101
98
|
# This contains a slightly modified version of the Hashidator gem
|
102
99
|
# but unfortunately the gem does not cope with Array schemas.
|
@@ -109,26 +106,24 @@ module Fog
|
|
109
106
|
case validator
|
110
107
|
when Array
|
111
108
|
return false if value.is_a?(Hash)
|
112
|
-
value.respond_to?(:all?) && value.all? {|x| validate_value(validator[0], x, options)}
|
109
|
+
value.respond_to?(:all?) && value.all? { |x| validate_value(validator[0], x, options) }
|
113
110
|
when Symbol
|
114
111
|
value.respond_to? validator
|
115
112
|
when Hash
|
116
113
|
return false if value.is_a?(Array)
|
117
114
|
|
118
115
|
# When being strict values not specified in the schema are fails
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end
|
116
|
+
# Validator is empty but values are not
|
117
|
+
return false if !options[:allow_extra_keys] &&
|
118
|
+
value.respond_to?(:empty?) &&
|
119
|
+
!value.empty? &&
|
120
|
+
validator.empty?
|
125
121
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
end
|
122
|
+
# Validator has rules left but no more values
|
123
|
+
return false if !options[:allow_optional_rules] &&
|
124
|
+
value.respond_to?(:empty?) &&
|
125
|
+
value.empty? &&
|
126
|
+
!validator.empty?
|
132
127
|
|
133
128
|
validator.all? do |key, sub_validator|
|
134
129
|
Fog::Logger.write :debug, "[blue][DEBUG] #{key.inspect} against #{sub_validator.inspect}[/]\n"
|
@@ -138,7 +133,7 @@ module Fog
|
|
138
133
|
result = validator == value
|
139
134
|
result = validator === value unless result
|
140
135
|
# Repeat unless we have a Boolean already
|
141
|
-
unless
|
136
|
+
unless result.is_a?(TrueClass) || result.is_a?(FalseClass)
|
142
137
|
result = validate_value(result, value, options)
|
143
138
|
end
|
144
139
|
if result
|