Class: KnifePlugins::RackspaceLoadBalancerCreate

Inherits:
Chef::Knife
  • Object
show all
Includes:
Chef::Knife::RackspaceBase, Chef::Knife::RackspaceLoadBalancerBase, Chef::Knife::RackspaceLoadBalancerNodes
Defined in:
lib/chef/knife/rackspace_load_balancer_create.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



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/chef/knife/rackspace_load_balancer_create.rb', line 72

def run
  if @name_args.first.nil?
    ui.fatal("Must provide name")
    show_usage
    exit 1
  end

  unless [:add_nodes_by_search, :add_nodes_by_name, :add_nodes_by_private_ip].any? {|addition| not config[addition].nil?}
    ui.fatal("Must provide nodes via --add-nodes-by-search, --add-nodes-by-node-name, or --add-nodes-by-private-ip")
    show_usage
    exit 2
  end

  node_ips = resolve_node_ips_from_config({
    :by_search     => config[:add_nodes_by_search],
    :by_name       => config[:add_nodes_by_name],
    :by_private_ip => config[:add_nodes_by_private_ip]
  })

  nodes = node_ips.map do |ip|
    {
      :address => ip,
      :port => config[:node_port],
      :condition => config[:node_condition],
      :weight => config[:node_weight]
    }
  end

  load_balancer_configuration = {
    :name => @name_args.first,
    :protocol => config[:protocol],
    :port => config[:port],
    :algorithm => config[:algorithm],
    :nodes => nodes,
    :virtual_ip_type => config[:virtual_ip_type]
  }

  unless config[:virtual_ip_ids].nil?
    load_balancer_configuration[:virtual_ip_ids] = config[:virtual_ip_ids].split(",")
  end

  ui.output format_for_display(load_balancer_configuration)

  unless config[:force]
    ui.confirm("Do you really want to create this load balancer")
  end

  load_balancer_id = lb_connection.create_load_balancer(load_balancer_configuration)

  ui.output(ui.color("Created load balancer #{@name_args.first}", :green))
end