Class: PoolParty::Base

Inherits:
Object show all
Extended by:
MethodMissingSugar
Includes:
Configurable
Defined in:
lib/poolparty/pool/base.rb,
lib/poolparty/base_packages/ruby.rb,
lib/poolparty/base_packages/haproxy.rb,
lib/poolparty/base_packages/heartbeat.rb,
lib/poolparty/base_packages/poolparty.rb

Class Method Summary collapse

Methods included from MethodMissingSugar

get_from_options, method_missing

Methods included from Configurable

included

Class Method Details

.access_key ⇒ Object

Get the access_key



40
41
42
# File 'lib/poolparty/pool/base.rb', line 40

def access_key
  ENV["AWS_ACCESS_KEY_ID"] ? ENV["AWS_ACCESS_KEY_ID"] : load_keys_from_file[:access_key]
end

.actionable_default_options ⇒ Object



33
34
35
# File 'lib/poolparty/pool/base.rb', line 33

def actionable_default_options
  default_options.merge!({:access_key => self.access_key,:secret_access_key => secret_access_key})
end

.get_working_key_file_locations ⇒ Object

Get the instance first instance file that exists on the system from the expected places denoted in the local_instances_list_file_locations



59
60
61
# File 'lib/poolparty/pool/base.rb', line 59

def get_working_key_file_locations
  key_file_locations.reject {|f| f unless ::File.file?(f) }.first
end

.key_file_locations ⇒ Object

Expected places for the instances.list to be located at on the machine



63
64
65
66
67
68
69
70
# File 'lib/poolparty/pool/base.rb', line 63

def key_file_locations
  [
    "#{Base.storage_directory}/.ppkeys",
    "#{Base.base_config_directory}/.ppkeys",
    "~/.ppkeys",
    "ppkeys"
  ]
end

.load_keys_from_file ⇒ Object



46
47
48
# File 'lib/poolparty/pool/base.rb', line 46

def load_keys_from_file
  @keys ||= get_working_key_file_locations ? YAML::load( open(get_working_key_file_locations).read ) : {}
end

.options(h = {}) ⇒ Object



36
37
38
# File 'lib/poolparty/pool/base.rb', line 36

def options(h={})
  @options ||= actionable_default_options.merge(h)
end

.reset! ⇒ Object



54
55
56
# File 'lib/poolparty/pool/base.rb', line 54

def reset!
  @keys = nil
end

.secret_access_key ⇒ Object



43
44
45
# File 'lib/poolparty/pool/base.rb', line 43

def secret_access_key
  ENV["AWS_SECRET_ACCESS_ID"] ? ENV["AWS_SECRET_ACCESS_ID"] : load_keys_from_file[:secret_access_key]
end

.store_keys_in_file ⇒ Object



49
50
51
52
53
# File 'lib/poolparty/pool/base.rb', line 49

def store_keys_in_file
  unless access_key.nil? || secret_access_key.nil?
    write_to_file( key_file_locations.first, YAML::dump({:access_key => access_key, :secret_access_key => secret_access_key}))        
  end
end