knuckle_cluster 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1f4c2401bd2ba5e45bde345234fea0af87f75d2
4
- data.tar.gz: 23cb6fb4cddbfd168e5940463387104445720bf2
3
+ metadata.gz: d4179fb4fe181bb800defdb0634691c7c85f9c63
4
+ data.tar.gz: e3c7e7786cba37a32531d4425dbed70e7713936c
5
5
  SHA512:
6
- metadata.gz: d8c7e0fc10f7d44b0269ac8c9317a25ba08c6f2f2e96b084ee58d89713791ca9960ca40cc6f834ad423d9b09fce130af7f344d08376a2971a4a2e01a53312f99
7
- data.tar.gz: 4ef267008c44f2550a64d41bd40d6b9bb37bb6290770dc69704fd6024c3a6f43d4ff9de135a00d48908eeb6332ebcd112d0ee8d2d73b2fa091a6f4c58404697e
6
+ metadata.gz: e09f159cae31ec646190f7c31457956c2b797e15e4e7f79096b03f0892171382d62b5eb5e58e62de3ccb62383bb629a07f8c06282ce708cf51c3be6336f54e1e
7
+ data.tar.gz: 2c9fd926e86258191a459ae27df48c360ccd7b11bbeb3371ec0907b7eaabe2de9cc2c57fc2c2395be130e6ec9f1afec46070b0d0a35bec984aea05c3f0a77284
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Have you ever wanted to shuck away the hard, rough exterior of an ECS cluster and get to the soft, chewy innards? Sounds like you need KnuckleCluster!
4
4
  This tool provides scripts, invoked via cli or rakefile, to list, connect to and/or run commands on ecs agents and containers via ssh. This makes it very easy to interrogate ECS agents and containers without having to go digging for IP addresses and things.
5
+ Primarily created as a tool to connect to instances in an ECS cluster and see what is running on them, it has evolved slightly to include the ability to list instances in spot requests and auto-scaling groups.
5
6
 
6
7
  ## Features
7
8
  * See what agents in your ECS cluster are doing
@@ -11,7 +12,7 @@ This tool provides scripts, invoked via cli or rakefile, to list, connect to and
11
12
  * Optionally integrates with [aws-vault](https://github.com/99designs/aws-vault) for AWS authentication
12
13
 
13
14
  ## Development Status
14
- Is being used in production for various projects and is considered stable. Any new features/bug fixes etc are most welcome! Test coverage is minimal...
15
+ Is being used in production for various projects and is considered stable. Any new features/bug fixes etc are most welcome!
15
16
 
16
17
  ## Installation
17
18
 
@@ -185,8 +186,9 @@ Possible options are below. If left blank, they will be ignored and defaults use
185
186
 
186
187
  Argument | Description
187
188
  -------- | -----------
188
- cluster_name | The name of the cluster (not the ARN). eg 'my-super-cluster'. Required (unless using spot_request_id)
189
- spot_request_id | The spot request ID you are connecting to. eg 'sfr-abcdef'. Required (unless using cluster_name)
189
+ cluster_name | The name of the cluster (not the ARN). eg 'my-super-cluster'. One of `cluster_name`,`spot_request_id` or `asg_name` is required.
190
+ spot_request_id | The spot request ID you are connecting to. eg 'sfr-abcdef'. One of `cluster_name`,`spot_request_id` or `asg_name` is required.
191
+ asg_name | The spot request ID you are connecting to. eg 'sfr-abcdef'. One of `cluster_name`,`spot_request_id` or `asg_name` is required.
190
192
  region | The AWS region you would like to use. Defaults to `us-east-1`
191
193
  bastion | if you have a bastion to proxy to your ecs cluster via ssh, put the name of it here as defined in your `~/.ssh/config` file.
192
194
  rsa_key_location | The RSA key needed to connect to an ecs agent eg `~/.ssh/id_rsa`.
@@ -196,7 +198,10 @@ aws_vault_profile | If you use the `aws-vault` tool to manage your AWS credentia
196
198
  profile | Another profile to inherit settings from. Settings from lower profiles can be overridden in higher ones.
197
199
 
198
200
  ## Spot Fleets
199
- If you wish to see what instances are running within a spot fleet, KnuckleCluster can do that too!. In your config, use `spot_request_id` instead of `cluster_name`. Note that the `containers` command will not work when invoking.
201
+ If you wish to see what instances are running within a spot fleet, KnuckleCluster can do that too!. In your config, use `spot_request_id` instead of `cluster_name`. Note that the `containers` command will not work when invoking (use `agents` instead).
202
+
203
+ ## AutoScaling Groups
204
+ If you wish to see what instances are running within an ASG, KnuckleCluster can do that too!. In your config, use `asg_name` instead of `cluster_name`. Note that the `containers` command will not work when invoking (use `agents` instead).
200
205
 
201
206
  ## Maintainer
202
207
  [Envato](https://github.com/envato)
@@ -1,3 +1,4 @@
1
+ require 'knuckle_cluster/asg_instance_registry'
1
2
  require 'knuckle_cluster/ecs_agent_registry'
2
3
  require 'knuckle_cluster/spot_request_instance_registry'
3
4
  require "knuckle_cluster/version"
@@ -14,6 +15,7 @@ module KnuckleCluster
14
15
  def new(
15
16
  cluster_name: nil,
16
17
  spot_request_id: nil,
18
+ asg_name: nil,
17
19
  region: 'us-east-1',
18
20
  bastion: nil,
19
21
  rsa_key_location: nil,
@@ -24,6 +26,7 @@ module KnuckleCluster
24
26
  tunnels: {})
25
27
  @cluster_name = cluster_name
26
28
  @spot_request_id = spot_request_id
29
+ @asg_name = asg_name
27
30
  @region = region
28
31
  @bastion = bastion
29
32
  @rsa_key_location = rsa_key_location
@@ -33,8 +36,8 @@ module KnuckleCluster
33
36
  @shortcuts = shortcuts
34
37
  @tunnels = tunnels
35
38
 
36
- if @cluster_name.nil? && @spot_request_id.nil?
37
- raise "Must specify either cluster_name or spot_request_id"
39
+ if @cluster_name.nil? && @spot_request_id.nil? && @asg_name.nil?
40
+ raise "Must specify either cluster_name, spot_request_id or asg name"
38
41
  end
39
42
  self
40
43
  end
@@ -78,7 +81,8 @@ module KnuckleCluster
78
81
 
79
82
  private
80
83
 
81
- attr_reader :cluster_name, :spot_request_id, :region, :bastion, :rsa_key_location, :ssh_username,
84
+ attr_reader :cluster_name, :spot_request_id, :asg_name,
85
+ :region, :bastion, :rsa_key_location, :ssh_username,
82
86
  :sudo, :aws_vault_profile, :shortcuts, :tunnels
83
87
 
84
88
  def select_agent(auto:)
@@ -196,6 +200,11 @@ module KnuckleCluster
196
200
  aws_client_config: aws_client_config,
197
201
  spot_request_id: spot_request_id,
198
202
  )
203
+ elsif @asg_name
204
+ AsgInstanceRegistry.new(
205
+ aws_client_config: aws_client_config,
206
+ asg_name: asg_name,
207
+ )
199
208
  end
200
209
  )
201
210
  end
@@ -0,0 +1,58 @@
1
+ require 'knuckle_cluster/agent'
2
+
3
+ require 'forwardable'
4
+
5
+ module KnuckleCluster
6
+ class AsgInstanceRegistry
7
+ extend Forwardable
8
+
9
+ def initialize(aws_client_config:, asg_name:)
10
+ @aws_client_config = aws_client_config
11
+ @asg_name = asg_name
12
+ end
13
+
14
+ def agents
15
+ @agents ||= load_agents
16
+ end
17
+
18
+ def output_agents
19
+ tp agents,
20
+ :index,
21
+ :instance_id,
22
+ # :public_ip,
23
+ :private_ip,
24
+ :availability_zone
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :aws_client_config, :asg_name
30
+
31
+ def load_agents
32
+ auto_scaling_instances = autoscaling_client.describe_auto_scaling_groups(auto_scaling_group_names: [@asg_name]).to_h
33
+
34
+ instance_ids = auto_scaling_instances[:auto_scaling_groups][0][:instances].map{|instance| instance[:instance_id]}
35
+
36
+ instance_reservations = ec2_client.describe_instances(instance_ids: instance_ids).reservations
37
+
38
+ instance_reservations.map(&:instances).flatten.map.with_index do |instance, index|
39
+ Agent.new(
40
+ index: index + 1,
41
+ instance_id: instance[:instance_id],
42
+ public_ip: instance[:public_ip_address],
43
+ private_ip: instance[:private_ip_address],
44
+ availability_zone: instance.dig(:placement, :availability_zone),
45
+ )
46
+ end
47
+ end
48
+
49
+ def ec2_client
50
+ @ec2_client ||= Aws::EC2::Client.new(aws_client_config)
51
+ end
52
+
53
+ def autoscaling_client
54
+ @autoscaling_client ||= Aws::AutoScaling::Client.new(aws_client_config)
55
+ end
56
+
57
+ end
58
+ end
@@ -1,3 +1,3 @@
1
1
  module KnuckleCluster
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knuckle_cluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Envato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-24 00:00:00.000000000 Z
11
+ date: 2017-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -103,6 +103,7 @@ files:
103
103
  - knuckle_cluster.gemspec
104
104
  - lib/knuckle_cluster.rb
105
105
  - lib/knuckle_cluster/agent.rb
106
+ - lib/knuckle_cluster/asg_instance_registry.rb
106
107
  - lib/knuckle_cluster/configuration.rb
107
108
  - lib/knuckle_cluster/container.rb
108
109
  - lib/knuckle_cluster/ecs_agent_registry.rb