lib/cloudstack-cli/commands/network.rb in cloudstack-cli-0.0.5 vs lib/cloudstack-cli/commands/network.rb in cloudstack-cli-0.1.0

- old
+ new

@@ -1,71 +1,50 @@ -class Network < Thor - include CommandLineReporter +class Network < CloudstackCli::Base - desc "network create NAME", "create network" + desc "create NAME", "create network" def create(name) - - + # TODO end - desc "network list", "list networks" + desc "list", "list networks" option :project option :physical, type: :boolean def list - cs_cli = CloudstackCli::Helper.new(options[:config]) - if options[:project] - project = cs_cli.projects.select { |p| p['name'] == options[:project] }.first - raise "Project '#{options[:project]}' not found" unless project - end - + project = find_project if options[:project] if options[:physical] - networks = cs_cli.physical_networks + networks = client.list_physical_networks if networks.size < 1 puts "No networks found" else - table(border: true) do - row do - column 'ID', width: 40 - column 'Name', width: 30 - column 'Zone ID', width: 14 unless options[:project] - column 'State' - end - networks.each do |network| - row do - column network["id"] - column network["name"] - column network["zoneid"] - column network["state"] - end - end + table = [['Name', 'State', 'ID', 'Zone ID']] + networks.each do |network| + table << [ + network["name"], + network["state"], + network["id"], + network["zoneid"] + ] end + print_table table end else - networks = cs_cli.networks(project ? project['id'] : -1) + networks = client.list_networks(project ? project['id'] : -1) if networks.size < 1 puts "No networks found" else - table(border: true) do - row do - column 'ID', width: 40 - column 'Name', width: 30 - column 'Displaytext', width: 30 - column 'Account', width: 14 unless options[:project] - column 'Project', width: 14 if options[:listall] || options[:project] - column 'State' - end - networks.each do |network| - row do - column network["id"] - column network["name"] - column network["displaytext"] - column network["account"] unless options[:project] - column network["project"] if options[:listall] || options[:project] - column network["state"] - end - end + table = [["Name", "Displaytext", "Account", "Project", "State", "ID"]] + networks.each do |network| + table << [ + network["name"], + network["displaytext"], + network["account"], + network["project"], + network["state"], + network["id"] + ] end + print_table table end end - end + end \ No newline at end of file