Class: Exos::Commands::Keys::Bastions

Inherits:
Object
  • Object
show all
Defined in:
lib/exos/commands/keys.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.roleObject

Returns the value of attribute role.



247
248
249
# File 'lib/exos/commands/keys.rb', line 247

def role
  @role
end

Class Method Details

.allObject



249
250
251
252
253
254
255
256
257
258
259
# File 'lib/exos/commands/keys.rb', line 249

def all
  @all ||= begin
    bastions = ec2.servers.all("tag:Role" => role).map do |bastion|
      bastion.username = "deploy"
      bastion
    end

    abort "No bastions found with role '#{ options.role }'." unless bastions.any?
    bastions
  end
end

.ec2Object



279
280
281
# File 'lib/exos/commands/keys.rb', line 279

def ec2
  @ec2 ||= ::Fog::Compute::AWS.new
end

.exec(*cmds) ⇒ Object



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/exos/commands/keys.rb', line 261

def exec(*cmds)
  results = []

  all.each do |bastion|
    if bastion.ssh("ls #{ LOCKFILE_NAME }").first.status == 0
      abort "Another `exos keys` operation is in progress."
    end

    commands = ["touch #{ LOCKFILE_NAME }", *cmds, "rm #{ LOCKFILE_NAME }"]
    results << bastion.ssh(commands)
  end

  results.last[-2]
# Ensure to handle Fog::SSH raising on SSH connection errors.
ensure
  all.each { |b| b.ssh("rm #{ LOCKFILE_NAME }") }
end