Class: Cloudmaster::PoolConfiguration

Inherits:
Object
  • Object
show all
Defined in:
app/pool_configuration.rb

Overview

PoolConfiguration holds the configuration parameters for one pool. It also stores aws parameters and defaults, providing a single lookup mechanism for all. If lookup files, then it raise an exception.

Instance Method Summary collapse

Constructor Details

#initialize(aws_config, default, config) ⇒ PoolConfiguration

Create a new PoolConfiguration. The default parameters are used if the desired parameter is not given.



85
86
87
88
89
90
91
92
# File 'app/pool_configuration.rb', line 85

def initialize(aws_config, default, config)
  # these parameters merge the defaults and the given parbameters
  # merged parameters are also evaluated
  @merge_params = [:user_data]
  @aws_config = aws_config
  @default = default
  @config = config
end

Instance Method Details

#[](param) ⇒ Object

Get a parameter, either from config or from default. Raise an exception if there is none.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/pool_configuration.rb', line 102

def [](param)
  if @default.nil?
    raise "Missing defaults"
  end
  config_param = @aws_config[param] || @config[param]
  if (res = config_param || @default[param]).nil?
    raise "Missing config: #{param}"
  end
  begin
    if @merge_params.include?(param)
	 # fix up default param if needed -- it must be a hash
	  @default[param] = {} if @default[param].nil? 
      @default[param] = eval(@default[param]) if @default[param].is_a?(String)
      if config_param 
        @default[param].merge(eval(config_param))
	  else
        @default[param]
	  end
    else
      res
    end
  rescue
    raise "Config bad format: #{param} #{config_param} #{$!}"
  end
end

#[]=(param, val) ⇒ Object

Store (create or replace) a parameter.



129
130
131
# File 'app/pool_configuration.rb', line 129

def []=(param, val)
  @config[param] = val
end

#append_env(name) ⇒ Object



133
134
135
136
# File 'app/pool_configuration.rb', line 133

def append_env(name)
  aws_env = @aws_config[:aws_env]
  aws_env.nil? || aws_env == '' ? name : "#{name}-#{aws_env}"
end

#get(param) ⇒ Object

Get a parameter, either from aws_config, config or default. Don’t raise an exception if there is no value.



96
97
98
# File 'app/pool_configuration.rb', line 96

def get(param)
  @aws_config[param] || @config[param] || @default[param]
end

#setup_image(key, name) ⇒ Object

Looks up the image, given its name. Stores the result in config under the given key (if given). Returns the image. Raises an exception if none found.



162
163
164
165
166
167
168
169
# File 'app/pool_configuration.rb', line 162

def setup_image(key, name)
  return nil unless name
  name = append_env(@config[name])
  image = EC2ImageEnumerator.new.find_image_id_by_name(name)
  raise "Bad configuration -- no image #{name}" if !image
  @config[key] = image if key
  image
end

#setup_queue(key, name) ⇒ Object

Looks up a queue given its name. Stores the result in config under the given key (if given). Returns the queue. Raises an exception if none found.



149
150
151
152
153
154
155
156
# File 'app/pool_configuration.rb', line 149

def setup_queue(key, name)
  return nil unless name
  name = append_env(@config[name])
  queue = NamedQueue.new(name)
  raise "Bad configuration -- no queue #{name}" if !queue
  @config[key] = queue if key
  queue
end

#valid?Boolean

Test to see that the derived parameters are valid.

Returns:

  • (Boolean)


139
140
141
142
143
# File 'app/pool_configuration.rb', line 139

def valid?
  @config[:ami_id] && 
    @config[:work_queue] && @config[:work_queue].valid? && 
    @config[:status_queue] && @config[:status_queue].valid?
end