Class: KnifePlugins::RackspaceLoadBalancerList

Inherits:
Chef::Knife
  • Object
show all
Includes:
Chef::Knife::RackspaceBase, Chef::Knife::RackspaceLoadBalancerBase
Defined in:
lib/chef/knife/rackspace_load_balancer_list.rb

Instance Method Summary collapse

Methods included from Chef::Knife::RackspaceLoadBalancerBase

included, #lb_connection, #rackspace_api_credentials

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/chef/knife/rackspace_load_balancer_list.rb', line 14

def run
  load_balancer_list = [
    ui.color("Id", :bold),
    ui.color("Name", :bold),
    ui.color("Nodes", :bold),
    ui.color("Virtual Ip", :bold),
    ui.color("Protocol / Port", :bold),
    ui.color("Status", :bold),
  ]

  lb_connection.list_load_balancers.each do |load_balancer|
    vip = (load_balancer[:virtualIps].detect {|vip| vip[:ipVersion] == "IPV4"})
    vip ||= load_balancer[:virtualIps].first

    load_balancer_list << load_balancer[:id].to_s
    load_balancer_list << load_balancer[:name].to_s
    load_balancer_list << load_balancer[:nodeCount].to_s
    load_balancer_list << (vip.nil? ? "None" : vip[:address].to_s)
    load_balancer_list << "#{load_balancer[:protocol]} / #{load_balancer[:port].to_s}"
    load_balancer_list << ui.color(load_balancer[:status].to_s, load_balancer[:status] == "ACTIVE" ? :green : :red)
  end

  puts ui.list(load_balancer_list, :columns_across, 6)
end