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
==========================================================
......
......@@ -5,7 +5,7 @@ require 'fog/core/version'
Gem::Specification.new do |spec|
spec.name = "fog-core"
spec.version = Fog::VERSION
spec.version = Fog::Core::VERSION
spec.authors = ["Evan Light", "Wesley Beary"]
spec.email = ["evan@tripledogdare.net", "geemus@gmail.com"]
spec.summary = %q{Shared classes and tests for fog providers and services.}
......@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency('minitest-stub-const')
spec.add_development_dependency('pry')
spec.add_development_dependency('coveralls')
spec.add_development_dependency('rubocop') if RUBY_VERSION.to_s >= '1.9.3'
end
module Fog
module Account
def self.[](provider)
self.new(:provider => provider)
new(:provider => provider)
end
def self.new(attributes)
......@@ -10,16 +9,15 @@ module Fog
provider = attributes.delete(:provider).to_s.downcase.to_sym
if provider == :stormondemand
require 'fog/storm_on_demand/account'
require "fog/storm_on_demand/account"
Fog::Account::StormOnDemand.new(attributes)
else
raise ArgumentError.new("#{provider} has no account service")
raise ArgumentError, "#{provider} has no account service"
end
end
def self.providers
Fog.services[:account]
end
end
end
module Fog
module Billing
def self.[](provider)
self.new(:provider => provider)
new(:provider => provider)
end
def self.new(attributes)
attributes = attributes.dup
provider = attributes.delete(:provider).to_s.downcase.to_sym
if provider == :stormondemand
require 'fog/storm_on_demand/billing'
require "fog/storm_on_demand/billing"
Fog::Billing::StormOnDemand.new(attributes)
else
raise ArgumentError.new("#{provider} has no billing service")
raise ArgumentError, "#{provider} has no billing service"
end
end
......
module Fog
module CDN
def self.[](provider)
self.new(:provider => provider)
new(:provider => provider)
end
def self.new(attributes)
attributes = attributes.dup # prevent delete from having side effects
provider = attributes.delete(:provider).to_s.downcase.to_sym
if self.providers.include?(provider)
if providers.include?(provider)
require "fog/#{provider}/cdn"
return Fog::CDN.const_get(Fog.providers[provider]).new(attributes)
end
raise ArgumentError.new("#{provider} is not a recognized cdn provider")
raise ArgumentError, "#{provider} is not a recognized cdn provider"
end
def self.providers
Fog.services[:cdn]
end
end
end
module Fog
module Compute
def self.[](provider)
self.new(:provider => provider)
new(:provider => provider)
end
def self.new(attributes)
attributes = attributes.dup # prevent delete from having side effects
provider = attributes.delete(:provider).to_s.downcase.to_sym
case provider
when :gogrid
require 'fog/go_grid/compute'
require "fog/go_grid/compute"
Fog::Compute::GoGrid.new(attributes)
when :hp
version = attributes.delete(:version)
version = version.to_s.downcase.to_sym unless version.nil?
if version == :v2
require 'fog/hp/compute_v2'
Fog::Compute::HPV2.new(attributes)
require "fog/hp/compute_v2"
Fog::Compute::HPV2.new(attributes)
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."
require 'fog/hp/compute'
require "fog/hp/compute"
Fog::Compute::HP.new(attributes)
end
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::Compute::BareMetalCloud.new(attributes)
when :baremetalcloud
require 'fog/bare_metal_cloud/compute'
require "fog/bare_metal_cloud/compute"
Fog::Compute::BareMetalCloud.new(attributes)
when :rackspace
version = attributes.delete(:version)
version = attributes.delete(:version)
version = version.to_s.downcase.to_sym unless version.nil?
if version == :v1
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)
else
require 'fog/rackspace/compute_v2'
require "fog/rackspace/compute_v2"
Fog::Compute::RackspaceV2.new(attributes)
end
when :stormondemand
require 'fog/storm_on_demand/compute'
require "fog/storm_on_demand/compute"
Fog::Compute::StormOnDemand.new(attributes)
when :vcloud
require 'fog/vcloud/compute'
require "fog/vcloud/compute"
Fog::Vcloud::Compute.new(attributes)
when :vclouddirector
require 'fog/vcloud_director/compute'
require "fog/vcloud_director/compute"
Fog::Compute::VcloudDirector.new(attributes)
else
if self.providers.include?(provider)
if providers.include?(provider)
require "fog/#{provider}/compute"
begin
Fog::Compute.const_get(Fog.providers[provider])
rescue
Fog::const_get(Fog.providers[provider])::Compute
Fog.const_get(Fog.providers[provider])::Compute
end.new(attributes)
else
raise ArgumentError.new("#{provider} is not a recognized compute provider")
raise ArgumentError, "#{provider} is not a recognized compute provider"
end
end
end
......@@ -72,7 +70,7 @@ module Fog
def self.servers
servers = []
for provider in self.providers
providers.each do |provider|
begin
servers.concat(self[provider].servers)
rescue # ignore any missing credentials/etc
......@@ -80,6 +78,5 @@ module Fog
end
servers
end
end
end
require 'fog/core/model'
require "fog/core/model"
module Fog
module Compute
class Server < Fog::Model
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
@username ||= 'root'
@username ||= "root"
end
def private_key_path
......@@ -35,20 +45,6 @@ module Fog
@ssh_port ||= 22
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.
# @return [String] IP Address
# @note By default this returns the public_ip_address
......@@ -60,16 +56,16 @@ module Fog
def ssh_options
@ssh_options ||= {}
ssh_options = @ssh_options.merge({:port => ssh_port})
ssh_options = @ssh_options.merge(:port => ssh_port)
if private_key
ssh_options[:key_data] = [private_key]
ssh_options[:auth_methods] = ["publickey"]
ssh_options[:auth_methods] = %w(publickey)
end
ssh_options
end
def scp(local_path, remote_path, upload_options = {})
require 'net/scp'
require "net/scp"
requires :ssh_ip_address, :username
Fog::SCP.new(ssh_ip_address, username, ssh_options).upload(local_path, remote_path, upload_options)
......@@ -78,14 +74,14 @@ module Fog
alias_method :scp_upload, :scp
def scp_download(remote_path, local_path, download_options = {})
require 'net/scp'
require "net/scp"
requires :ssh_ip_address, :username
Fog::SCP.new(ssh_ip_address, username, ssh_options).download(remote_path, local_path, download_options)
end
def ssh(commands, options={}, &blk)
require 'net/ssh'
def ssh(commands, options = {}, &blk)
require "net/ssh"
requires :ssh_ip_address, :username
options = ssh_options.merge(options)
......@@ -93,12 +89,11 @@ module Fog
Fog::SSH.new(ssh_ip_address, username, options).run(commands, &blk)
end
def sshable?(options={})
ready? && !ssh_ip_address.nil? && !!Timeout::timeout(8) { ssh('pwd', options) }
def sshable?(options = {})
ready? && !ssh_ip_address.nil? && !!Timeout.timeout(8) { ssh("pwd", options) }
rescue SystemCallError, Net::SSH::AuthenticationFailed, Net::SSH::Disconnect, Timeout::Error
false
end
end
end
end
# external core dependencies
require 'base64'
require 'cgi'
require 'uri'
require 'excon'
require 'fileutils'
require 'formatador'
require 'openssl'
require 'time'
require 'timeout'
require 'ipaddr'
require "base64"
require "cgi"
require "uri"
require "excon"
require "fileutils"
require "formatador"
require "openssl"
require "time"
require "timeout"
require "ipaddr"
# internal core dependencies
require "fog/core/version"
require 'fog/core/attributes'
require 'fog/core/attributes/default'
require 'fog/core/attributes/array'
require 'fog/core/attributes/boolean'
require 'fog/core/attributes/float'
require 'fog/core/attributes/integer'
require 'fog/core/attributes/string'
require 'fog/core/attributes/time'
require 'fog/core/attributes/timestamp'
require 'fog/core/associations/default'
require 'fog/core/associations/many_identities'
require 'fog/core/associations/many_models'
require 'fog/core/associations/one_model'
require 'fog/core/associations/one_identity'
require 'fog/core/collection'
require 'fog/core/connection'
require 'fog/core/credentials'
require 'fog/core/current_machine'
require 'fog/core/deprecation'
require 'fog/core/errors'
require 'fog/core/hmac'
require 'fog/core/logger'
require 'fog/core/model'
require 'fog/core/mock'
require 'fog/core/provider'
require 'fog/core/service'
require 'fog/core/ssh'
require 'fog/core/scp'
require 'fog/core/time'
require 'fog/core/utils'
require 'fog/core/wait_for'
require 'fog/core/wait_for_defaults'
require 'fog/core/uuid'
require 'fog/core/stringify_keys'
require 'fog/core/whitelist_keys'
require "fog/core/attributes"
require "fog/core/attributes/default"
require "fog/core/attributes/array"
require "fog/core/attributes/boolean"
require "fog/core/attributes/float"
require "fog/core/attributes/integer"
require "fog/core/attributes/string"
require "fog/core/attributes/time"
require "fog/core/attributes/timestamp"
require "fog/core/associations/default"
require "fog/core/associations/many_identities"
require "fog/core/associations/many_models"
require "fog/core/associations/one_model"
require "fog/core/associations/one_identity"
require "fog/core/collection"
require "fog/core/association"
require "fog/core/connection"
require "fog/core/credentials"
require "fog/core/current_machine"
require "fog/core/deprecation"
require "fog/core/errors"
require "fog/core/hmac"
require "fog/core/logger"
require "fog/core/model"
require "fog/core/mock"
require "fog/core/provider"
require "fog/core/service"
require "fog/core/ssh"
require "fog/core/scp"
require "fog/core/time"
require "fog/core/utils"
require "fog/core/wait_for"
require "fog/core/wait_for_defaults"
require "fog/core/uuid"
require "fog/core/stringify_keys"
require "fog/core/whitelist_keys"
# service wrappers
require 'fog/account'
require 'fog/billing'
require 'fog/cdn'
require 'fog/compute'
require 'fog/dns'
require 'fog/identity'
require 'fog/image'
require 'fog/metering'
require 'fog/monitoring'
require 'fog/network'
require 'fog/orchestration'
require 'fog/storage'
require 'fog/support'
require 'fog/volume'
require 'fog/vpn'
require "fog/account"
require "fog/billing"
require "fog/cdn"
require "fog/compute"
require "fog/dns"
require "fog/identity"
require "fog/image"
require "fog/metering"
require "fog/monitoring"
require "fog/network"
require "fog/orchestration"
require "fog/storage"
require "fog/support"
require "fog/volume"
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 Associations
# = Fog Default Association
#
# This class has the shared behavior between all association models.
class Default
attr_reader :model, :name
attr_reader :model, :name, :aliases, :as, :association_class
def initialize(model, name, collection_name)
def initialize(model, name, collection_name, options)
@model = model
@name = name
model.associations[name] = collection_name
@aliases = options.fetch(:aliases, [])
@as = options.fetch(:as, name)
@association_class = options.fetch(:association_class, Fog::Association)
create_setter
create_getter
create_aliases
create_mask
end
def create_aliases
Array(aliases).each do |alias_name|
model.aliases[alias_name] = name
end
end
def create_mask
model.masks[name] = as
end
end
end
end
\ No newline at end of file
end
module Fog
module Associations
# = Fog Multiple Association
#
# This class handles multiple association between the models.
# It expects the provider to return a collection of ids.
# The association models will be loaded based on the collection of ids.
class ManyIdentities < Default
def create_setter
model.class_eval <<-EOS, __FILE__, __LINE__
......@@ -15,12 +20,13 @@ module Fog
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}
return [] if associations[:#{name}].nil?
Array(associations[:#{name}]).map do |association|
data = Array(associations[:#{name}]).map do |association|
service.send(self.class.associations[:#{name}]).get(association)
end
#{association_class}.new(data)
end
EOS
end
end
end
end
\ No newline at end of file
end
module Fog
module Associations
# = Fog Multiple Association
#
# This class handles multiple association between the models.
# It expects the provider to map the attribute with a collection of objects.
class ManyModels < Default
def create_setter
model.class_eval <<-EOS, __FILE__, __LINE__
......@@ -12,10 +16,11 @@ module Fog
def create_getter
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}
Array(associations[:#{name}])
data = associations[:#{name}]
#{association_class}.new(data)
end
EOS
end
end
end
end
\ No newline at end of file
end
module Fog
module Associations
# = Fog Single Association
#
# This class handles single association between the models.
# It expects the provider to return only the id of the association.
# The association model will be loaded based on the id initialized.
class OneIdentity < Default
def create_setter
model.class_eval <<-EOS, __FILE__, __LINE__
......@@ -19,4 +24,4 @@ module Fog
end
end
end
end
\ No newline at end of file
end
module Fog
module Associations
# = Fog Single Association
#
# This class handles single association between the models.
# It expects the provider to map the attribute with an initialized object.
class OneModel < Default
def create_setter
model.class_eval <<-EOS, __FILE__, __LINE__
......@@ -18,4 +22,4 @@ module Fog
end
end
end
end
\ No newline at end of file
end
module Fog
module Attributes
module ClassMethods
def _load(marshalled)
new(Marshal.load(marshalled))
end
......@@ -22,45 +21,47 @@ module Fog
@default_values ||= {}
end
def masks
@masks ||= {}
end
def attribute(name, options = {})
type = options.fetch(:type, 'default').to_s.capitalize
Fog::Attributes::const_get(type).new(self, name, options)
type = options.fetch(:type, "default").to_s.capitalize
Fog::Attributes.const_get(type).new(self, name, options)
end