class Chef::Knife::CloudstackNetworkList

Public Instance Methods

run() click to toggle source
# File lib/chef/knife/cloudstack_network_list.rb, line 29
def run
  $stdout.sync = true

  validate!

  network_list = [
    ui.color('ID', :bold),
    ui.color('Name', :bold),
    ui.color('Zone ID', :bold),
    ui.color('VLAN', :bold),
    ui.color('State', :bold)
  ]
  response = connection.list_networks['listnetworksresponse']
    if networks = response['network']
      networks.each do |network|
        network_list << network['id'].to_s
        network_list << network['name'].to_s
        network_list << network['zoneid'].to_s
        network_list << network['vlan'].to_s
        network_list << begin
          state = network['state'].to_s.downcase
          case state
            when 'allocated'
              ui.color(state, :red)
            when 'pending'
              ui.color(state, :yellow)
            else
              ui.color(state, :green)
          end
        end
      end
    end
  puts ui.list(network_list, :columns_across, 5)

end