This changes the custom code in UbiCli and the cli-commands files to use the Ruby SDK for all changes. This is slightly slower, but allows for testing Ruby SDK using the existing tests for the CLI. The only spec change is to an error message, and the error message is now more helpful. As the Ruby SDK uses symbol keys instead of string keys, this switches UbiCli and the cli-commands files to also use symbol keys. This adds an UbiCli#check_no_slash helper method to DRY up code that checks for slashes in strings used as path fragments.
36 lines
982 B
Ruby
36 lines
982 B
Ruby
# frozen_string_literal: true
|
|
|
|
UbiCli.on("lb").run_on("show") do
|
|
desc "Show details for a load balancer"
|
|
|
|
fields = %w[id name state location hostname algorithm stack health-check-endpoint health-check-protocol src-port dst-port subnet vms].freeze.each(&:freeze)
|
|
|
|
options("ubi lb (location/lb-name | lb-id) show [options]", key: :lb_show) do
|
|
on("-f", "--fields=fields", "show specific fields (comma separated)")
|
|
end
|
|
help_option_values("Fields:", fields)
|
|
|
|
run do |opts|
|
|
data = sdk_object.info
|
|
keys = underscore_keys(check_fields(opts[:lb_show][:fields], fields, "lb show -f option"))
|
|
|
|
body = []
|
|
|
|
keys.each do |key|
|
|
case key
|
|
when :vms
|
|
body << "vms:\n"
|
|
data[key].each do |vm|
|
|
body << " " << vm.id << "\n"
|
|
end
|
|
when :subnet
|
|
body << key.to_s << ": " << data.subnet.name << "\n"
|
|
else
|
|
body << key.to_s << ": " << data[key].to_s << "\n"
|
|
end
|
|
end
|
|
|
|
response(body)
|
|
end
|
|
end
|