lib/cloudstack-cli/commands/port_rule.rb in cloudstack-cli-1.4.1 vs lib/cloudstack-cli/commands/port_rule.rb in cloudstack-cli-1.4.2
- old
+ new
@@ -42,28 +42,37 @@
end
end
desc "list", "list portforwarding rules"
option :project
+ option :format, default: "table",
+ enum: %w(table json yaml)
def list
resolve_project
rules = client.list_port_forwarding_rules(options)
if rules.size < 1
puts "No rules found."
else
- table = [["IP", "Server", "Public-Port", "Private-Port", "Protocol", "State"]]
- rules.each do |rule|
- table << [
- rule['ipaddress'],
- rule['virtualmachinename'],
- print_ports(rule, 'public'),
- print_ports(rule, 'private'),
- rule['protocol'],
- rule['state']
- ]
+ case options[:format].to_sym
+ when :yaml
+ puts({rules: rules}.to_yaml)
+ when :json
+ puts JSON.pretty_generate(rules: rules)
+ else
+ table = [["IP", "Server", "Public-Port", "Private-Port", "Protocol", "State"]]
+ rules.each do |rule|
+ table << [
+ rule['ipaddress'],
+ rule['virtualmachinename'],
+ print_ports(rule, 'public'),
+ print_ports(rule, 'private'),
+ rule['protocol'],
+ rule['state']
+ ]
+ end
+ print_table table
+ say "Total number of rules: #{rules.count}"
end
- print_table table
- say "Total number of rules: #{rules.count}"
end
end
no_commands do
def print_ports(rule, type)