fog-core 2.0.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_dependency("builder")
24
24
  spec.add_dependency("mime-types")
25
- spec.add_dependency("excon", "~> 0.58")
25
+ spec.add_dependency("excon", "~> 0.71")
26
26
  spec.add_dependency("formatador", "~> 0.2")
27
27
 
28
28
  # https://github.com/fog/fog-core/issues/206
@@ -1,21 +1,5 @@
1
1
  module Fog
2
2
  module Account
3
3
  extend Fog::ServicesMixin
4
-
5
- def self.new(orig_attributes)
6
- attributes = orig_attributes.dup
7
- provider = attributes.delete(:provider).to_s.downcase.to_sym
8
-
9
- if provider == :stormondemand
10
- require "fog/account/storm_on_demand"
11
- Fog::Account::StormOnDemand.new(attributes)
12
- else
13
- super(orig_attributes)
14
- end
15
- end
16
-
17
- def self.providers
18
- Fog.services[:account] || []
19
- end
20
4
  end
21
5
  end
@@ -1,16 +1,5 @@
1
1
  module Fog
2
2
  module Billing
3
3
  extend Fog::ServicesMixin
4
-
5
- def self.new(orig_attributes)
6
- attributes = orig_attributes.dup
7
- provider = attributes.delete(:provider).to_s.downcase.to_sym
8
- if provider == :stormondemand
9
- require "fog/billing/storm_on_demand"
10
- Fog::Billing::StormOnDemand.new(attributes)
11
- else
12
- super(orig_attributes)
13
- end
14
- end
15
4
  end
16
5
  end
@@ -7,16 +7,6 @@ module Fog
7
7
  provider = attributes.delete(:provider).to_s.downcase.to_sym
8
8
 
9
9
  case provider
10
- when :gogrid
11
- require "fog/go_grid/compute"
12
- Fog::Compute::GoGrid.new(attributes)
13
- when :new_servers
14
- require "fog/bare_metal_cloud/compute"
15
- Fog::Logger.deprecation "`new_servers` is deprecated. Please use `bare_metal_cloud` instead."
16
- Fog::Compute::BareMetalCloud.new(attributes)
17
- when :baremetalcloud
18
- require "fog/bare_metal_cloud/compute"
19
- Fog::Compute::BareMetalCloud.new(attributes)
20
10
  when :rackspace
21
11
  version = attributes.delete(:version)
22
12
  version = version.to_s.downcase.to_sym unless version.nil?
@@ -38,18 +28,6 @@ module Fog
38
28
  require 'fog/digitalocean/compute'
39
29
  Fog::Compute::DigitalOcean.new(attributes)
40
30
  end
41
- when :stormondemand
42
- require "fog/compute/storm_on_demand"
43
- Fog::Compute::StormOnDemand.new(attributes)
44
- when :vcloud
45
- require "fog/vcloud/compute"
46
- Fog::Vcloud::Compute.new(attributes)
47
- when :vclouddirector
48
- require "fog/vcloud_director/compute"
49
- Fog::Compute::VcloudDirector.new(attributes)
50
- when :cloudatcost
51
- require "fog/cloudatcost/compute"
52
- Fog::Compute::CloudAtCost.new(attributes)
53
31
  else
54
32
  super(orig_attributes)
55
33
  end
@@ -79,14 +79,26 @@ module Fog
79
79
 
80
80
  def all_attributes
81
81
  self.class.attributes.reduce({}) do |hash, attribute|
82
- hash[masks[attribute]] = send(attribute)
82
+ if masks[attribute].nil?
83
+ Fog::Logger.deprecation("Please define #{attribute} using the Fog DSL")
84
+ hash[attribute] = send(attribute)
85
+ else
86
+ hash[masks[attribute]] = send(attribute)
87
+ end
88
+
83
89
  hash
84
90
  end
85
91
  end
86
92
 
87
93
  def all_associations
88
94
  self.class.associations.keys.reduce({}) do |hash, association|
89
- hash[masks[association]] = associations[association] || send(association)
95
+ if masks[association].nil?
96
+ Fog::Logger.deprecation("Please define #{association} using the Fog DSL")
97
+ hash[association] = associations[association] || send(association)
98
+ else
99
+ hash[masks[association]] = associations[association] || send(association)
100
+ end
101
+
90
102
  hash
91
103
  end
92
104
  end
@@ -44,12 +44,10 @@ module Fog
44
44
  # @option params [Class] :instrumentor Responds to #instrument as in ActiveSupport::Notifications
45
45
  # @option params [String] :instrumentor_name Name prefix for #instrument events. Defaults to 'excon'
46
46
  def initialize(url, persistent = false, params = {})
47
- if params[:path_prefix]
48
- if params[:path]
49
- raise ArgumentError, "optional arg 'path' is invalid when 'path_prefix' is provided"
50
- end
47
+ @path_prefix = params.delete(:path_prefix)
51
48
 
52
- @path_prefix = params.delete(:path_prefix)
49
+ if @path_prefix && params[:path]
50
+ raise ArgumentError, "optional arg 'path' is invalid when 'path_prefix' is provided"
53
51
  end
54
52
 
55
53
  params[:debug_response] = true unless params.key?(:debug_response)
@@ -112,6 +112,10 @@ An alternate file may be used by placing its path in the FOG_RC environment vari
112
112
  :vcloud_director_host:
113
113
  :vcloud_director_username:
114
114
  :vcloud_director_password:
115
+ :kubevirt_hostname:
116
+ :kubevirt_port:
117
+ :kubevirt_token:
118
+
115
119
  #
116
120
  # End of Fog Credentials File
117
121
  #######################################################
@@ -46,6 +46,8 @@ module Fog
46
46
 
47
47
  object = collection.get(identity)
48
48
 
49
+ return unless object
50
+
49
51
  merge_attributes(object.all_associations_and_attributes)
50
52
 
51
53
  self
@@ -11,6 +11,7 @@ module Fog
11
11
  def self.extended(base)
12
12
  provider = base.to_s.split("::").last
13
13
  Fog.providers[provider.downcase.to_sym] = provider
14
+ Fog.providers[underscore_name(provider)] = provider
14
15
  end
15
16
 
16
17
  def [](service_key)
@@ -21,11 +22,40 @@ module Fog
21
22
  Fog.services[new_service] ||= []
22
23
  Fog.services[new_service] |= [to_s.split("::").last.downcase.to_sym]
23
24
  @services_registry ||= {}
24
- @services_registry[new_service] = [to_s, constant_string].join("::")
25
+ @services_registry[new_service] = service_klass(constant_string)
25
26
  end
26
27
 
27
28
  def services
28
29
  @services_registry.keys
29
30
  end
31
+
32
+ # Returns service constant path, with provider, as string. If
33
+ # "provider::service" is defined (the preferred format) then it returns that
34
+ # string, otherwise it returns the deprecated string "service::provider".
35
+ def service_klass(constant_string)
36
+ eval([to_s, constant_string].join("::"))
37
+ [to_s, constant_string].join("::")
38
+ rescue NameError
39
+ provider = to_s.split("::").last
40
+ Fog::Logger.deprecation("Unable to load #{[to_s, constant_string].join("::")}")
41
+ Fog::Logger.deprecation(
42
+ format(
43
+ Fog::ServicesMixin::E_SERVICE_PROVIDER_CONSTANT,
44
+ service: constant_string,
45
+ provider: provider
46
+ )
47
+ )
48
+ ['Fog', constant_string, provider].join("::")
49
+ end
50
+
51
+ private
52
+
53
+ def underscore_name(string)
54
+ string.gsub(/::/, '/').
55
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
56
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
57
+ tr("-", "_").
58
+ downcase
59
+ end
30
60
  end
31
61
  end
@@ -64,7 +64,9 @@ module Fog
64
64
 
65
65
  @address = address
66
66
  @username = username
67
- @options = { :paranoid => false, :verify_host_key => false }.merge(options)
67
+ @options = { :paranoid => false, :verify_host_key => :never }.merge(options)
68
+ @options.delete(:paranoid) if Net::SSH::VALID_OPTIONS.include? :verify_host_key
69
+ @options[:verify_host_key] = false unless Net::SSH::Verifiers.const_defined?(:Never)
68
70
  end
69
71
 
70
72
  def upload(local_path, remote_path, upload_options = {}, &block)
@@ -1,12 +1,25 @@
1
1
  module Fog
2
2
  module ServicesMixin
3
+ E_SERVICE_PROVIDER_CONSTANT = <<-EOS.gsub(/\s+/, ' ').strip.freeze
4
+ Falling back to deprecated constant Fog::%<service>s::%<provider>s. The
5
+ preferred format of service provider constants has changed from
6
+ service::provider to provider::service. Please update this service
7
+ provider to use the preferred format.
8
+ EOS
9
+ E_SERVICE_PROVIDER_PATH = <<-EOS.gsub(/\s+/, ' ').strip.freeze
10
+ Falling back to deprecated path fog/%<service>s/%<provider>s. The
11
+ preferred file path format has changed from service/provider to
12
+ provider/service. Please update this service provider to use the preferred
13
+ format.
14
+ EOS
15
+
3
16
  def [](provider)
4
17
  new(:provider => provider)
5
18
  end
6
19
 
7
20
  def new(attributes)
8
21
  attributes = attributes.dup # Prevent delete from having side effects
9
- provider = attributes.delete(:provider).to_s.downcase.to_sym
22
+ provider = check_provider_alias(attributes.delete(:provider).to_s.downcase.to_sym)
10
23
  provider_name = Fog.providers[provider]
11
24
 
12
25
  raise ArgumentError, "#{provider} is not a recognized provider" unless providers.include?(provider)
@@ -14,7 +27,9 @@ module Fog
14
27
  require_service_provider_library(service_name.downcase, provider)
15
28
  spc = service_provider_constant(service_name, provider_name)
16
29
  spc.new(attributes)
17
- rescue LoadError, NameError # Only rescue errors in finding the libraries, allow connection errors through to the caller
30
+ rescue LoadError, NameError => e # Only rescue errors in finding the libraries, allow connection errors through to the caller
31
+ Fog::Logger.warning("Error while loading provider #{provider}: #{e.message}")
32
+ Fog::Logger.debug("backtrace: #{e.backtrace.join("\n")}")
18
33
  raise Fog::Service::NotFound, "#{provider} has no #{service_name.downcase} service"
19
34
  end
20
35
 
@@ -24,16 +39,28 @@ module Fog
24
39
 
25
40
  private
26
41
 
42
+ # This method should be removed once all providers are extracted.
43
+ # Bundler will correctly require all dependencies automatically and thus
44
+ # fog-core wont need to know any specifics providers. Each provider will
45
+ # have to load its dependencies.
27
46
  def require_service_provider_library(service, provider)
28
47
  require "fog/#{provider}/#{service}"
29
48
  rescue LoadError # Try to require the service provider in an alternate location
49
+ Fog::Logger.deprecation("Unable to require fog/#{provider}/#{service}")
50
+ Fog::Logger.deprecation(
51
+ format(E_SERVICE_PROVIDER_PATH, service: service, provider: provider)
52
+ )
30
53
  require "fog/#{service}/#{provider}"
31
54
  end
32
55
 
33
56
  def service_provider_constant(service_name, provider_name)
34
- Fog.const_get(service_name).const_get(*const_get_args(provider_name))
35
- rescue NameError # Try to find the constant from in an alternate location
36
57
  Fog.const_get(provider_name).const_get(*const_get_args(service_name))
58
+ rescue NameError # Try to find the constant from in an alternate location
59
+ Fog::Logger.deprecation("Unable to load Fog::#{provider_name}::#{service_name}")
60
+ Fog::Logger.deprecation(
61
+ format(E_SERVICE_PROVIDER_CONSTANT, service: service_name, provider: provider_name)
62
+ )
63
+ Fog.const_get(service_name).const_get(*const_get_args(provider_name))
37
64
  end
38
65
 
39
66
  def const_get_args(*args)
@@ -43,5 +70,29 @@ module Fog
43
70
  def service_name
44
71
  name.split("Fog::").last
45
72
  end
73
+
74
+ def check_provider_alias(provider)
75
+ case provider
76
+ when :baremetalcloud
77
+ Fog::Logger.deprecation(':baremetalcloud is deprecated. Use :bare_metal_cloud instead!')
78
+ :bare_metal_cloud
79
+ when :gogrid
80
+ Fog::Logger.deprecation(':gogrid is deprecated. Use :go_grid instead!')
81
+ :go_grid
82
+ when :internetarchive
83
+ Fog::Logger.deprecation(':internetarchive is deprecated. Use :internet_archive instead!')
84
+ :internet_archive
85
+ when :new_servers
86
+ Fog::Logger.deprecation(':new_servers is deprecated. Use :bare_metal_cloud instead!')
87
+ :bare_metal_cloud
88
+ when :stormondemand
89
+ Fog::Logger.deprecation(':stormondemand is deprecated. Use :storm_on_demand instead!')
90
+ :storm_on_demand
91
+ when :vclouddirector
92
+ Fog::Logger.deprecation(':vclouddirector is deprecated. Use :vcloud_director instead!')
93
+ :vcloud_director
94
+ else provider
95
+ end
96
+ end
46
97
  end
47
98
  end
@@ -34,31 +34,10 @@ module Fog
34
34
 
35
35
  class Real
36
36
  def initialize(address, username, options)
37
- begin
38
- require "net/ssh"
39
- rescue LoadError
40
- Fog::Logger.warning("'net/ssh' missing, please install and try again.")
41
- exit(1)
42
- end
43
-
44
- key_manager = Net::SSH::Authentication::KeyManager.new(nil, options)
45
-
46
- unless options[:key_data] || options[:keys] || options[:password] || key_manager.agent
47
- raise ArgumentError, ":key_data, :keys, :password or a loaded ssh-agent is required to initialize SSH"
48
- end
49
-
50
- options[:timeout] ||= 30
51
- if options[:key_data] || options[:keys]
52
- options[:keys_only] = true
53
- # Explicitly set these so net-ssh doesn"t add the default keys
54
- # as seen at https://github.com/net-ssh/net-ssh/blob/master/lib/net/ssh/authentication/session.rb#L131-146
55
- options[:keys] = [] unless options[:keys]
56
- options[:key_data] = [] unless options[:key_data]
57
- end
58
-
37
+ assert_net_ssh_loaded
59
38
  @address = address
60
39
  @username = username
61
- @options = { :paranoid => false, :verify_host_key => false }.merge(options)
40
+ @options = build_options(options)
62
41
  end
63
42
 
64
43
  def run(commands, &blk)
@@ -106,6 +85,51 @@ module Fog
106
85
  end
107
86
  results
108
87
  end
88
+
89
+ private
90
+
91
+ def assert_net_ssh_loaded
92
+ begin
93
+ require "net/ssh"
94
+ rescue LoadError
95
+ Fog::Logger.warning("'net/ssh' missing, please install and try again.")
96
+ exit(1)
97
+ end
98
+ end
99
+
100
+ # Modifies the given `options` hash AND returns a new hash.
101
+ # TODO: Probably shouldn't modify the given hash.
102
+ def build_options(options)
103
+ validate_options(options)
104
+ merge_default_options_into(options)
105
+ end
106
+
107
+ def merge_default_options_into(options)
108
+ options[:timeout] ||= 30
109
+ if options[:key_data] || options[:keys]
110
+ options[:keys_only] = true
111
+ # Explicitly set these so net-ssh doesn"t add the default keys
112
+ # as seen at https://github.com/net-ssh/net-ssh/blob/master/lib/net/ssh/authentication/session.rb#L131-146
113
+ options[:keys] = [] unless options[:keys]
114
+ options[:key_data] = [] unless options[:key_data]
115
+ end
116
+
117
+ # net-ssh has deprecated :paranoid in favor of :verify_host_key
118
+ # https://github.com/net-ssh/net-ssh/pull/524
119
+ opts = { :paranoid => false, :verify_host_key => :never }.merge(options)
120
+ if Net::SSH::VALID_OPTIONS.include? :verify_host_key
121
+ opts.delete(:paranoid)
122
+ end
123
+ opts[:verify_host_key] = false unless Net::SSH::Verifiers.const_defined?(:Never)
124
+ opts
125
+ end
126
+
127
+ def validate_options(options)
128
+ key_manager = Net::SSH::Authentication::KeyManager.new(nil, options)
129
+ unless options[:key_data] || options[:keys] || options[:password] || key_manager.agent
130
+ raise ArgumentError, ":key_data, :keys, :password or a loaded ssh-agent is required to initialize SSH"
131
+ end
132
+ end
109
133
  end
110
134
 
111
135
  class Result
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Core
3
- VERSION = "2.0.0"
3
+ VERSION = "2.2.1"
4
4
  end
5
5
  end
@@ -2,17 +2,6 @@ module Fog
2
2
  module DNS
3
3
  extend Fog::ServicesMixin
4
4
 
5
- def self.new(orig_attributes)
6
- attributes = orig_attributes.dup # prevent delete from having side effects
7
- case attributes.delete(:provider).to_s.downcase.to_sym
8
- when :stormondemand
9
- require "fog/dns/storm_on_demand"
10
- Fog::DNS::StormOnDemand.new(attributes)
11
- else
12
- super(orig_attributes)
13
- end
14
- end
15
-
16
5
  def self.zones
17
6
  zones = []
18
7
  providers.each do |provider|
@@ -1,16 +1,5 @@
1
1
  module Fog
2
2
  module Monitoring
3
3
  extend Fog::ServicesMixin
4
-
5
- def self.new(orig_attributes)
6
- attributes = orig_attributes.dup
7
- provider = attributes.delete(:provider).to_s.downcase.to_sym
8
- if provider == :stormondemand
9
- require "fog/monitoring/storm_on_demand"
10
- Fog::Monitoring::StormOnDemand.new(attributes)
11
- else
12
- super(orig_attributes)
13
- end
14
- end
15
4
  end
16
5
  end
@@ -1,17 +1,5 @@
1
1
  module Fog
2
2
  module Network
3
3
  extend Fog::ServicesMixin
4
-
5
- def self.new(orig_attributes)
6
- attributes = orig_attributes.dup # Prevent delete from having side effects
7
- provider = attributes.delete(:provider).to_s.downcase.to_sym
8
-
9
- if provider == :stormondemand
10
- require "fog/network/storm_on_demand"
11
- return Fog::Network::StormOnDemand.new(attributes)
12
- else
13
- super(orig_attributes)
14
- end
15
- end
16
4
  end
17
5
  end