aly 0.2.0 → 0.2.1
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 +35 -28
- data/lib/aly/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31c380fbca73a1136b7c8dea73e13ddd28f03a8e6e3a9a395bd55d225215ee56
|
4
|
+
data.tar.gz: b320bcbb2b06fadd45f1ba005526fba07657287dbdf81e7ba48c50c3e4d24723
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ea21f6de6ea31ded361e64a40b97f7f48fe1e8652994effebbd99d1b380c1b8a08d11519cdb4dd2d58196f66fd24adde2cc5d4d2069367809c8e7766cab4906
|
7
|
+
data.tar.gz: 1a5f4e03792bded3c18cb798d03c574a35f96bda022c36265f0ff281cd7d52f8fe3edd987dbc36826768272f824b20dd42b320da63e30fa576b4a7032b4f8034
|
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')
|
25
|
+
raw_out = exec('ecs', 'DescribeInstances', '--pager', **options)
|
26
26
|
selected = raw_out['Instances']['Instance'].each do |item|
|
27
|
-
item['PrivateIP'] = (item['NetworkInterfaces']['NetworkInterface'] || []).map { |ni| ni['PrimaryIpAddress'] }.join(',
|
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(',')
|
@@ -66,7 +66,7 @@ module Aly
|
|
66
66
|
if options['detail']
|
67
67
|
puts JSON.pretty_generate(selected)
|
68
68
|
else
|
69
|
-
net_intefraces = exec('ecs', 'DescribeNetworkInterfaces', '--pager')['NetworkInterfaceSets']['NetworkInterfaceSet'].each_with_object({}) do |item, result|
|
69
|
+
net_intefraces = exec('ecs', 'DescribeNetworkInterfaces', '--pager', **options)['NetworkInterfaceSets']['NetworkInterfaceSet'].each_with_object({}) do |item, result|
|
70
70
|
result[item['NetworkInterfaceId']] = item
|
71
71
|
end
|
72
72
|
selected = selected.map do |row|
|
@@ -91,10 +91,10 @@ module Aly
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def slb(*args, **options)
|
94
|
-
raw_out = exec('slb', 'DescribeLoadBalancers', '--pager')
|
94
|
+
raw_out = exec('slb', 'DescribeLoadBalancers', '--pager', **options)
|
95
95
|
selected = raw_out['LoadBalancers']['LoadBalancer']
|
96
96
|
|
97
|
-
listeners = exec('slb', 'DescribeLoadBalancerListeners', '--pager', 'path=Listeners')['Listeners'].each_with_object({}) do |listener, result|
|
97
|
+
listeners = exec('slb', 'DescribeLoadBalancerListeners', '--pager', 'path=Listeners', **options)['Listeners'].each_with_object({}) do |listener, result|
|
98
98
|
instance_id = listener['LoadBalancerId']
|
99
99
|
result[instance_id] ||= []
|
100
100
|
result[instance_id] << listener
|
@@ -112,11 +112,11 @@ module Aly
|
|
112
112
|
|
113
113
|
if options['detail']
|
114
114
|
selected.each do |row|
|
115
|
-
described_load_balancer_attributes = exec('slb', 'DescribeLoadBalancerAttribute', "--LoadBalancerId=#{row['LoadBalancerId']}")
|
115
|
+
described_load_balancer_attributes = exec('slb', 'DescribeLoadBalancerAttribute', "--LoadBalancerId=#{row['LoadBalancerId']}", **options)
|
116
116
|
row['BackendServers'] = described_load_balancer_attributes['BackendServers']['BackendServer']
|
117
117
|
|
118
118
|
row['Listeners'].select { |e| e['VServerGroupId'] }.each do |listener|
|
119
|
-
vserver_group = exec('slb', 'DescribeVServerGroupAttribute', "--VServerGroupId=#{listener['VServerGroupId']}")
|
119
|
+
vserver_group = exec('slb', 'DescribeVServerGroupAttribute', "--VServerGroupId=#{listener['VServerGroupId']}", **options)
|
120
120
|
listener['VServerGroup'] = vserver_group
|
121
121
|
end
|
122
122
|
end
|
@@ -155,27 +155,32 @@ module Aly
|
|
155
155
|
@ecs.any? { |item| item['AllIPs'].include?(host) }
|
156
156
|
end
|
157
157
|
|
158
|
-
def show_slb(host)
|
159
|
-
@listeners ||= exec('slb', 'DescribeLoadBalancerListeners', '--pager', 'path=Listeners')['Listeners']
|
158
|
+
def show_slb(host, **options)
|
159
|
+
@listeners ||= exec('slb', 'DescribeLoadBalancerListeners', '--pager', 'path=Listeners', **options)['Listeners']
|
160
160
|
lb = @slb.find { |e| e['Address'] == host }
|
161
161
|
listeners = @listeners.select { |e| e['LoadBalancerId'] == lb['LoadBalancerId'] }
|
162
|
-
background_servers = exec('slb', 'DescribeLoadBalancerAttribute', "--LoadBalancerId=#{lb['LoadBalancerId']}")['BackendServers']['BackendServer']
|
162
|
+
background_servers = exec('slb', 'DescribeLoadBalancerAttribute', "--LoadBalancerId=#{lb['LoadBalancerId']}", **options)['BackendServers']['BackendServer']
|
163
163
|
|
164
164
|
puts 'LoadBalancers:'
|
165
165
|
puts([{
|
166
166
|
Id: lb['LoadBalancerId'],
|
167
167
|
Name: lb['LoadBalancerName'],
|
168
168
|
Address: lb['Address'],
|
169
|
-
Listeners: listeners.size
|
170
|
-
BackendServers: background_servers.map { |e| e['ServerId'] }.join(', ')
|
169
|
+
Listeners: listeners.size
|
171
170
|
}].table.to_s)
|
172
171
|
puts
|
173
172
|
|
173
|
+
if background_servers && background_servers.size > 0
|
174
|
+
puts 'Default Backend Servers:'
|
175
|
+
puts background_servers.table.to_s
|
176
|
+
puts
|
177
|
+
end
|
178
|
+
|
174
179
|
listeners_info = listeners.map do |listener|
|
175
180
|
{
|
176
181
|
Port: listener['ListenerPort'],
|
177
182
|
Protocol: listener['ListenerProtocol'],
|
178
|
-
Status: listener['
|
183
|
+
Status: listener['Status'],
|
179
184
|
BackendServerPort: listener['BackendServerPort'],
|
180
185
|
ForwardPort: listener.dig('HTTPListenerConfig', 'ForwardPort'),
|
181
186
|
VServerGroup: listener['VServerGroupId']
|
@@ -188,11 +193,11 @@ module Aly
|
|
188
193
|
|
189
194
|
listeners_info.each do |listener|
|
190
195
|
if listener[:VServerGroup]
|
191
|
-
vserver_group = exec('slb', 'DescribeVServerGroupAttribute', "--VServerGroupId=#{listener[:VServerGroup]}")["BackendServers"]["BackendServer"]
|
196
|
+
vserver_group = exec('slb', 'DescribeVServerGroupAttribute', "--VServerGroupId=#{listener[:VServerGroup]}", **options)["BackendServers"]["BackendServer"]
|
192
197
|
puts "VServerGroup #{listener[:VServerGroup]}:"
|
193
198
|
puts(vserver_group.map { |e|
|
194
199
|
{
|
195
|
-
|
200
|
+
EcsInstanceId: e['ServerId'],
|
196
201
|
Port: e['Port'],
|
197
202
|
Weight: e['Weight'],
|
198
203
|
Type: e['Type']
|
@@ -205,7 +210,7 @@ module Aly
|
|
205
210
|
ecs_ids = background_servers.map { |e| e['ServerId'] }
|
206
211
|
ecs_ids += listeners_info.flat_map { |e|
|
207
212
|
if e[:VServerGroup]
|
208
|
-
exec('slb', 'DescribeVServerGroupAttribute', "--VServerGroupId=#{e[:VServerGroup]}")["BackendServers"]["BackendServer"].map { |e| e['ServerId'] }
|
213
|
+
exec('slb', 'DescribeVServerGroupAttribute', "--VServerGroupId=#{e[:VServerGroup]}", **options)["BackendServers"]["BackendServer"].map { |e| e['ServerId'] }
|
209
214
|
else
|
210
215
|
[]
|
211
216
|
end
|
@@ -220,8 +225,8 @@ module Aly
|
|
220
225
|
{
|
221
226
|
Id: row['InstanceId'],
|
222
227
|
Name: row['InstanceName'],
|
223
|
-
PrivateIP: row['PrivateIP'].join(',
|
224
|
-
PublicIP: row['PublicIP'].join(',
|
228
|
+
PrivateIP: row['PrivateIP'].join(','),
|
229
|
+
PublicIP: row['PublicIP'].join(','),
|
225
230
|
CPU: row['Cpu'],
|
226
231
|
RAM: "#{row['Memory'] / 1024.0} GB"
|
227
232
|
}
|
@@ -234,8 +239,8 @@ module Aly
|
|
234
239
|
{
|
235
240
|
Id: row['InstanceId'],
|
236
241
|
Name: row['InstanceName'],
|
237
|
-
PrivateIP: row['PrivateIP'].join(',
|
238
|
-
PublicIP: row['PublicIP'].join(',
|
242
|
+
PrivateIP: row['PrivateIP'].join(','),
|
243
|
+
PublicIP: row['PublicIP'].join(','),
|
239
244
|
CPU: row['Cpu'],
|
240
245
|
RAM: "#{row['Memory'] / 1024.0} GB"
|
241
246
|
}
|
@@ -249,11 +254,11 @@ module Aly
|
|
249
254
|
end
|
250
255
|
|
251
256
|
def show(*args, **options)
|
252
|
-
@slb ||= exec('slb', 'DescribeLoadBalancers', '--pager')['LoadBalancers']['LoadBalancer']
|
257
|
+
@slb ||= exec('slb', 'DescribeLoadBalancers', '--pager', **options)['LoadBalancers']['LoadBalancer']
|
253
258
|
|
254
|
-
@eip ||= exec('vpc', 'DescribeEipAddresses', '--PageSize=100')['EipAddresses']['EipAddress']
|
259
|
+
@eip ||= exec('vpc', 'DescribeEipAddresses', '--PageSize=100', **options)['EipAddresses']['EipAddress']
|
255
260
|
unless @ecs
|
256
|
-
@ecs = exec('ecs', 'DescribeInstances', '--pager')['Instances']['Instance']
|
261
|
+
@ecs = exec('ecs', 'DescribeInstances', '--pager', **options)['Instances']['Instance']
|
257
262
|
@ecs.each do |item|
|
258
263
|
item['PrivateIP'] = (item['NetworkInterfaces']['NetworkInterface'] || []).map { |ni| ni['PrimaryIpAddress'] }
|
259
264
|
item['PublicIP'] = []
|
@@ -273,7 +278,7 @@ module Aly
|
|
273
278
|
puts
|
274
279
|
|
275
280
|
if slb_contains_host?(host)
|
276
|
-
show_slb(host)
|
281
|
+
show_slb(host, **options)
|
277
282
|
elsif ecs_contains_host?(host)
|
278
283
|
show_ecs(host)
|
279
284
|
elsif eip_contains_host?(host)
|
@@ -283,8 +288,10 @@ module Aly
|
|
283
288
|
end
|
284
289
|
end
|
285
290
|
|
286
|
-
def exec(command, sub_command, *args)
|
287
|
-
|
291
|
+
def exec(command, sub_command, *args, **options)
|
292
|
+
command = "aliyun #{command} #{sub_command} #{args.join(' ')}"
|
293
|
+
command += " -p #{options['profile']}" if options['profile']
|
294
|
+
JSON.parse(`#{command}`)
|
288
295
|
end
|
289
296
|
end
|
290
297
|
end
|
data/lib/aly/version.rb
CHANGED