Class: Chef::Knife::CloudstackNetworkofferingList

Inherits:
Chef::Knife
  • Object
show all
Includes:
CloudstackBase
Defined in:
lib/chef/knife/cloudstack_networkoffering_list.rb

Instance Method Summary collapse

Methods included from CloudstackBase

#connection, included, #locate_config_value, #msg_pair, #validate!

Instance Method Details

#runObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/chef/knife/cloudstack_networkoffering_list.rb', line 29

def run
  $stdout.sync = true

  validate!

  network_list = [
    ui.color('ID', :bold),
    ui.color('Name', :bold),
    ui.color('Display Name', :bold),
    ui.color('Traffic Type', :bold),
    ui.color('State', :bold),
    ui.color('Service Offering ID', :bold)
  ]

  response = connection.list_network_offerings['listnetworkofferingsresponse']

  if networks = response['networkoffering']

    networks.each do |networkoffering|
      # puts networkoffering
      network_list << networkoffering['id'].to_s
      network_list << networkoffering['name'].to_s
      network_list << networkoffering['displaytext'].to_s
      network_list << networkoffering['traffictype'].to_s
      network_list << begin
        state = networkoffering['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
      network_list << networkoffering['serviceofferingid'].to_s
    end
  end

  puts ui.list(network_list, :uneven_columns_across, 6)

end