File tree Expand file tree Collapse file tree 3 files changed +122
-3
lines changed Expand file tree Collapse file tree 3 files changed +122
-3
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env ruby
2+
3+ require "aws-sdk-elasticloadbalancingv2"
4+
5+ host_id = ARGV [ 0 ]
6+
7+ fail "Please specify HOST_ID" if host_id . nil?
8+
9+ REGION = "us-west-2" . freeze
10+ class AWSClient
11+ class << self
12+ def elbv2
13+ @elbv2 ||= Aws ::ElasticLoadBalancingV2 ::Client . new ( region : REGION )
14+ end
15+ end
16+ end
17+
18+ tgs = AWSClient . elbv2 . describe_target_groups . target_groups
19+
20+ tgs . each do |tg |
21+ targets = AWSClient . elbv2 . describe_target_health ( target_group_arn : tg . target_group_arn )
22+ . target_health_descriptions . map ( &:target )
23+ target_ports = targets . map ( &:port ) . uniq
24+
25+ AWSClient . elbv2 . deregister_targets ( {
26+ target_group_arn : tg . target_group_arn ,
27+ targets : [
28+ {
29+ id : host_id ,
30+ port : target_ports [ 0 ]
31+ }
32+ ]
33+ } )
34+ end
35+
36+ tgs . each do |tg |
37+ targets = AWSClient . elbv2 . describe_target_health ( target_group_arn : tg . target_group_arn )
38+ . target_health_descriptions . map ( &:target )
39+ target_ports = targets . map ( &:port ) . uniq
40+
41+ AWSClient . elbv2 . wait_until (
42+ :target_deregistered ,
43+ target_group_arn : tg . target_group_arn ,
44+ targets : [
45+ {
46+ id : host_id ,
47+ port : target_ports [ 0 ]
48+ }
49+ ]
50+ )
51+
52+ puts "#{ tg . target_group_name } :#{ target_ports [ 0 ] } de-registered"
53+ end
54+
55+ puts "\n Target host de-registered from all target groups"
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env ruby
2+
3+ require "aws-sdk-elasticloadbalancingv2"
4+
5+ host_id = ARGV [ 0 ]
6+ tg_skip = ARGV [ 1 ]
7+
8+ fail "Please specify HOST_ID" if host_id . nil?
9+
10+ REGION = "us-west-2" . freeze
11+ class AWSClient
12+ class << self
13+ def elbv2
14+ @elbv2 ||= Aws ::ElasticLoadBalancingV2 ::Client . new ( region : REGION )
15+ end
16+ end
17+ end
18+
19+ tgs = AWSClient . elbv2 . describe_target_groups . target_groups
20+
21+ if tg_skip
22+ tgs . reject! { |tg | tg_skip . include? tg . target_group_name }
23+ end
24+
25+ tgs . each do |tg |
26+ targets = AWSClient . elbv2 . describe_target_health ( target_group_arn : tg . target_group_arn )
27+ . target_health_descriptions . map ( &:target )
28+ target_ports = targets . map ( &:port ) . uniq
29+
30+ AWSClient . elbv2 . register_targets ( {
31+ target_group_arn : tg . target_group_arn ,
32+ targets : [
33+ {
34+ id : host_id ,
35+ port : target_ports [ 0 ]
36+ }
37+ ]
38+ } )
39+ end
40+
41+ tgs . each do |tg |
42+ targets = AWSClient . elbv2 . describe_target_health ( target_group_arn : tg . target_group_arn )
43+ . target_health_descriptions . map ( &:target )
44+ target_ports = targets . map ( &:port ) . uniq
45+
46+ AWSClient . elbv2 . wait_until (
47+ :target_in_service ,
48+ target_group_arn : tg . target_group_arn ,
49+ targets : [
50+ {
51+ id : host_id ,
52+ port : target_ports [ 0 ]
53+ }
54+ ]
55+ )
56+ puts "#{ tg . target_group_name } :#{ target_ports [ 0 ] } registered"
57+ end
58+
59+ puts "\n Target host registered back to all target groups"
Original file line number Diff line number Diff line change 11Gem ::Specification . new do |s |
22 s . name = 'deploy-tools'
3- s . version = '0.1.2 '
4- s . date = '2022-06-28 '
3+ s . version = '0.1.3 '
4+ s . date = '2022-09-02 '
55 s . summary = "Deploy tools"
66 s . description = "A set of script used for deployment"
77 s . authors = [ "Tony Nyurkin" , "Serhii Voronoi" ]
8899 s . files = `git ls-files ` . split ( "\n " )
1010 s . bindir = "bin"
11- s . executables = [ "blue_green_switch" , "detect_inactive_color" ]
11+ s . executables = [
12+ "blue_green_switch" ,
13+ "detect_inactive_color" ,
14+ "deregister_single_target" ,
15+ "register_single_target"
16+ ]
1217 s . add_runtime_dependency 'aws-sdk-elasticloadbalancingv2' , '~>1.44'
1318end
You can’t perform that action at this time.
0 commit comments