lib/aly/app.rb in aly-0.3.3 vs lib/aly/app.rb in aly-0.3.4
- old
+ new
@@ -16,11 +16,11 @@
end
module Aly
class App
def start(options)
- send(options[:command], *options[:args], **options[:options])
+ send(options[:command], *options[:args], **(options[:options].transform_keys(&:to_sym)))
end
def ecs(*args, **options)
raw_out = exec('ecs', 'DescribeInstances', '--pager', **options)
selected = (raw_out['Instances']['Instance'] || []).each do |item|
@@ -33,11 +33,11 @@
selected = selected.select do |item|
item.values_at('InstanceId', 'InstanceName', 'PrivateIP', 'PublicIP').compact.any? { |e| query.any? { |q| e.include?(q) } }
end
end
- if options['full']
+ if options[:full]
selected = selected.map do |row|
{
Id: row['InstanceId'],
Name: row['InstanceName'],
PrivateIP: row['PrivateIP'],
@@ -46,11 +46,11 @@
RAM: "#{row['Memory'] / 1024.0} GB",
WEB: "https://ecs.console.aliyun.com/#/server/#{row['InstanceId']}/monitor?regionId=#{row['RegionId']}"
}
end
puts selected.table&.to_s
- elsif options['detail']
+ elsif options[:detail]
puts JSON.pretty_generate(selected)
else
selected = selected.map do |row|
{
Id: row['InstanceId'],
@@ -75,11 +75,11 @@
item.values_at('AllocationId', 'InstanceId', 'InstanceType', 'IpAddress').compact.any? { |e| query.any? { |q| e.include?(q) } }
end
end
- if options['detail']
+ if options[:detail]
puts JSON.pretty_generate(selected)
else
net_intefraces = exec('ecs', 'DescribeNetworkInterfaces', '--pager', **options)['NetworkInterfaceSets']['NetworkInterfaceSet'].each_with_object({}) do |item, result|
result[item['NetworkInterfaceId']] = item
end
@@ -201,11 +201,11 @@
puts ' Listener Rules:'
puts listener_rules.table.to_s.gsub(/^/, ' ')
puts
- if options['acl']
+ if options[:acl]
acl_ids = listeners.flat_map { |listener| listener['AclIds'] || [] }.uniq
unless acl_ids.empty?
alc_entries = acl_ids.flat_map do |acl_id|
attr = exec('slb', 'DescribeAccessControlListAttribute', "--AclId=#{acl_id}", **options)
(attr.dig('AclEntrys', 'AclEntry') || []).each_with_index.map do |e, idx|
@@ -269,13 +269,13 @@
item['PublicIP'] += ips
end
item['AllIPs'] = item['PrivateIP'] + item['PublicIP']
end
- if options['full']
+ if options[:full]
full_slb(selected, eips, **options)
- elsif options['detail']
+ elsif options[:detail]
selected.each do |row|
described_load_balancer_attributes = exec('slb', 'DescribeLoadBalancerAttribute', "--LoadBalancerId=#{row['LoadBalancerId']}", **options)
row['BackendServers'] = described_load_balancer_attributes['BackendServers']['BackendServer']
row['Listeners'].select { |e| e['VServerGroupId'] }.each do |listener|
@@ -498,10 +498,10 @@
end
end
def exec(command, sub_command, *args, **options)
command = "aliyun #{command} #{sub_command} #{args.join(' ')}"
- command += " -p #{options['profile']}" if options['profile']
+ command += " -p #{options[:profile]}" if options[:profile]
JSON.parse(`#{command}`)
end
end
end