Module: Kontena::Cli::Stacks::Common::StackValuesFromOption::InstanceMethods

Defined in:
lib/kontena/cli/stacks/common.rb

Instance Method Summary collapse

Instance Method Details

#dependency_values_from_options(name) ⇒ Object

Transforms a hash dependency_values_from_options(‘foo.bar’ => 1, ‘foo’)

=> { 'bar' => 1 }

Used for dependency variable injection



159
160
161
162
163
164
165
166
167
# File 'lib/kontena/cli/stacks/common.rb', line 159

def dependency_values_from_options(name)
  name_with_dot = name.to_s + '.'
  values_from_options.each_with_object({}) do |kv_pair, obj|
    key = kv_pair.first.to_s
    value = kv_pair.last
    next unless key.start_with?(name_with_dot)
    obj[key.sub(name_with_dot, '')] = value
  end
end

#read_values_from_stacks(stackname) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/kontena/cli/stacks/common.rb', line 118

def read_values_from_stacks(stackname)
  result = {}
  response = client.get("stacks/#{current_grid}/#{stackname}")
  result.merge!(response['variables']) if response['variables']
  if response['children']
    response['children'].each do |child_info|
      result.merge!(
        read_values_from_stacks(child_info['name']).tap do |child_result|
          child_result.keys.each do |key|
            new_key = child_info['name'].dup # foofoo-redis-monitor
            new_key.sub!("#{stackname}-", '') # monitor
            new_key.concat ".#{key}" # monitor.foovariable
            child_result[new_key] = child_result.delete(key)
          end
        end
      )
    end
  end
  result
end

#values_from_fileObject



139
140
141
# File 'lib/kontena/cli/stacks/common.rb', line 139

def values_from_file
  @values_from_file ||= {}
end

#values_from_installed_stacksObject



147
148
149
# File 'lib/kontena/cli/stacks/common.rb', line 147

def values_from_installed_stacks
  @values_from_installed_stacks ||= {}
end

#values_from_optionsObject



151
152
153
# File 'lib/kontena/cli/stacks/common.rb', line 151

def values_from_options
  @values_from_options ||= values_from_installed_stacks.merge(values_from_file).merge(values_from_value_options)
end

#values_from_value_optionsObject



143
144
145
# File 'lib/kontena/cli/stacks/common.rb', line 143

def values_from_value_options
  @values_from_value_options ||= {}
end