Module: Fog

Defined in:
lib/fog/test_helpers/formats_helper.rb,
lib/fog/cdn.rb,
lib/fog/dns.rb,
lib/fog/vpn.rb,
lib/fog/image.rb,
lib/fog/volume.rb,
lib/fog/account.rb,
lib/fog/billing.rb,
lib/fog/compute.rb,
lib/fog/network.rb,
lib/fog/storage.rb,
lib/fog/support.rb,
lib/fog/version.rb,
lib/fog/core/scp.rb,
lib/fog/core/ssh.rb,
lib/fog/identity.rb,
lib/fog/metering.rb,
lib/fog/core/hmac.rb,
lib/fog/core/mock.rb,
lib/fog/core/time.rb,
lib/fog/core/uuid.rb,
lib/fog/core/model.rb,
lib/fog/monitoring.rb,
lib/fog/core/errors.rb,
lib/fog/core/logger.rb,
lib/tasks/test_task.rb,
lib/fog/core/service.rb,
lib/fog/core/provider.rb,
lib/fog/core/wait_for.rb,
lib/fog/orchestration.rb,
lib/fog/core/attributes.rb,
lib/fog/core/collection.rb,
lib/fog/core/connection.rb,
lib/fog/core/credentials.rb,
lib/fog/core/deprecation.rb,
lib/fog/core/current_machine.rb,
lib/fog/compute/models/server.rb,
lib/fog/schema/data_validator.rb,
lib/fog/core/wait_for_defaults.rb,
lib/fog/core/deprecated_connection_accessors.rb

Overview

format related hackery allows both true.is_a?(Fog::Boolean) and false.is_a?(Fog::Boolean) allows both nil.is_a?(Fog::Nullable::String) and ”.is_a?(Fog::Nullable::String)

Defined Under Namespace

Modules: Account, Attributes, Billing, Boolean, CDN, Compute, Core, DNS, Deprecation, Errors, Identity, Image, Metering, Mock, Monitoring, Network, Nullable, Orchestration, Provider, Rake, SCP, SSH, Schema, Storage, Support, VPN, Volume Classes: Collection, CurrentMachine, HMAC, Logger, Model, PagedCollection, Service, Time, UUID

Constant Summary collapse

VERSION =
"1.22.0"

Class Method Summary collapse

Class Method Details

.credentialSymbol

Note:

This can be set using the FOG_CREDENTIAL environment variable

This is the named credential from amongst the configuration file being used or :default

Returns:

  • (Symbol)

    The credential to use in Fog



40
41
42
# File 'lib/fog/core/credentials.rb', line 40

def self.credential
  @credential ||= ( ENV["FOG_CREDENTIAL"] && ENV["FOG_CREDENTIAL"].to_sym ) || :default
end

.credential=(new_credential) ⇒ Symbol

Assign a new credential to use from configuration file

Parameters:

  • new_credential (String, Symbol)

    name of new credential to use

Returns:

  • (Symbol)

    name of the new credential



30
31
32
33
# File 'lib/fog/core/credentials.rb', line 30

def self.credential=(new_credential)
  @credentials = nil
  @credential = new_credential && new_credential.to_sym
end

.credentialsHash

Returns The credentials pulled from the configuration file.

Returns:

  • (Hash)

    The credentials pulled from the configuration file

Raises:

  • (LoadError)

    Configuration unavailable in configuration file



67
68
69
70
71
72
73
74
75
76
# File 'lib/fog/core/credentials.rb', line 67

def self.credentials
  @credentials ||= begin
    if credentials_path && File.exists?(credentials_path)
      credentials = Fog::Core::Utils.prepare_service_settings(YAML.load_file(credentials_path))
      (credentials && credentials[credential]) || Fog::Errors.missing_credentials
    else
      {}
    end
  end
end

.credentials=(new_credentials) ⇒ Hash

Sets the global configuration up from a Hash rather than using background loading from a file

Examples:

Fog.credentials = {
  :default => {
    :example_url => "https://example.com/"
    :example_username => "bob",
    :example_password => "obo"
  },
  :production => {
    :example_username => "bob",
    :example_password => "obo"
  }
}

Returns:

  • (Hash)

    The newly assigned credentials



22
23
24
# File 'lib/fog/core/credentials.rb', line 22

def self.credentials=(new_credentials)
  @credentials = new_credentials
end

.credentials_pathString

Note:

This can be set using the FOG_RC environment variable or defaults to $HOME/.fog

This returns the path to the configuration file being used globally to look for sets of credentials

Returns:

  • (String)

    The path for configuration_file



50
51
52
53
54
55
56
57
# File 'lib/fog/core/credentials.rb', line 50

def self.credentials_path
  @credential_path ||= begin
    path = ENV["FOG_RC"] || (ENV['HOME'] && File.directory?(ENV['HOME']) && '~/.fog')
    File.expand_path(path) if path
  rescue
    nil
  end
end

.credentials_path=(new_credentials_path) ⇒ String

Returns The new path for credentials file.

Returns:

  • (String)

    The new path for credentials file



60
61
62
63
# File 'lib/fog/core/credentials.rb', line 60

def self.credentials_path=(new_credentials_path)
  @credentials = nil
  @credential_path = new_credentials_path
end

.intervalObject



3
4
5
# File 'lib/fog/core/wait_for_defaults.rb', line 3

def self.interval
  @interval
end

.interval=(interval) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/fog/core/wait_for_defaults.rb', line 7

def self.interval=(interval)
  if interval.kind_of?(Proc)
    raise ArgumentError, "interval proc must return a positive" unless interval.call(1) >= 0
  else
    raise ArgumentError, "interval must be non-negative" unless interval >= 0
  end
  @interval = interval
end

.max_intervalObject



27
28
29
# File 'lib/fog/core/wait_for_defaults.rb', line 27

def self.max_interval
  @max_interval
end

.max_interval=(interval) ⇒ Object

Raises:

  • (ArgumentError)


31
32
33
34
# File 'lib/fog/core/wait_for_defaults.rb', line 31

def self.max_interval=(interval)
  raise ArgumentError, "interval must be non-negative" unless interval >= 0
  @max_interval = interval
end

.mock!Object



5
6
7
# File 'lib/fog/core/mock.rb', line 5

def self.mock!
  @mocking = true
end

.mock?Boolean

Returns:



13
14
15
# File 'lib/fog/core/mock.rb', line 13

def self.mock?
  @mocking
end

.mocking?Boolean

Returns:



17
18
19
# File 'lib/fog/core/mock.rb', line 17

def self.mocking?
  @mocking
end

.providersObject



3
4
5
# File 'lib/fog/core/provider.rb', line 3

def self.providers
  @providers ||= {}
end

.providers=(new_providers) ⇒ Object



7
8
9
# File 'lib/fog/core/provider.rb', line 7

def self.providers=(new_providers)
  @providers = new_providers
end

.servicesObject



4
5
6
# File 'lib/fog/core/service.rb', line 4

def self.services
  @services ||= {}
end

.symbolize_credential?(key) ⇒ true

Deprecated.

Don’t use!

Returns if key == :headers.

Parameters:

  • key (Object)

Returns:

  • (true)

    if key == :headers



81
82
83
# File 'lib/fog/core/credentials.rb', line 81

def self.symbolize_credential?(key)
  ![:headers].include?(key)
end

.symbolize_credentials(hash) ⇒ Object



86
87
88
# File 'lib/fog/core/credentials.rb', line 86

def self.symbolize_credentials(hash)
  Fog::Core::Utils.prepare_service_settings(hash)
end

.timeoutObject



17
18
19
# File 'lib/fog/core/wait_for_defaults.rb', line 17

def self.timeout
  @timeout
end

.timeout=(timeout) ⇒ Object

Raises:

  • (ArgumentError)


21
22
23
24
# File 'lib/fog/core/wait_for_defaults.rb', line 21

def self.timeout=(timeout)
  raise ArgumentError, "timeout must be non-negative" unless timeout >= 0
  @timeout = timeout
end

.unmock!Object



9
10
11
# File 'lib/fog/core/mock.rb', line 9

def self.unmock!
  @mocking = false
end

.wait_for(timeout = Fog.timeout, interval = Fog.interval, &block) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/fog/core/wait_for.rb', line 2

def self.wait_for(timeout=Fog.timeout, interval=Fog.interval, &block)
  duration = 0
  start = Time.now
  retries = 0
  until yield || duration > timeout
    sleep(interval.respond_to?(:call) ? interval.call(retries += 1).to_f : interval.to_f)
    duration = Time.now - start
  end
  if duration > timeout
    raise Errors::TimeoutError.new("The specified wait_for timeout (#{timeout} seconds) was exceeded")
  else
    { :duration => duration }
  end
end