Class: Chef::Knife::RaxClusterExpand

Inherits:
Chef::Knife show all
Includes:
RaxClusterBase
Defined in:
lib/chef/knife/rax_cluster_expand.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RaxClusterBase

#authenticate, included, #make_web_call, #msg_pair, #populate_environment

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



7
8
9
# File 'lib/chef/knife/rax_cluster_expand.rb', line 7

def headers
  @headers
end

#lb_idObject

Returns the value of attribute lb_id.



7
8
9
# File 'lib/chef/knife/rax_cluster_expand.rb', line 7

def lb_id
  @lb_id
end

#rax_endpointObject

Returns the value of attribute rax_endpoint.



7
8
9
# File 'lib/chef/knife/rax_cluster_expand.rb', line 7

def rax_endpoint
  @rax_endpoint
end

Instance Method Details

#expand_clusterObject



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
74
75
76
77
78
79
80
# File 'lib/chef/knife/rax_cluster_expand.rb', line 38

def expand_cluster
     rs_cluster = RaxClusterCreate.new
     rs_cluster.config[:blue_print]  = config[:blue_print]
     rs_cluster.lb_name = @name_args[0]
     instance_return = rs_cluster.deploy(config[:blue_print],'update_cluster')
     lb_auth = authenticate()
     puts lb_auth['auth_token']
     headers = {"x-auth-token" => lb_auth['auth_token'], "content-type" => "application/json"}
     lb_url = ""
     lb_auth['lb_urls'].each {|lb|
       if config[:lb_region].to_s.downcase ==  lb['region'].to_s.downcase
         lb_url = lb['publicURL']
         break
       end
       lb_url = lb['publicURL']
       }
      = {
       "metadata" => []        
     }
     node_data_request = {
       "nodes" => []
     }
     meta_url = lb_url + "/loadbalancers/#{@lb_id}/metadata"
     node_url = lb_url + "/loadbalancers/#{@lb_id}/nodes"
     
     instance_return.each {|inst|
       node_data_request['nodes'] << {"address" => inst['ip_address'], 'port' =>Chef::Config[:knife][:port] || '80', "condition" => "ENABLED" }          
       ['metadata'] << {"key" => inst['server_name'], "value" => inst['uuid']} 
       }
     meta_request = make_web_call("post", meta_url, headers, .to_json)
     lb_status = lb_url + "/loadbalancers/#{@lb_id}"
     lb_stats = make_web_call("get", lb_status, headers)
     lb_stats = JSON.parse(lb_stats.body)

     while lb_stats['loadBalancer']['status'].to_s.downcase != 'active'
       sleep(5)
       lb_stats = make_web_call("get", lb_status, headers)
       lb_stats = JSON.parse(lb_stats.body)
     end
     node_request = make_web_call("post", node_url, headers, node_data_request.to_json)        
     ui.msg "Load balancer id #{@lb_id} has been updated"
     
end

#runObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/chef/knife/rax_cluster_expand.rb', line 82

def run
     if @name_args.empty?
       ui.fatal "Please specify Load balancer ID to add nodes too"
       exit(1)
     end
     if !config[:blue_print]
       ui.fatal "Please specify a blue print file to parse with -B"
       exit(1)
     end
     
     if config[:blue_print]
       @lb_id = @name_args[0]
       expand_cluster
     end
     
end