Commit b68bf56f authored by Praveen Arimbrathodiyil's avatar Praveen Arimbrathodiyil
Browse files

Merge tag 'upstream/1.25.0'

Upstream version 1.25.0

# gpg: Signature made Sunday 30 November 2014 05:44:52 PM IST using RSA key ID 4512C22A
# gpg: Good signature from "Praveen Arimbrathodiyil (piratepin) <praveen@debian.org>"
# gpg:                 aka "Praveen Arimbrathodiyil (j4v4m4n) <pravi.a@gmail.com>"
# gpg:                 aka "Pirate Praveen (PP) <praveen@privacyrequired.com>"
# gpg:                 aka "Pirate Praveen (pirates.org.in) <praveen@onenetbeyond.org>"
parents e4617ae7 1cdc81f1
Metrics/LineLength:
Enabled: false
Style/EachWithObject:
Enabled: false
Style/Encoding:
EnforcedStyle: when_needed
Style/FormatString:
Enabled: false
Style/HashSyntax:
EnforcedStyle: hash_rockets
Style/SignalException:
EnforcedStyle: only_raise
Style/StringLiterals:
EnforcedStyle: double_quotes
1.25.0 11/18/2014
==========================================================
add alias options for associations
improve spec message
add feature to overwrite keys on hash of attributes generation
remove method_missing from model
add rubocop
fix rubocop warnings
return collections on association getters
fix require bug in service
put fog and fog-core versions in user agent
don't mutate/destroy encoding in get_body_size
fix error output in from const_get usage
separate to have distinct version from fog
1.24.0 08/26/2014 1.24.0 08/26/2014
========================================================== ==========================================================
......
...@@ -5,7 +5,7 @@ require 'fog/core/version' ...@@ -5,7 +5,7 @@ require 'fog/core/version'
Gem::Specification.new do |spec| Gem::Specification.new do |spec|
spec.name = "fog-core" spec.name = "fog-core"
spec.version = Fog::VERSION spec.version = Fog::Core::VERSION
spec.authors = ["Evan Light", "Wesley Beary"] spec.authors = ["Evan Light", "Wesley Beary"]
spec.email = ["evan@tripledogdare.net", "geemus@gmail.com"] spec.email = ["evan@tripledogdare.net", "geemus@gmail.com"]
spec.summary = %q{Shared classes and tests for fog providers and services.} spec.summary = %q{Shared classes and tests for fog providers and services.}
...@@ -32,4 +32,5 @@ Gem::Specification.new do |spec| ...@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency('minitest-stub-const') spec.add_development_dependency('minitest-stub-const')
spec.add_development_dependency('pry') spec.add_development_dependency('pry')
spec.add_development_dependency('coveralls') spec.add_development_dependency('coveralls')
spec.add_development_dependency('rubocop') if RUBY_VERSION.to_s >= '1.9.3'
end end
module Fog module Fog
module Account module Account
def self.[](provider) def self.[](provider)
self.new(:provider => provider) new(:provider => provider)
end end
def self.new(attributes) def self.new(attributes)
...@@ -10,16 +9,15 @@ module Fog ...@@ -10,16 +9,15 @@ module Fog
provider = attributes.delete(:provider).to_s.downcase.to_sym provider = attributes.delete(:provider).to_s.downcase.to_sym
if provider == :stormondemand if provider == :stormondemand
require 'fog/storm_on_demand/account' require "fog/storm_on_demand/account"
Fog::Account::StormOnDemand.new(attributes) Fog::Account::StormOnDemand.new(attributes)
else else
raise ArgumentError.new("#{provider} has no account service") raise ArgumentError, "#{provider} has no account service"
end end
end end
def self.providers def self.providers
Fog.services[:account] Fog.services[:account]
end end
end end
end end
module Fog module Fog
module Billing module Billing
def self.[](provider) def self.[](provider)
self.new(:provider => provider) new(:provider => provider)
end end
def self.new(attributes) def self.new(attributes)
attributes = attributes.dup attributes = attributes.dup
provider = attributes.delete(:provider).to_s.downcase.to_sym provider = attributes.delete(:provider).to_s.downcase.to_sym
if provider == :stormondemand if provider == :stormondemand
require 'fog/storm_on_demand/billing' require "fog/storm_on_demand/billing"
Fog::Billing::StormOnDemand.new(attributes) Fog::Billing::StormOnDemand.new(attributes)
else else
raise ArgumentError.new("#{provider} has no billing service") raise ArgumentError, "#{provider} has no billing service"
end end
end end
......
module Fog module Fog
module CDN module CDN
def self.[](provider) def self.[](provider)
self.new(:provider => provider) new(:provider => provider)
end end
def self.new(attributes) def self.new(attributes)
attributes = attributes.dup # prevent delete from having side effects attributes = attributes.dup # prevent delete from having side effects
provider = attributes.delete(:provider).to_s.downcase.to_sym provider = attributes.delete(:provider).to_s.downcase.to_sym
if self.providers.include?(provider) if providers.include?(provider)
require "fog/#{provider}/cdn" require "fog/#{provider}/cdn"
return Fog::CDN.const_get(Fog.providers[provider]).new(attributes) return Fog::CDN.const_get(Fog.providers[provider]).new(attributes)
end end
raise ArgumentError.new("#{provider} is not a recognized cdn provider") raise ArgumentError, "#{provider} is not a recognized cdn provider"
end end
def self.providers def self.providers
Fog.services[:cdn] Fog.services[:cdn]
end end
end end
end end
module Fog module Fog
module Compute module Compute
def self.[](provider) def self.[](provider)
self.new(:provider => provider) new(:provider => provider)
end end
def self.new(attributes) def self.new(attributes)
attributes = attributes.dup # prevent delete from having side effects attributes = attributes.dup # prevent delete from having side effects
provider = attributes.delete(:provider).to_s.downcase.to_sym provider = attributes.delete(:provider).to_s.downcase.to_sym
case provider case provider
when :gogrid when :gogrid
require 'fog/go_grid/compute' require "fog/go_grid/compute"
Fog::Compute::GoGrid.new(attributes) Fog::Compute::GoGrid.new(attributes)
when :hp when :hp
version = attributes.delete(:version) version = attributes.delete(:version)
version = version.to_s.downcase.to_sym unless version.nil? version = version.to_s.downcase.to_sym unless version.nil?
if version == :v2 if version == :v2
require 'fog/hp/compute_v2' require "fog/hp/compute_v2"
Fog::Compute::HPV2.new(attributes) Fog::Compute::HPV2.new(attributes)
else else
Fog::Logger.deprecation "HP Cloud Compute V1 service will be soon deprecated. Please use `:version => v2` attribute to use HP Cloud Compute V2 service." Fog::Logger.deprecation "HP Cloud Compute V1 service will be soon deprecated. Please use `:version => v2` attribute to use HP Cloud Compute V2 service."
require 'fog/hp/compute' require "fog/hp/compute"
Fog::Compute::HP.new(attributes) Fog::Compute::HP.new(attributes)
end end
when :new_servers when :new_servers
require 'fog/bare_metal_cloud/compute' require "fog/bare_metal_cloud/compute"
Fog::Logger.deprecation "`new_servers` is deprecated. Please use `bare_metal_cloud` instead." Fog::Logger.deprecation "`new_servers` is deprecated. Please use `bare_metal_cloud` instead."
Fog::Compute::BareMetalCloud.new(attributes) Fog::Compute::BareMetalCloud.new(attributes)
when :baremetalcloud when :baremetalcloud
require 'fog/bare_metal_cloud/compute' require "fog/bare_metal_cloud/compute"
Fog::Compute::BareMetalCloud.new(attributes) Fog::Compute::BareMetalCloud.new(attributes)
when :rackspace when :rackspace
version = attributes.delete(:version) version = attributes.delete(:version)
version = version.to_s.downcase.to_sym unless version.nil? version = version.to_s.downcase.to_sym unless version.nil?
if version == :v1 if version == :v1
Fog::Logger.deprecation "First Gen Cloud Servers are deprecated. Please use `:version => :v2` attribute to use Next Gen Cloud Servers." Fog::Logger.deprecation "First Gen Cloud Servers are deprecated. Please use `:version => :v2` attribute to use Next Gen Cloud Servers."
require 'fog/rackspace/compute' require "fog/rackspace/compute"
Fog::Compute::Rackspace.new(attributes) Fog::Compute::Rackspace.new(attributes)
else else
require 'fog/rackspace/compute_v2' require "fog/rackspace/compute_v2"
Fog::Compute::RackspaceV2.new(attributes) Fog::Compute::RackspaceV2.new(attributes)
end end
when :stormondemand when :stormondemand
require 'fog/storm_on_demand/compute' require "fog/storm_on_demand/compute"
Fog::Compute::StormOnDemand.new(attributes) Fog::Compute::StormOnDemand.new(attributes)
when :vcloud when :vcloud
require 'fog/vcloud/compute' require "fog/vcloud/compute"
Fog::Vcloud::Compute.new(attributes) Fog::Vcloud::Compute.new(attributes)
when :vclouddirector when :vclouddirector
require 'fog/vcloud_director/compute' require "fog/vcloud_director/compute"
Fog::Compute::VcloudDirector.new(attributes) Fog::Compute::VcloudDirector.new(attributes)
else else
if self.providers.include?(provider) if providers.include?(provider)
require "fog/#{provider}/compute" require "fog/#{provider}/compute"
begin begin
Fog::Compute.const_get(Fog.providers[provider]) Fog::Compute.const_get(Fog.providers[provider])
rescue rescue
Fog::const_get(Fog.providers[provider])::Compute Fog.const_get(Fog.providers[provider])::Compute
end.new(attributes) end.new(attributes)
else else
raise ArgumentError.new("#{provider} is not a recognized compute provider") raise ArgumentError, "#{provider} is not a recognized compute provider"
end end
end end
end end
...@@ -72,7 +70,7 @@ module Fog ...@@ -72,7 +70,7 @@ module Fog
def self.servers def self.servers
servers = [] servers = []
for provider in self.providers providers.each do |provider|
begin begin
servers.concat(self[provider].servers) servers.concat(self[provider].servers)
rescue # ignore any missing credentials/etc rescue # ignore any missing credentials/etc
...@@ -80,6 +78,5 @@ module Fog ...@@ -80,6 +78,5 @@ module Fog
end end
servers servers
end end
end end
end end
require 'fog/core/model' require "fog/core/model"
module Fog module Fog
module Compute module Compute
class Server < Fog::Model class Server < Fog::Model
attr_writer :username, :private_key, :private_key_path, :public_key, :public_key_path, :ssh_port, :ssh_options attr_writer :username, :private_key, :private_key_path, :public_key, :public_key_path, :ssh_port, :ssh_options
# Sets the proc used to determine the IP Address used for ssh/scp interactions.
# @example
# service.servers.bootstrap :name => "bootstrap-server",
# :flavor_id => service.flavors.first.id,
# :image_id => service.images.find {|img| img.name =~ /Ubuntu/}.id,
# :public_key_path => "~/.ssh/fog_rsa.pub",
# :private_key_path => "~/.ssh/fog_rsa",
# :ssh_ip_address => Proc.new {|server| server.private_ip_address }
#
# @note By default scp/ssh will use the public_ip_address if this proc is not set.
attr_writer :ssh_ip_address
def username def username
@username ||= 'root' @username ||= "root"
end end
def private_key_path def private_key_path
...@@ -35,20 +45,6 @@ module Fog ...@@ -35,20 +45,6 @@ module Fog
@ssh_port ||= 22 @ssh_port ||= 22
end end
# Sets the proc used to determine the IP Address used for ssh/scp interactions.
# @example
# service.servers.bootstrap :name => 'bootstrap-server',
# :flavor_id => service.flavors.first.id,
# :image_id => service.images.find {|img| img.name =~ /Ubuntu/}.id,
# :public_key_path => '~/.ssh/fog_rsa.pub',
# :private_key_path => '~/.ssh/fog_rsa',
# :ssh_ip_address => Proc.new {|server| server.private_ip_address }
#
# @note By default scp/ssh will use the public_ip_address if this proc is not set.
def ssh_ip_address=(proc)
@ssh_ip_address = proc
end
# IP Address used for ssh/scp interactions with server. # IP Address used for ssh/scp interactions with server.
# @return [String] IP Address # @return [String] IP Address
# @note By default this returns the public_ip_address # @note By default this returns the public_ip_address
...@@ -60,16 +56,16 @@ module Fog ...@@ -60,16 +56,16 @@ module Fog
def ssh_options def ssh_options
@ssh_options ||= {} @ssh_options ||= {}
ssh_options = @ssh_options.merge({:port => ssh_port}) ssh_options = @ssh_options.merge(:port => ssh_port)
if private_key if private_key
ssh_options[:key_data] = [private_key] ssh_options[:key_data] = [private_key]
ssh_options[:auth_methods] = ["publickey"] ssh_options[:auth_methods] = %w(publickey)
end end
ssh_options ssh_options
end end
def scp(local_path, remote_path, upload_options = {}) def scp(local_path, remote_path, upload_options = {})
require 'net/scp' require "net/scp"
requires :ssh_ip_address, :username requires :ssh_ip_address, :username
Fog::SCP.new(ssh_ip_address, username, ssh_options).upload(local_path, remote_path, upload_options) Fog::SCP.new(ssh_ip_address, username, ssh_options).upload(local_path, remote_path, upload_options)
...@@ -78,14 +74,14 @@ module Fog ...@@ -78,14 +74,14 @@ module Fog
alias_method :scp_upload, :scp alias_method :scp_upload, :scp
def scp_download(remote_path, local_path, download_options = {}) def scp_download(remote_path, local_path, download_options = {})
require 'net/scp' require "net/scp"
requires :ssh_ip_address, :username requires :ssh_ip_address, :username
Fog::SCP.new(ssh_ip_address, username, ssh_options).download(remote_path, local_path, download_options) Fog::SCP.new(ssh_ip_address, username, ssh_options).download(remote_path, local_path, download_options)
end end
def ssh(commands, options={}, &blk) def ssh(commands, options = {}, &blk)
require 'net/ssh' require "net/ssh"
requires :ssh_ip_address, :username requires :ssh_ip_address, :username
options = ssh_options.merge(options) options = ssh_options.merge(options)
...@@ -93,12 +89,11 @@ module Fog ...@@ -93,12 +89,11 @@ module Fog
Fog::SSH.new(ssh_ip_address, username, options).run(commands, &blk) Fog::SSH.new(ssh_ip_address, username, options).run(commands, &blk)
end end
def sshable?(options={}) def sshable?(options = {})
ready? && !ssh_ip_address.nil? && !!Timeout::timeout(8) { ssh('pwd', options) } ready? && !ssh_ip_address.nil? && !!Timeout.timeout(8) { ssh("pwd", options) }
rescue SystemCallError, Net::SSH::AuthenticationFailed, Net::SSH::Disconnect, Timeout::Error rescue SystemCallError, Net::SSH::AuthenticationFailed, Net::SSH::Disconnect, Timeout::Error
false false
end end
end end
end end
end end
# external core dependencies # external core dependencies
require 'base64' require "base64"
require 'cgi' require "cgi"
require 'uri' require "uri"
require 'excon' require "excon"
require 'fileutils' require "fileutils"
require 'formatador' require "formatador"
require 'openssl' require "openssl"
require 'time' require "time"
require 'timeout' require "timeout"
require 'ipaddr' require "ipaddr"
# internal core dependencies # internal core dependencies
require "fog/core/version" require "fog/core/version"
require 'fog/core/attributes' require "fog/core/attributes"
require 'fog/core/attributes/default' require "fog/core/attributes/default"
require 'fog/core/attributes/array' require "fog/core/attributes/array"
require 'fog/core/attributes/boolean' require "fog/core/attributes/boolean"
require 'fog/core/attributes/float' require "fog/core/attributes/float"
require 'fog/core/attributes/integer' require "fog/core/attributes/integer"
require 'fog/core/attributes/string' require "fog/core/attributes/string"
require 'fog/core/attributes/time' require "fog/core/attributes/time"
require 'fog/core/attributes/timestamp' require "fog/core/attributes/timestamp"
require 'fog/core/associations/default' require "fog/core/associations/default"
require 'fog/core/associations/many_identities' require "fog/core/associations/many_identities"
require 'fog/core/associations/many_models' require "fog/core/associations/many_models"
require 'fog/core/associations/one_model' require "fog/core/associations/one_model"
require 'fog/core/associations/one_identity' require "fog/core/associations/one_identity"
require 'fog/core/collection' require "fog/core/collection"
require 'fog/core/connection' require "fog/core/association"
require 'fog/core/credentials' require "fog/core/connection"
require 'fog/core/current_machine' require "fog/core/credentials"
require 'fog/core/deprecation' require "fog/core/current_machine"
require 'fog/core/errors' require "fog/core/deprecation"
require 'fog/core/hmac' require "fog/core/errors"
require 'fog/core/logger' require "fog/core/hmac"
require 'fog/core/model' require "fog/core/logger"
require 'fog/core/mock' require "fog/core/model"
require 'fog/core/provider' require "fog/core/mock"
require 'fog/core/service' require "fog/core/provider"
require 'fog/core/ssh' require "fog/core/service"
require 'fog/core/scp' require "fog/core/ssh"
require 'fog/core/time' require "fog/core/scp"
require 'fog/core/utils' require "fog/core/time"
require 'fog/core/wait_for' require "fog/core/utils"
require 'fog/core/wait_for_defaults' require "fog/core/wait_for"
require 'fog/core/uuid' require "fog/core/wait_for_defaults"
require 'fog/core/stringify_keys' require "fog/core/uuid"
require 'fog/core/whitelist_keys' require "fog/core/stringify_keys"
require "fog/core/whitelist_keys"
# service wrappers # service wrappers
require 'fog/account' require "fog/account"
require 'fog/billing' require "fog/billing"
require 'fog/cdn' require "fog/cdn"
require 'fog/compute' require "fog/compute"
require 'fog/dns' require "fog/dns"
require 'fog/identity' require "fog/identity"
require 'fog/image' require "fog/image"
require 'fog/metering' require "fog/metering"
require 'fog/monitoring' require "fog/monitoring"
require 'fog/network' require "fog/network"
require 'fog/orchestration' require "fog/orchestration"
require 'fog/storage' require "fog/storage"
require 'fog/support' require "fog/support"
require 'fog/volume' require "fog/volume"
require 'fog/vpn' require "fog/vpn"
module Fog
class Association < Collection
def initialize(associations = [])
@loaded = true
load(associations)
end
def load(associations)
return unless associations.kind_of?(Array)
associations.each do |association|
self << association
end
end
end
end
module Fog module Fog
module Associations module Associations
# = Fog Default Association
#
# This class has the shared behavior between all association models.
class Default class Default
attr_reader :model, :name attr_reader :model, :name, :aliases, :as, :association_class
def initialize(model, name, collection_name)