Module: KnuckleCluster

Extended by:
Forwardable, Scp
Defined in:
lib/knuckle_cluster.rb,
lib/knuckle_cluster/scp.rb,
lib/knuckle_cluster/task.rb,
lib/knuckle_cluster/agent.rb,
lib/knuckle_cluster/version.rb,
lib/knuckle_cluster/container.rb,
lib/knuckle_cluster/task_registry.rb,
lib/knuckle_cluster/ecs_agent_registry.rb,
lib/knuckle_cluster/asg_instance_registry.rb,
lib/knuckle_cluster/spot_request_instance_registry.rb

Defined Under Namespace

Modules: Scp Classes: Agent, AsgInstanceRegistry, Configuration, Container, EcsAgentRegistry, SpotRequestInstanceRegistry, Task, TaskRegistry

Constant Summary collapse

VERSION =
'2.0.0'

Class Method Summary collapse

Methods included from Scp

generate_agent_scp_string, generate_scp_connection_string, initiate_scp, scp_to_container, scp_with_agent

Class Method Details

.connect_to_agents(command: nil, auto: false) ⇒ Object



52
53
54
55
# File 'lib/knuckle_cluster.rb', line 52

def connect_to_agents(command: nil, auto: false)
  agent = select_agent(auto: auto)
  run_command_in_agent(agent: agent, command: command)
end

.connect_to_container(name:, command: 'bash') ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/knuckle_cluster.rb', line 62

def connect_to_container(name:, command: 'bash')
  if shortcut = shortcuts[name.to_sym]
    name = shortcut[:container]
    new_command = shortcut[:command]
    new_command += " #{command}" unless command == 'bash'
    command = new_command
  end

  container = find_container(name: name)
  run_command_in_container(container: container, command: command)
end

.connect_to_containers(command: 'bash', auto: false) ⇒ Object



57
58
59
60
# File 'lib/knuckle_cluster.rb', line 57

def connect_to_containers(command: 'bash', auto: false)
  container = select_container(auto: auto)
  run_command_in_container(container: container, command: command)
end

.container_logs(name:) ⇒ Object



74
75
76
77
78
# File 'lib/knuckle_cluster.rb', line 74

def container_logs(name:)
  container = find_container(name: name)
  subcommand = "#{'sudo ' if sudo}docker logs -f \\`#{get_container_id_command(container.name)}\\`"
  run_command_in_agent(agent: container.task.agent, command: subcommand)
end

.new(cluster_name: nil, spot_request_id: nil, asg_name: nil, region: 'us-east-1', bastion: nil, rsa_key_location: nil, ssh_username: 'ec2-user', sudo: false, aws_vault_profile: nil, shortcuts: {}, tunnels: {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/knuckle_cluster.rb', line 22

def new(
    cluster_name: nil,
    spot_request_id: nil,
    asg_name: nil,
    region: 'us-east-1',
    bastion: nil,
    rsa_key_location: nil,
    ssh_username: 'ec2-user',
    sudo: false,
    aws_vault_profile: nil,
    shortcuts: {},
    tunnels: {})
  @cluster_name      = cluster_name
  @spot_request_id   = spot_request_id
  @asg_name          = asg_name
  @region            = region
  @bastion           = bastion
  @rsa_key_location  = rsa_key_location
  @ssh_username      = ssh_username
  @sudo              = sudo
  @aws_vault_profile = aws_vault_profile
  @shortcuts         = shortcuts
  @tunnels           = tunnels

  if @cluster_name.nil? && @spot_request_id.nil? && @asg_name.nil?
    raise "Must specify either cluster_name, spot_request_id or asg name"
  end
  self
end

.open_tunnel(name:) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/knuckle_cluster.rb', line 80

def open_tunnel(name:)
  if tunnel = tunnels[name.to_sym]
    agent = select_agent(auto: true)
    open_tunnel_via_agent(tunnel.merge(agent: agent))
  else
    puts "ERROR: A tunnel configuration was not found for '#{name}'"
  end
end