Class: Awful::Alb

Inherits:
Cli show all
Defined in:
lib/awful/alb.rb

Constant Summary collapse

COLORS =
{
  active:       :green,
  provisioning: :yellow,
  failed:       :red,
  healthy:      :green,
  unhealthy:    :red,
  InService:    :green,
  OutOfService: :red,
}

Instance Method Summary collapse

Methods inherited from Cli

#initialize

Constructor Details

This class inherits a constructor from Awful::Cli

Instance Method Details

#dump(*names) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/awful/alb.rb', line 82

def dump(*names)
  describe_load_balancers(*names).output do |albs|
    albs.each do |alb|
      puts YAML.dump(stringify_keys(alb.to_hash))
    end
  end
end

#instances(name) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/awful/alb.rb', line 120

def instances(name)
  alb.describe_target_groups(load_balancer_arn: get_arn(name)).target_groups.map do |tg|
    alb.describe_target_health(target_group_arn: tg.target_group_arn).target_health_descriptions
  end.flatten(1).output do |targets|
    if options[:long]
      print_table targets.map { |t|
        [t.target.id, t.target.port, color(t.target_health.state), t.target_health.reason, t.target_health.description]
      }
    else
      puts targets.map{ |t| t.target.id }
    end
  end
end

#listeners(name) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/awful/alb.rb', line 92

def listeners(name)
  alb.describe_listeners(load_balancer_arn: get_arn(name)).listeners.output do |listeners|
    if options[:long]
      print_table listeners.map { |l|
        [l.protocol, l.port, l.ssl_policy, l.certificates.join(','), l.listener_arn]
      }.sort
    else
      puts listeners.map(&:listener_arn)
    end
  end
end

#ls(*names) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/awful/alb.rb', line 69

def ls(*names)
  describe_load_balancers(*names).tap do |albs|
    albs.select! { |a| a.load_balancer_name.match(options[:matching]) } if options[:matching]
  end.output do |list|
    if options[:long]
      print_table list.map { |a| [a.load_balancer_name, a.dns_name, color(a.state.code), a.vpc_id, a.created_time] }
    else
      puts list.map(&:load_balancer_name)
    end
  end
end

#rules(listener) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/awful/alb.rb', line 136

def rules(listener)
  alb.describe_rules(listener_arn: listener).rules.output do |rules|
    if options[:long]
      print_table rules.map { |r|
        [r.priority, r.rule_arn]
      }
    else
      puts rules.map(&:rule_arn)
    end
  end
end

#tag(name, key, value = nil) ⇒ Object



159
160
161
162
163
164
165
166
167
# File 'lib/awful/alb.rb', line 159

def tag(name, key, value = nil)
  if options[:delete]
    remove_tags(name, key)
  elsif value
    add_tag(name, key, value)
  else
    get_tag(name, key)
  end
end

#tags(*names) ⇒ Object



149
150
151
152
153
154
155
# File 'lib/awful/alb.rb', line 149

def tags(*names)
  alb.describe_tags(resource_arns: names.map(&method(:get_arn))).tag_descriptions.output do |albs|
    albs.each do |alb|
      print_table alb.tags.map{ |t| [t.key, t.value] }
    end
  end
end

#targets(name) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/awful/alb.rb', line 106

def targets(name)
  alb.describe_target_groups(load_balancer_arn: get_arn(name)).target_groups.output do |target_groups|
    if options[:long]
      print_table target_groups.map { |t|
        [t.target_group_name, t.port, t.protocol, t.vpc_id]
      }
    else
      puts target_groups.map(&:target_group_name)
    end
  end
end