Class: KnifePlugins::RackspaceLoadBalancerShow

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

Instance Method Summary collapse

Methods included from Chef::Knife::RackspaceLoadBalancerNodes

#nodes_by_search, #resolve_node_ips_from_config

Methods included from Chef::Knife::RackspaceLoadBalancerBase

included, #lb_connection, #rackspace_api_credentials

Instance Method Details

#runObject



20
21
22
23
24
25
26
27
28
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
71
72
73
# File 'lib/chef/knife/rackspace_load_balancer_show.rb', line 20

def run
  @name_args.each do |load_balancer_id|
    load_balancer = lb_connection.get_load_balancer(load_balancer_id)
    nodes = load_balancer.list_nodes

    load_balancer_info = {
      :name => load_balancer.name,
      :id => load_balancer.id,
      :protocol => load_balancer.protocol,
      :port => load_balancer.port,
      :status => ui.color(load_balancer.status, load_balancer.status == "ACTIVE" ? :green : :red)
    }

    vip_list = [
      ui.color("Virtual Ip(s)", :bold),
      ui.color("Id", :bold),
      ui.color("Version", :bold),
    ]

    load_balancer.list_virtual_ips.each do |vip|
      vip_list << vip[:address].to_s
      vip_list << vip[:id].to_s
      vip_list << vip[:ipVersion].to_s
    end

    node_list = [
      ui.color("Node(s)", :bold),
      ui.color("Address", :bold),
      ui.color("Port", :bold),
      ui.color("Condition", :bold),
      ui.color("Status", :bold)
    ]

    nodes.each do |node|
      node_name = node[:id]

      if config[:resolve_node_names]
        first_node = nodes_by_search("private_ip:#{node[:address]}").first
        node_name = first_node.name unless first_node.nil? || first_node.name.nil?
      end

      node_list << node_name.to_s
      node_list << node[:address].to_s
      node_list << node[:port].to_s
      node_list << ui.color(node[:condition].to_s, node[:condition] == "ENABLED" ? :green : :red)
      node_list << ui.color(node[:status].to_s, node[:status] == "ONLINE" ? :green : :red)
    end

    ui.output(format_for_display(load_balancer_info))
    ui.output("\n")
    ui.output(ui.list(vip_list, :columns_across, 3))
    ui.output(ui.list(node_list, :columns_across, 5))
  end
end