Class: PoolParty::Default

Inherits:
Object show all
Includes:
Dslify
Defined in:
lib/poolparty/poolparty/default.rb

Class Method Summary collapse

Class Method Details

.access_keyObject

# Get the access_key



57
58
59
# File 'lib/poolparty/poolparty/default.rb', line 57

def access_key
  @access_key ||= load_access_keys_from_environment_var || load_keys_from_file[:access_key]
end

.custom_modules_directoriesObject



149
150
151
152
153
154
155
# File 'lib/poolparty/poolparty/default.rb', line 149

def custom_modules_directories
  [
    "/var/poolparty/modules",
    "/etc/poolparty/modules",
    "#{Dir.pwd}/modules"
  ].select {|d| d if viable_directory?(d) }
end

.custom_monitor_directoriesObject



141
142
143
144
145
146
147
# File 'lib/poolparty/poolparty/default.rb', line 141

def custom_monitor_directories
  [
    "/var/poolparty/monitors",
    "/etc/poolparty/monitors",
    "#{Dir.pwd}/monitors"
  ].select {|d| d if viable_directory?(d) }
end

.get_working_key_file_locationsObject

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



98
99
100
# File 'lib/poolparty/poolparty/default.rb', line 98

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

.key_file_locationsObject

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



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/poolparty/poolparty/default.rb', line 102

def key_file_locations
  [
    ".ppkeys",
    "#{Default.base_config_directory}/.ppkeys",
    "#{Default.storage_directory}/ppkeys",
    "#{ENV["HOME"]}/.ssh/ppkeys",
    "#{ENV["HOME"]}/.ssh/.ppkeys",
    "~/.ppkeys",
    "ppkeys"
  ]
end

.keys_in_yamlObject



82
83
84
# File 'lib/poolparty/poolparty/default.rb', line 82

def keys_in_yaml
  YAML::dump({:access_key => access_key, :secret_access_key => secret_access_key})
end

.load_access_keys_from_environment_varObject



60
61
62
# File 'lib/poolparty/poolparty/default.rb', line 60

def load_access_keys_from_environment_var
  [ ENV["AWS_ACCESS_KEY"], ENV["AWS_ACCESS_KEY_ID"]].reject {|a| a.nil? }.first
end

.load_keys_from_fileObject



72
73
74
# File 'lib/poolparty/poolparty/default.rb', line 72

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

.load_secret_access_keys_from_environment_varObject



66
67
68
# File 'lib/poolparty/poolparty/default.rb', line 66

def load_secret_access_keys_from_environment_var
  [ ENV["AWS_SECRET_ACCESS_KEY"] ].reject {|a| a.nil? }.first
end

.logger_locationObject



129
130
131
132
133
134
135
# File 'lib/poolparty/poolparty/default.rb', line 129

def logger_location
  [
      "/var/log/poolparty"
  ].select do |dir|
    dir if viable_directory?(dir)
  end.first
end

.method_missing(m, *a, &block) ⇒ Object



53
54
55
# File 'lib/poolparty/poolparty/default.rb', line 53

def method_missing(m,*a,&block)
  dsl_options.include?(m) ? dsl_options[m] : super
end

.pool_logger_locationObject

Assume the logs will be at the pool.log location within the logger_location set above



138
139
140
# File 'lib/poolparty/poolparty/default.rb', line 138

def pool_logger_location
  ::File.join(logger_location, "poolparty.log")
end

.properties_hash_fileObject



113
114
115
116
117
118
119
120
121
# File 'lib/poolparty/poolparty/default.rb', line 113

def properties_hash_file
  [
    Default.base_config_directory,
    Dir.pwd
  ].collect do |dir|
    full_dir = ::File.join(dir, Default.properties_hash_filename)
    full_dir if ::File.file?(full_dir)
  end.compact.first || "#{Default.base_config_directory}/#{Default.properties_hash_filename}"
end

.read_keyfileObject



69
70
71
# File 'lib/poolparty/poolparty/default.rb', line 69

def read_keyfile
  open(get_working_key_file_locations).read
end

.reset!Object



92
93
94
# File 'lib/poolparty/poolparty/default.rb', line 92

def reset!
  @keys = nil
end

.secret_access_keyObject



63
64
65
# File 'lib/poolparty/poolparty/default.rb', line 63

def secret_access_key
  @secret_access_key ||= load_secret_access_keys_from_environment_var || load_keys_from_file[:secret_access_key]
end

.storage_directoryObject



122
123
124
125
126
127
128
# File 'lib/poolparty/poolparty/default.rb', line 122

def storage_directory
  [
      "/var/poolparty"
  ].select do |dir|
    dir if viable_directory?(dir)
  end.first || ::File.join( "/tmp/poolparty/#{name}")
end

.store_keys_in_file(f = nil) ⇒ Object

Store the keys in a yaml format to give the master access So that the master has access to the files



77
78
79
80
81
# File 'lib/poolparty/poolparty/default.rb', line 77

def store_keys_in_file(f=nil)
  unless access_key.nil? || secret_access_key.nil?
    write_to_file( (f ? f : key_file_locations.first), keys_in_yaml)
  end
end

.store_keys_in_file_for(obj = nil) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/poolparty/poolparty/default.rb', line 85

def store_keys_in_file_for(obj=nil)
  if obj
    @access_key = obj.access_key
    @secret_access_key = obj.secret_access_key
  end
  store_keys_in_file
end

.viable_directory?(dir) ⇒ Boolean

Only return true if the directory we are reading is both readable and exists

Returns:

  • (Boolean)


158
159
160
# File 'lib/poolparty/poolparty/default.rb', line 158

def viable_directory?(dir)
  ::File.directory?(dir) && ::File.readable?(dir)
end