Module: Kontena::Plugin::Aws::Prompts

Defined Under Namespace

Modules: Common

Instance Method Summary collapse

Instance Method Details

#ask_nodeObject



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/kontena/plugin/aws/prompts.rb', line 153

def ask_node
  if self.name.nil?
    nodes = client.get("grids/#{current_grid}/nodes")
    nodes = nodes['nodes'].select{ |n|
      n['labels'] && n['labels'].include?('provider=aws'.freeze)
    }
    raise "Did not find any nodes with label provider=aws" if nodes.size == 0
    prompt.select("Select node:") do |menu|
      nodes.sort_by{ |n| n['node_number'] }.reverse.each do |node|
        initial = node['initial_member'] ? '(initial) ' : ''
        menu.choice "#{node['name']} #{initial}", node['name']
      end
    end
  else
    self.name
  end
end

#aws_clientObject



4
5
6
# File 'lib/kontena/plugin/aws/prompts.rb', line 4

def aws_client
  @aws_client ||= Aws::EC2::Client.new(access_key_id: access_key, secret_access_key: secret_key, region: region)
end

#resolve_region(node) ⇒ Object



171
172
173
174
175
176
177
# File 'lib/kontena/plugin/aws/prompts.rb', line 171

def resolve_region(node)
  return nil if node.nil? || node['labels'].nil?
  node['labels'].each do |label|
    tag, value = label.split('=', 2)
    return value if tag == 'region'
  end
end