knuckle_cluster 1.0.0 → 1.1.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: d1938a27084e6da4bd72ce501a8e373a5a919b18
4
- data.tar.gz: e27ce437a1519ce998b79429d00ca18c793a9fae
3
+ metadata.gz: a1f4c2401bd2ba5e45bde345234fea0af87f75d2
4
+ data.tar.gz: 23cb6fb4cddbfd168e5940463387104445720bf2
5
5
  SHA512:
6
- metadata.gz: 3b470a48b031d80f4761aa538243862beb946e46825b37fbdd361db52216452d21bca92ae02641e62804303b50823590edf2a5eea91ff081d6f26c94a685872c
7
- data.tar.gz: 56ef57f3f84bc4cc707296d67592b5ac8e5867a94663b0f2fe21eda609c154fbc70c9f94feb6f9e231a05e09c6dd9f247a789bebe40151d528ef1f10cbd46ad7
6
+ metadata.gz: d8c7e0fc10f7d44b0269ac8c9317a25ba08c6f2f2e96b084ee58d89713791ca9960ca40cc6f834ad423d9b09fce130af7f344d08376a2971a4a2e01a53312f99
7
+ data.tar.gz: 4ef267008c44f2550a64d41bd40d6b9bb37bb6290770dc69704fd6024c3a6f43d4ff9de135a00d48908eeb6332ebcd112d0ee8d2d73b2fa091a6f4c58404697e
data/README.md CHANGED
@@ -185,7 +185,8 @@ Possible options are below. If left blank, they will be ignored and defaults use
185
185
 
186
186
  Argument | Description
187
187
  -------- | -----------
188
- cluster_name | The name of the cluster (not the ARN). eg 'my-super-cluster'. Required
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
190
  region | The AWS region you would like to use. Defaults to `us-east-1`
190
191
  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.
191
192
  rsa_key_location | The RSA key needed to connect to an ecs agent eg `~/.ssh/id_rsa`.
@@ -194,6 +195,8 @@ sudo | true or false - will sudo the `docker` command on the target machine. Usu
194
195
  aws_vault_profile | If you use the `aws-vault` tool to manage your AWS credentials, you can specify a profile here that will be automatically used to connect to this cluster.
195
196
  profile | Another profile to inherit settings from. Settings from lower profiles can be overridden in higher ones.
196
197
 
198
+ ## 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.
197
200
 
198
201
  ## Maintainer
199
202
  [Envato](https://github.com/envato)
@@ -1,4 +1,5 @@
1
- require 'knuckle_cluster/agent_registry'
1
+ require 'knuckle_cluster/ecs_agent_registry'
2
+ require 'knuckle_cluster/spot_request_instance_registry'
2
3
  require "knuckle_cluster/version"
3
4
  require "knuckle_cluster/configuration"
4
5
 
@@ -11,7 +12,8 @@ module KnuckleCluster
11
12
  extend Forwardable
12
13
 
13
14
  def new(
14
- cluster_name:,
15
+ cluster_name: nil,
16
+ spot_request_id: nil,
15
17
  region: 'us-east-1',
16
18
  bastion: nil,
17
19
  rsa_key_location: nil,
@@ -21,6 +23,7 @@ module KnuckleCluster
21
23
  shortcuts: {},
22
24
  tunnels: {})
23
25
  @cluster_name = cluster_name
26
+ @spot_request_id = spot_request_id
24
27
  @region = region
25
28
  @bastion = bastion
26
29
  @rsa_key_location = rsa_key_location
@@ -29,6 +32,10 @@ module KnuckleCluster
29
32
  @aws_vault_profile = aws_vault_profile
30
33
  @shortcuts = shortcuts
31
34
  @tunnels = tunnels
35
+
36
+ if @cluster_name.nil? && @spot_request_id.nil?
37
+ raise "Must specify either cluster_name or spot_request_id"
38
+ end
32
39
  self
33
40
  end
34
41
 
@@ -71,7 +78,7 @@ module KnuckleCluster
71
78
 
72
79
  private
73
80
 
74
- attr_reader :cluster_name, :region, :bastion, :rsa_key_location, :ssh_username,
81
+ attr_reader :cluster_name, :spot_request_id, :region, :bastion, :rsa_key_location, :ssh_username,
75
82
  :sudo, :aws_vault_profile, :shortcuts, :tunnels
76
83
 
77
84
  def select_agent(auto:)
@@ -79,14 +86,7 @@ module KnuckleCluster
79
86
 
80
87
  puts "\nListing Agents"
81
88
 
82
- tp agents,
83
- :index,
84
- :instance_id,
85
- # :public_ip,
86
- # :private_ip,
87
- # :availability_zone,
88
- { task: { display_method: 'tasks.name', width: 999 } },
89
- { container: { display_method: 'tasks.containers.name', width: 999 } }
89
+ output_agents
90
90
 
91
91
  puts "\nConnect to which agent?"
92
92
  agents[STDIN.gets.strip.to_i - 1]
@@ -185,12 +185,21 @@ module KnuckleCluster
185
185
  end
186
186
 
187
187
  def agent_registry
188
- @agent_registry ||= AgentRegistry.new(
189
- aws_client_config: aws_client_config,
190
- cluster_name: cluster_name,
188
+ @agent_registry ||= (
189
+ if @cluster_name
190
+ EcsAgentRegistry.new(
191
+ aws_client_config: aws_client_config,
192
+ cluster_name: cluster_name,
193
+ )
194
+ elsif @spot_request_id
195
+ SpotRequestInstanceRegistry.new(
196
+ aws_client_config: aws_client_config,
197
+ spot_request_id: spot_request_id,
198
+ )
199
+ end
191
200
  )
192
201
  end
193
202
 
194
- def_delegators :agent_registry, :agents, :tasks, :containers
203
+ def_delegators :agent_registry, :agents, :tasks, :containers, :output_agents
195
204
  end
196
205
  end
@@ -6,8 +6,8 @@ module KnuckleCluster
6
6
  public_ip:,
7
7
  private_ip:,
8
8
  availability_zone:,
9
- container_instance_arn:,
10
- task_registry:
9
+ container_instance_arn: nil,
10
+ task_registry: nil
11
11
  )
12
12
  @index = index
13
13
  @instance_id = instance_id
@@ -4,7 +4,7 @@ require 'knuckle_cluster/task_registry'
4
4
  require 'forwardable'
5
5
 
6
6
  module KnuckleCluster
7
- class AgentRegistry
7
+ class EcsAgentRegistry
8
8
  extend Forwardable
9
9
 
10
10
  def initialize(aws_client_config:, cluster_name:)
@@ -20,6 +20,17 @@ module KnuckleCluster
20
20
  agents_by_container_instance_arn[container_instance_arn]&.first
21
21
  end
22
22
 
23
+ def output_agents
24
+ tp agents,
25
+ :index,
26
+ :instance_id,
27
+ # :public_ip,
28
+ # :private_ip,
29
+ # :availability_zone,
30
+ { task: { display_method: 'tasks.name', width: 999 } },
31
+ { container: { display_method: 'tasks.containers.name', width: 999 } }
32
+ end
33
+
23
34
  def_delegators :task_registry, :tasks, :containers
24
35
 
25
36
  private
@@ -0,0 +1,53 @@
1
+ require 'knuckle_cluster/agent'
2
+
3
+ require 'forwardable'
4
+
5
+ module KnuckleCluster
6
+ class SpotRequestInstanceRegistry
7
+ extend Forwardable
8
+
9
+ def initialize(aws_client_config:, spot_request_id:)
10
+ @aws_client_config = aws_client_config
11
+ @spot_request_id = spot_request_id
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, :spot_request_id
30
+
31
+ def load_agents
32
+ spot_fleet_instances = ec2_client.describe_spot_fleet_instances(spot_fleet_request_id: spot_request_id)
33
+ instance_ids = spot_fleet_instances.active_instances.map(&:instance_id)
34
+
35
+ instance_reservations = ec2_client.describe_instances(instance_ids: instance_ids).reservations
36
+
37
+ instance_reservations.map(&:instances).flatten.map.with_index do |instance, index|
38
+ Agent.new(
39
+ index: index + 1,
40
+ instance_id: instance[:instance_id],
41
+ public_ip: instance[:public_ip_address],
42
+ private_ip: instance[:private_ip_address],
43
+ availability_zone: instance.dig(:placement, :availability_zone),
44
+ )
45
+ end
46
+ end
47
+
48
+ def ec2_client
49
+ @ec2_client ||= Aws::EC2::Client.new(aws_client_config)
50
+ end
51
+
52
+ end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module KnuckleCluster
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.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.0.0
4
+ version: 1.1.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-18 00:00:00.000000000 Z
11
+ date: 2017-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -103,9 +103,10 @@ files:
103
103
  - knuckle_cluster.gemspec
104
104
  - lib/knuckle_cluster.rb
105
105
  - lib/knuckle_cluster/agent.rb
106
- - lib/knuckle_cluster/agent_registry.rb
107
106
  - lib/knuckle_cluster/configuration.rb
108
107
  - lib/knuckle_cluster/container.rb
108
+ - lib/knuckle_cluster/ecs_agent_registry.rb
109
+ - lib/knuckle_cluster/spot_request_instance_registry.rb
109
110
  - lib/knuckle_cluster/task.rb
110
111
  - lib/knuckle_cluster/task_registry.rb
111
112
  - lib/knuckle_cluster/version.rb