fog-core 1.24.0 → 1.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +5 -13
  2. data/.rubocop.yml +20 -0
  3. data/changelog.md +17 -0
  4. data/fog-core.gemspec +2 -1
  5. data/lib/fog/account.rb +3 -5
  6. data/lib/fog/billing.rb +3 -4
  7. data/lib/fog/cdn.rb +3 -5
  8. data/lib/fog/compute.rb +17 -20
  9. data/lib/fog/compute/models/server.rb +21 -26
  10. data/lib/fog/core.rb +61 -60
  11. data/lib/fog/core/association.rb +15 -0
  12. data/lib/fog/core/associations/default.rb +21 -3
  13. data/lib/fog/core/associations/many_identities.rb +8 -2
  14. data/lib/fog/core/associations/many_models.rb +7 -2
  15. data/lib/fog/core/associations/one_identity.rb +6 -1
  16. data/lib/fog/core/associations/one_model.rb +5 -1
  17. data/lib/fog/core/attributes.rb +41 -44
  18. data/lib/fog/core/attributes/array.rb +5 -1
  19. data/lib/fog/core/attributes/boolean.rb +5 -1
  20. data/lib/fog/core/attributes/default.rb +12 -2
  21. data/lib/fog/core/attributes/float.rb +5 -1
  22. data/lib/fog/core/attributes/integer.rb +5 -1
  23. data/lib/fog/core/attributes/string.rb +5 -1
  24. data/lib/fog/core/attributes/time.rb +5 -1
  25. data/lib/fog/core/attributes/timestamp.rb +5 -1
  26. data/lib/fog/core/collection.rb +22 -27
  27. data/lib/fog/core/connection.rb +5 -6
  28. data/lib/fog/core/credentials.rb +7 -7
  29. data/lib/fog/core/current_machine.rb +10 -8
  30. data/lib/fog/core/deprecated_connection_accessors.rb +0 -1
  31. data/lib/fog/core/deprecation.rb +0 -2
  32. data/lib/fog/core/errors.rb +3 -5
  33. data/lib/fog/core/hmac.rb +4 -6
  34. data/lib/fog/core/logger.rb +10 -11
  35. data/lib/fog/core/mock.rb +19 -25
  36. data/lib/fog/core/model.rb +9 -20
  37. data/lib/fog/core/provider.rb +6 -9
  38. data/lib/fog/core/scp.rb +14 -24
  39. data/lib/fog/core/service.rb +28 -31
  40. data/lib/fog/core/ssh.rb +16 -24
  41. data/lib/fog/core/stringify_keys.rb +7 -9
  42. data/lib/fog/core/time.rb +5 -7
  43. data/lib/fog/core/utils.rb +24 -20
  44. data/lib/fog/core/uuid.rb +2 -3
  45. data/lib/fog/core/version.rb +3 -1
  46. data/lib/fog/core/wait_for.rb +2 -2
  47. data/lib/fog/core/wait_for_defaults.rb +13 -10
  48. data/lib/fog/core/whitelist_keys.rb +1 -1
  49. data/lib/fog/dns.rb +6 -8
  50. data/lib/fog/identity.rb +5 -6
  51. data/lib/fog/image.rb +3 -5
  52. data/lib/fog/metering.rb +3 -6
  53. data/lib/fog/monitoring.rb +3 -5
  54. data/lib/fog/network.rb +4 -6
  55. data/lib/fog/orchestration.rb +3 -5
  56. data/lib/fog/schema/data_validator.rb +17 -22
  57. data/lib/fog/storage.rb +22 -16
  58. data/lib/fog/support.rb +3 -6
  59. data/lib/fog/test_helpers.rb +10 -10
  60. data/lib/fog/test_helpers/collection_helper.rb +23 -43
  61. data/lib/fog/test_helpers/compute/flavors_helper.rb +4 -10
  62. data/lib/fog/test_helpers/compute/server_helper.rb +3 -9
  63. data/lib/fog/test_helpers/compute/servers_helper.rb +0 -4
  64. data/lib/fog/test_helpers/formats_helper.rb +13 -14
  65. data/lib/fog/test_helpers/helper.rb +9 -4
  66. data/lib/fog/test_helpers/mock_helper.rb +92 -94
  67. data/lib/fog/test_helpers/model_helper.rb +7 -15
  68. data/lib/fog/test_helpers/responds_to_helper.rb +1 -3
  69. data/lib/fog/test_helpers/succeeds_helper.rb +1 -3
  70. data/lib/fog/volume.rb +3 -6
  71. data/lib/fog/vpn.rb +3 -5
  72. data/lib/tasks/test_task.rb +2 -6
  73. data/spec/compute_spec.rb +11 -13
  74. data/spec/connection_spec.rb +24 -14
  75. data/spec/credentials_spec.rb +23 -23
  76. data/spec/current_machine_spec.rb +6 -6
  77. data/spec/fake_app/fake_service.rb +18 -0
  78. data/spec/fake_app/models/collection.rb +5 -0
  79. data/spec/fake_app/models/model.rb +2 -0
  80. data/spec/fake_app/requests/request.rb +11 -0
  81. data/spec/fog_attribute_spec.rb +178 -136
  82. data/spec/identity_spec.rb +11 -13
  83. data/spec/mocking_spec.rb +7 -8
  84. data/spec/service_spec.rb +21 -7
  85. data/spec/spec_helper.rb +14 -8
  86. data/spec/storage_spec.rb +25 -13
  87. data/spec/test_helpers/formats_helper_spec.rb +52 -52
  88. data/spec/test_helpers/schema_validator_spec.rb +45 -45
  89. data/spec/timeout_spec.rb +1 -2
  90. data/spec/utils_spec.rb +2 -2
  91. data/spec/uuid_spec.rb +1 -1
  92. data/spec/wait_for_spec.rb +7 -4
  93. metadata +57 -33
@@ -1,10 +1,9 @@
1
- require 'time'
1
+ require "time"
2
2
 
3
3
  module Fog
4
4
  class Time < ::Time
5
-
6
- DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
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
- self.utc.strftime("#{DAYS[self.utc.wday]}, %d #{MONTHS[self.utc.month - 1]} %Y %H:%M:%S +0000")
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
- self.utc.strftime('%Y%m%dT%H%M%SZ')
27
+ utc.strftime("%Y%m%dT%H%M%SZ")
29
28
  end
30
-
31
29
  end
32
30
  end
@@ -1,24 +1,28 @@
1
- module Fog::Core::Utils
2
- # This helper prepares a Hash of settings for passing into {Fog::Service.new}.
3
- #
4
- # The only special consideration is if +:header+ key is passed in the contents are unchanged. This
5
- # allows the headers to be passed through to requests to customise HTTP headers without them being
6
- # broken by the +#to_sym+ calls.
7
- #
8
- # @param [Hash] settings The String based Hash to prepare
9
- # @option settings [Hash] :headers Passed to the underlying {Fog::Core::Connection} unchanged
10
- # @return [Hash]
11
- #
12
- def self.prepare_service_settings(settings)
13
- if settings.is_a? Hash
14
- copy = Array.new
15
- settings.each do |key, value|
16
- obj = ![:headers].include?(key) ? self.prepare_service_settings(value) : value
17
- copy.push(key.to_sym, obj)
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
@@ -1,9 +1,8 @@
1
- require 'securerandom'
1
+ require "securerandom"
2
2
 
3
3
  module Fog
4
4
  class UUID
5
5
  class << self
6
-
7
6
  def uuid
8
7
  if supported?
9
8
  SecureRandom.uuid
@@ -20,4 +19,4 @@ module Fog
20
19
  end
21
20
  end
22
21
  end
23
- end
22
+ end
@@ -1,3 +1,5 @@
1
1
  module Fog
2
- VERSION = "1.24.0"
2
+ module Core
3
+ VERSION = "1.25.0"
4
+ end
3
5
  end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
- def self.wait_for(timeout=Fog.timeout, interval=Fog.interval, &block)
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.new("The specified wait_for timeout (#{timeout} seconds) was exceeded")
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 ** (retries - 1), @max_interval].min }
3
- def self.interval
4
- @interval
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.kind_of?(Proc)
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
- def self.timeout
18
- @timeout
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
- def self.max_interval
28
- @max_interval
29
+
30
+ class << self
31
+ attr_reader :max_interval
29
32
  end
30
33
 
31
34
  def self.max_interval=(interval)
@@ -2,7 +2,7 @@ module Fog
2
2
  module WhitelistKeys
3
3
  def self.whitelist(hash, valid_keys)
4
4
  valid_hash = StringifyKeys.stringify(hash)
5
- valid_hash.select {|k,v| valid_keys.include?(k)}
5
+ valid_hash.select { |k, _v| valid_keys.include?(k) }
6
6
  end
7
7
  end
8
8
  end
@@ -1,26 +1,25 @@
1
1
  module Fog
2
2
  module DNS
3
-
4
3
  def self.[](provider)
5
- self.new(:provider => provider)
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 'fog/storm_on_demand/dns'
11
+ require "fog/storm_on_demand/dns"
13
12
  Fog::DNS::StormOnDemand.new(attributes)
14
13
  else
15
- if self.providers.include?(provider)
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::const_get(Fog.providers[provider])::DNS
19
+ Fog.const_get(Fog.providers[provider])::DNS
21
20
  end.new(attributes)
22
21
  else
23
- raise ArgumentError.new("#{provider} is not a recognized dns provider")
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
- for provider in self.providers
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
@@ -1,8 +1,7 @@
1
1
  module Fog
2
2
  module Identity
3
-
4
3
  def self.[](provider)
5
- self.new(:provider => provider)
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.new("#{provider} has no identity service")
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]).new(attributes)
17
+ Fog::Identity.const_get(Fog.providers[provider])
19
18
  rescue
20
- Fog::const_get(Fog.providers[provider])::Identity.new(attributes)
21
- end
19
+ Fog.const_get(Fog.providers[provider])::Identity
20
+ end.new(attributes)
22
21
  end
23
22
 
24
23
  def self.providers
@@ -1,23 +1,21 @@
1
1
  module Fog
2
2
  module Image
3
-
4
3
  def self.[](provider)
5
- self.new(:provider => provider)
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 self.providers.include?(provider)
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.new("#{provider} has no identity service")
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
@@ -1,25 +1,22 @@
1
1
  module Fog
2
2
  module Metering
3
-
4
3
  def self.[](provider)
5
- self.new(:provider => provider)
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 self.providers.include?(provider)
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.new("#{provider} has no identity service")
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
-
@@ -1,24 +1,22 @@
1
1
  module Fog
2
2
  module Monitoring
3
-
4
3
  def self.[](provider)
5
- self.new(:provider => provider)
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 'fog/storm_on_demand/billing'
11
+ require "fog/storm_on_demand/billing"
13
12
  Fog::Monitoring::StormOnDemand.new(attributes)
14
13
  else
15
- raise ArgumentError.new("#{provider} has no monitoring service")
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
@@ -1,8 +1,7 @@
1
1
  module Fog
2
2
  module Network
3
-
4
3
  def self.[](provider)
5
- self.new(:provider => provider)
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 self.providers.include?(provider)
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.new("#{provider} has no network service")
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
@@ -1,25 +1,23 @@
1
1
  module Fog
2
2
  module Orchestration
3
-
4
3
  def self.[](provider)
5
- self.new(:provider => provider)
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 self.providers.include?(provider)
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.new("#{provider} has no orchestration service")
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
- # This returns the last message set by the validator
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
- unless options[:allow_extra_keys]
120
- if value.respond_to?(:empty?)
121
- # Validator is empty but values are not
122
- return false if !value.empty? && validator.empty?
123
- end
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
- unless options[:allow_optional_rules]
127
- if value.respond_to?(:empty?)
128
- # Validator has rules left but no more values
129
- return false if value.empty? && !validator.empty?
130
- end
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 (result.is_a?(TrueClass) || result.is_a?(FalseClass))
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