aly 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/aly/app.rb +53 -33
- data/lib/aly/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f26b851dc09f00694624a45426546e11bc72c63de0a991ceb1e6b1e8989a3f1
|
4
|
+
data.tar.gz: e4f1e81074036af2e6565f0f98a30ffd7a81dc82a1c42bb878f6357c5a93cf55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c762fdf73886adb7229a88510e613ec7d58966dc42cb1fe98bf3d84b7082274551e2201f08439953c467743561e90a4229d777294963d765a68987f0c3916c2d
|
7
|
+
data.tar.gz: 97f110b453a54434943d380ad960536dc26934ceff82b6f8fac8782011c38f2e8aba9692ff56cd8d5714c2df78926f0a947e965d78169e55f8d9fcf1f35d9796
|
data/Gemfile.lock
CHANGED
data/lib/aly/app.rb
CHANGED
@@ -22,11 +22,11 @@ module Aly
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def ecs(*args, **options)
|
25
|
-
raw_out = exec('ecs', 'DescribeInstances', '--pager')
|
26
|
-
selected = raw_out['Instances']['Instance'].each do |item|
|
27
|
-
item['PrivateIP'] = (item['NetworkInterfaces']['NetworkInterface'] || []).map { |ni| ni['PrimaryIpAddress'] }.join(',
|
25
|
+
raw_out = exec('ecs', 'DescribeInstances', '--pager', **options)
|
26
|
+
selected = (raw_out['Instances']['Instance'] || []).each do |item|
|
27
|
+
item['PrivateIP'] = (item['NetworkInterfaces']['NetworkInterface'] || []).map { |ni| ni['PrimaryIpAddress'] }.join(',')
|
28
28
|
item['PublicIP'] = item['EipAddress']['IpAddress'] || ''
|
29
|
-
item['PublicIP'] = item['PublicIpAddress']['IpAddress'].join(',
|
29
|
+
item['PublicIP'] = item['PublicIpAddress']['IpAddress'].join(',') if item['PublicIP'] == ''
|
30
30
|
end
|
31
31
|
|
32
32
|
if query = args.first&.split(',')
|
@@ -54,7 +54,7 @@ module Aly
|
|
54
54
|
|
55
55
|
def eip(*args, **options)
|
56
56
|
puts 'EIPs:'
|
57
|
-
raw_out = exec('vpc', 'DescribeEipAddresses', '--PageSize=100')
|
57
|
+
raw_out = exec('vpc', 'DescribeEipAddresses', '--PageSize=100', **options)
|
58
58
|
selected = raw_out['EipAddresses']['EipAddress']
|
59
59
|
|
60
60
|
if query = args.first&.split(',')
|
@@ -63,10 +63,11 @@ module Aly
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
|
66
67
|
if options['detail']
|
67
68
|
puts JSON.pretty_generate(selected)
|
68
69
|
else
|
69
|
-
net_intefraces = exec('ecs', 'DescribeNetworkInterfaces', '--pager')['NetworkInterfaceSets']['NetworkInterfaceSet'].each_with_object({}) do |item, result|
|
70
|
+
net_intefraces = exec('ecs', 'DescribeNetworkInterfaces', '--pager', **options)['NetworkInterfaceSets']['NetworkInterfaceSet'].each_with_object({}) do |item, result|
|
70
71
|
result[item['NetworkInterfaceId']] = item
|
71
72
|
end
|
72
73
|
selected = selected.map do |row|
|
@@ -91,10 +92,14 @@ module Aly
|
|
91
92
|
end
|
92
93
|
|
93
94
|
def slb(*args, **options)
|
94
|
-
raw_out = exec('slb', 'DescribeLoadBalancers', '--pager')
|
95
|
-
selected = raw_out['LoadBalancers']['LoadBalancer']
|
95
|
+
raw_out = exec('slb', 'DescribeLoadBalancers', '--pager', **options)
|
96
|
+
selected = raw_out['LoadBalancers']['LoadBalancer'] || []
|
97
|
+
|
98
|
+
eips = exec('vpc', 'DescribeEipAddresses', "--PageSize=#{selected.size}", **options)['EipAddresses']['EipAddress'].each_with_object({}) do |item, result|
|
99
|
+
result[item['InstanceId']] = item['IpAddress']
|
100
|
+
end
|
96
101
|
|
97
|
-
listeners = exec('slb', 'DescribeLoadBalancerListeners', '--pager', 'path=Listeners')['Listeners'].each_with_object({}) do |listener, result|
|
102
|
+
listeners = (exec('slb', 'DescribeLoadBalancerListeners', '--pager', 'path=Listeners', **options)['Listeners'] || []).each_with_object({}) do |listener, result|
|
98
103
|
instance_id = listener['LoadBalancerId']
|
99
104
|
result[instance_id] ||= []
|
100
105
|
result[instance_id] << listener
|
@@ -112,11 +117,11 @@ module Aly
|
|
112
117
|
|
113
118
|
if options['detail']
|
114
119
|
selected.each do |row|
|
115
|
-
described_load_balancer_attributes = exec('slb', 'DescribeLoadBalancerAttribute', "--LoadBalancerId=#{row['LoadBalancerId']}")
|
120
|
+
described_load_balancer_attributes = exec('slb', 'DescribeLoadBalancerAttribute', "--LoadBalancerId=#{row['LoadBalancerId']}", **options)
|
116
121
|
row['BackendServers'] = described_load_balancer_attributes['BackendServers']['BackendServer']
|
117
122
|
|
118
123
|
row['Listeners'].select { |e| e['VServerGroupId'] }.each do |listener|
|
119
|
-
vserver_group = exec('slb', 'DescribeVServerGroupAttribute', "--VServerGroupId=#{listener['VServerGroupId']}")
|
124
|
+
vserver_group = exec('slb', 'DescribeVServerGroupAttribute', "--VServerGroupId=#{listener['VServerGroupId']}", **options)
|
120
125
|
listener['VServerGroup'] = vserver_group
|
121
126
|
end
|
122
127
|
end
|
@@ -140,6 +145,7 @@ module Aly
|
|
140
145
|
Id: row['LoadBalancerId'],
|
141
146
|
Name: row['LoadBalancerName'],
|
142
147
|
Address: row['Address'],
|
148
|
+
Eip: eips[row['LoadBalancerId']] || '',
|
143
149
|
Listeners: listeners
|
144
150
|
}
|
145
151
|
end
|
@@ -148,34 +154,40 @@ module Aly
|
|
148
154
|
end
|
149
155
|
|
150
156
|
def slb_contains_host?(host)
|
151
|
-
@slb.any? { |lb| lb['Address'] == host }
|
157
|
+
@slb.any? { |lb| lb['Address'] == host || lb['Eip'] == host }
|
152
158
|
end
|
153
159
|
|
154
160
|
def ecs_contains_host?(host)
|
155
161
|
@ecs.any? { |item| item['AllIPs'].include?(host) }
|
156
162
|
end
|
157
163
|
|
158
|
-
def show_slb(host)
|
159
|
-
@listeners ||= exec('slb', 'DescribeLoadBalancerListeners', '--pager', 'path=Listeners')['Listeners']
|
160
|
-
lb = @slb.find { |e| e['Address'] == host }
|
164
|
+
def show_slb(host, **options)
|
165
|
+
@listeners ||= exec('slb', 'DescribeLoadBalancerListeners', '--pager', 'path=Listeners', **options)['Listeners'] || []
|
166
|
+
lb = @slb.find { |e| e['Address'] == host || e['Eip'] == host }
|
161
167
|
listeners = @listeners.select { |e| e['LoadBalancerId'] == lb['LoadBalancerId'] }
|
162
|
-
background_servers = exec('slb', 'DescribeLoadBalancerAttribute', "--LoadBalancerId=#{lb['LoadBalancerId']}")['BackendServers']['BackendServer']
|
168
|
+
background_servers = exec('slb', 'DescribeLoadBalancerAttribute', "--LoadBalancerId=#{lb['LoadBalancerId']}", **options)['BackendServers']['BackendServer']
|
163
169
|
|
164
170
|
puts 'LoadBalancers:'
|
165
171
|
puts([{
|
166
172
|
Id: lb['LoadBalancerId'],
|
167
173
|
Name: lb['LoadBalancerName'],
|
168
174
|
Address: lb['Address'],
|
169
|
-
|
170
|
-
|
175
|
+
Eip: lb['Eip'],
|
176
|
+
Listeners: listeners.size
|
171
177
|
}].table.to_s)
|
172
178
|
puts
|
173
179
|
|
180
|
+
if background_servers && background_servers.size > 0
|
181
|
+
puts 'Default Backend Servers:'
|
182
|
+
puts background_servers.table.to_s
|
183
|
+
puts
|
184
|
+
end
|
185
|
+
|
174
186
|
listeners_info = listeners.map do |listener|
|
175
187
|
{
|
176
188
|
Port: listener['ListenerPort'],
|
177
189
|
Protocol: listener['ListenerProtocol'],
|
178
|
-
Status: listener['
|
190
|
+
Status: listener['Status'],
|
179
191
|
BackendServerPort: listener['BackendServerPort'],
|
180
192
|
ForwardPort: listener.dig('HTTPListenerConfig', 'ForwardPort'),
|
181
193
|
VServerGroup: listener['VServerGroupId']
|
@@ -188,11 +200,11 @@ module Aly
|
|
188
200
|
|
189
201
|
listeners_info.each do |listener|
|
190
202
|
if listener[:VServerGroup]
|
191
|
-
vserver_group = exec('slb', 'DescribeVServerGroupAttribute', "--VServerGroupId=#{listener[:VServerGroup]}")["BackendServers"]["BackendServer"]
|
203
|
+
vserver_group = exec('slb', 'DescribeVServerGroupAttribute', "--VServerGroupId=#{listener[:VServerGroup]}", **options)["BackendServers"]["BackendServer"]
|
192
204
|
puts "VServerGroup #{listener[:VServerGroup]}:"
|
193
205
|
puts(vserver_group.map { |e|
|
194
206
|
{
|
195
|
-
|
207
|
+
EcsInstanceId: e['ServerId'],
|
196
208
|
Port: e['Port'],
|
197
209
|
Weight: e['Weight'],
|
198
210
|
Type: e['Type']
|
@@ -205,7 +217,7 @@ module Aly
|
|
205
217
|
ecs_ids = background_servers.map { |e| e['ServerId'] }
|
206
218
|
ecs_ids += listeners_info.flat_map { |e|
|
207
219
|
if e[:VServerGroup]
|
208
|
-
exec('slb', 'DescribeVServerGroupAttribute', "--VServerGroupId=#{e[:VServerGroup]}")["BackendServers"]["BackendServer"].map { |e| e['ServerId'] }
|
220
|
+
exec('slb', 'DescribeVServerGroupAttribute', "--VServerGroupId=#{e[:VServerGroup]}", **options)["BackendServers"]["BackendServer"].map { |e| e['ServerId'] }
|
209
221
|
else
|
210
222
|
[]
|
211
223
|
end
|
@@ -220,8 +232,8 @@ module Aly
|
|
220
232
|
{
|
221
233
|
Id: row['InstanceId'],
|
222
234
|
Name: row['InstanceName'],
|
223
|
-
PrivateIP: row['PrivateIP'].join(',
|
224
|
-
PublicIP: row['PublicIP'].join(',
|
235
|
+
PrivateIP: row['PrivateIP'].join(','),
|
236
|
+
PublicIP: row['PublicIP'].join(','),
|
225
237
|
CPU: row['Cpu'],
|
226
238
|
RAM: "#{row['Memory'] / 1024.0} GB"
|
227
239
|
}
|
@@ -234,8 +246,8 @@ module Aly
|
|
234
246
|
{
|
235
247
|
Id: row['InstanceId'],
|
236
248
|
Name: row['InstanceName'],
|
237
|
-
PrivateIP: row['PrivateIP'].join(',
|
238
|
-
PublicIP: row['PublicIP'].join(',
|
249
|
+
PrivateIP: row['PrivateIP'].join(','),
|
250
|
+
PublicIP: row['PublicIP'].join(','),
|
239
251
|
CPU: row['Cpu'],
|
240
252
|
RAM: "#{row['Memory'] / 1024.0} GB"
|
241
253
|
}
|
@@ -249,11 +261,17 @@ module Aly
|
|
249
261
|
end
|
250
262
|
|
251
263
|
def show(*args, **options)
|
252
|
-
@slb ||= exec('slb', 'DescribeLoadBalancers', '--pager')['LoadBalancers']['LoadBalancer']
|
264
|
+
@slb ||= exec('slb', 'DescribeLoadBalancers', '--pager', **options)['LoadBalancers']['LoadBalancer'] || []
|
265
|
+
|
266
|
+
@eip ||= exec('vpc', 'DescribeEipAddresses', '--PageSize=100', **options)['EipAddresses']['EipAddress'] || []
|
267
|
+
|
268
|
+
eip_map = @eip.each_with_object({}) { |eip, h| h[eip['InstanceId']] = eip['IpAddress'] }
|
269
|
+
@slb.each do |slb|
|
270
|
+
slb['Eip'] = eip_map[slb['LoadBalancerId']]
|
271
|
+
end
|
253
272
|
|
254
|
-
@eip ||= exec('vpc', 'DescribeEipAddresses', '--PageSize=100')['EipAddresses']['EipAddress']
|
255
273
|
unless @ecs
|
256
|
-
@ecs = exec('ecs', 'DescribeInstances', '--pager')['Instances']['Instance']
|
274
|
+
@ecs = exec('ecs', 'DescribeInstances', '--pager', **options)['Instances']['Instance'] || []
|
257
275
|
@ecs.each do |item|
|
258
276
|
item['PrivateIP'] = (item['NetworkInterfaces']['NetworkInterface'] || []).map { |ni| ni['PrimaryIpAddress'] }
|
259
277
|
item['PublicIP'] = []
|
@@ -273,18 +291,20 @@ module Aly
|
|
273
291
|
puts
|
274
292
|
|
275
293
|
if slb_contains_host?(host)
|
276
|
-
show_slb(host)
|
294
|
+
show_slb(host, **options)
|
277
295
|
elsif ecs_contains_host?(host)
|
278
296
|
show_ecs(host)
|
279
297
|
elsif eip_contains_host?(host)
|
280
|
-
eip(host)
|
298
|
+
eip(host, **options)
|
281
299
|
else
|
282
300
|
puts "Not found: #{host}"
|
283
301
|
end
|
284
302
|
end
|
285
303
|
|
286
|
-
def exec(command, sub_command, *args)
|
287
|
-
|
304
|
+
def exec(command, sub_command, *args, **options)
|
305
|
+
command = "aliyun #{command} #{sub_command} #{args.join(' ')}"
|
306
|
+
command += " -p #{options['profile']}" if options['profile']
|
307
|
+
JSON.parse(`#{command}`)
|
288
308
|
end
|
289
309
|
end
|
290
310
|
end
|
data/lib/aly/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liu Xiang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|