Class: ChefMetal::OpenstackCredentials

Inherits:
Object
  • Object
show all
Defined in:
lib/chef_metal/openstack_credentials.rb

Overview

Reads in a credentials file

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOpenstackCredentials

Returns a new instance of OpenstackCredentials.



4
5
6
# File 'lib/chef_metal/openstack_credentials.rb', line 4

def initialize
  @credentials = {}
end

Class Method Details

.method_missing(name, *args, &block) ⇒ Object



36
37
38
# File 'lib/chef_metal/openstack_credentials.rb', line 36

def self.method_missing(name, *args, &block)
  singleton.send(name, *args, &block)
end

.singletonObject



40
41
42
# File 'lib/chef_metal/openstack_credentials.rb', line 40

def self.singleton
  @openstack_credentials ||= OpenstackCredentials.new
end

Instance Method Details

#[](name) ⇒ Object



16
17
18
# File 'lib/chef_metal/openstack_credentials.rb', line 16

def [](name)
  @credentials[name]
end

#defaultObject



8
9
10
# File 'lib/chef_metal/openstack_credentials.rb', line 8

def default
  @credentials['default'] || @credentials.first[1]
end

#keysObject



12
13
14
# File 'lib/chef_metal/openstack_credentials.rb', line 12

def keys
  @credentials.keys
end

#load_defaultObject



32
33
34
# File 'lib/chef_metal/openstack_credentials.rb', line 32

def load_default
  load_yaml('~/.fog')
end

#load_yaml(credentials_yaml_file) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/chef_metal/openstack_credentials.rb', line 20

def load_yaml(credentials_yaml_file)
  creds_file = YAML.load_file(File.expand_path(credentials_yaml_file))
  creds_file.each do |section, creds|
    @credentials[section] = {
      :openstack_username => creds_file[section]['openstack_username'],
      :openstack_api_key => creds_file[section]['openstack_api_key'],
      :openstack_tenant => creds_file[section]['openstack_tenant'],
      :openstack_auth_url => creds_file[section]['openstack_auth_url']
    }
  end
end