knife-rackspace-cluster 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chef/knife/rax_cluster_base.rb +7 -2
- data/lib/chef/knife/rax_cluster_change.rb +10 -10
- data/lib/chef/knife/rax_cluster_create.rb +51 -27
- data/lib/chef/knife/rax_cluster_delete.rb +5 -6
- data/lib/chef/knife/rax_cluster_expand.rb +11 -6
- data/lib/chef/knife/rax_cluster_list.rb +3 -3
- data/lib/chef/knife/rax_cluster_show.rb +72 -0
- metadata +3 -21
@@ -106,11 +106,16 @@ class Chef
|
|
106
106
|
"post" => "Net::HTTP::Post.new(uri.request_uri, headers)"
|
107
107
|
}
|
108
108
|
#Get to work boy! This is Ruby!
|
109
|
+
ssl_used = false
|
110
|
+
if uri =~ /https/
|
111
|
+
ssl_used = true
|
112
|
+
end
|
109
113
|
uri = URI.parse(uri)
|
114
|
+
|
110
115
|
http = Net::HTTP.new(uri.host, uri.port)
|
111
|
-
|
116
|
+
if ssl_used
|
112
117
|
http.use_ssl = true
|
113
|
-
|
118
|
+
end
|
114
119
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
115
120
|
request = eval verbs[httpVerb]
|
116
121
|
if httpVerb == 'post' or httpVerb == 'put'
|
@@ -31,11 +31,11 @@ class Chef
|
|
31
31
|
:long => "--chef-env environment",
|
32
32
|
:description => "Pass a comma delimted run list --run-list 'recipe[apt],role[base]'",
|
33
33
|
:proc => Proc.new { |chef_env| Chef::Config[:knife][:chef_env] = chef_env}
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
=begin
|
35
|
+
Takes an array of hashes of instance data and a block that provides
|
36
|
+
what work should be done. This function will look up the chef object
|
37
|
+
For the node and pass that object into the calling block.
|
38
|
+
=end
|
39
39
|
def change_chef_vars(instances, &block)
|
40
40
|
instances.each { |inst|
|
41
41
|
query = "name:#{inst['server_name']}"
|
@@ -45,11 +45,11 @@ class Chef
|
|
45
45
|
end
|
46
46
|
}
|
47
47
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
=begin
|
49
|
+
Looks up the LB meta data and grabs the server name for every node
|
50
|
+
In the LB pool
|
51
|
+
Looks them up in chef and changes there run_list or chef_env
|
52
|
+
=end
|
53
53
|
def run
|
54
54
|
if !config[:run_list] and !config[:chef_env]
|
55
55
|
ui.fatal "Please specify either --run-list or --chef-env to change on your cluster"
|
@@ -66,10 +66,10 @@ class Chef
|
|
66
66
|
#:long => "--session-persistence session_persistence_on_or_off",
|
67
67
|
#:description => "Load balancer session persistence on or off",
|
68
68
|
#:proc => Proc.new { |session_persistence| Chef::Config[:knife][:session_persistence] = session_persistence}
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
=begin
|
70
|
+
Generates a template json file in the current dir called
|
71
|
+
map_template.json
|
72
|
+
=end
|
73
73
|
def generate_map_template
|
74
74
|
file_name = "./map_template.json"
|
75
75
|
template = %q(
|
@@ -92,13 +92,13 @@ class Chef
|
|
92
92
|
|
93
93
|
File.open(file_name, 'w') { |file| file.write(template)}
|
94
94
|
end
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
def create_lb(instances)
|
95
|
+
=begin
|
96
|
+
Takes instance array of hash data and creates a load balancer.
|
97
|
+
Will put all nodes created in the LB pool (using private IP)
|
98
|
+
Will store servers in meta data using key = server name
|
99
|
+
value = uuid, this is for updates on chef vars on these nodes
|
100
|
+
=end
|
101
|
+
def create_lb(instances,error_text=nil)
|
102
102
|
lb_request = {
|
103
103
|
"loadBalancer" => {
|
104
104
|
"name" => @lb_name.to_s + "_cluster",
|
@@ -139,13 +139,16 @@ class Chef
|
|
139
139
|
lb_ip = ""
|
140
140
|
lb_details['loadBalancer']['virtualIps'].each {|lb| (lb['ipVersion'] == "IPV4") ? lb_ip = lb['address'] : "not_found"}
|
141
141
|
ui.msg "Load Balancer IP Address: #{lb_ip}"
|
142
|
+
if error_text
|
143
|
+
ui.msg "Some nodes failed to bootstrap or boot, verify with knife node list and or nova list to track down errors"
|
144
|
+
end
|
142
145
|
end
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
146
|
+
=begin
|
147
|
+
Parses json, creates blue_prints w/ specified chef vars
|
148
|
+
If ruby 1.9 is used builds will be spun up with Threads
|
149
|
+
If update_cluster is specified, an LB will not be created
|
150
|
+
an array of instance data will be returned to the caller
|
151
|
+
=end
|
149
152
|
def deploy(blue_print,update_cluster=nil)
|
150
153
|
(File.exist?(blue_print)) ? map_contents = JSON.parse(File.read(blue_print)) : map_contents = JSON.parse(blue_print)
|
151
154
|
sleep_interval = 1
|
@@ -169,6 +172,7 @@ class Chef
|
|
169
172
|
exit(1)
|
170
173
|
end
|
171
174
|
bootstrap_nodes = []
|
175
|
+
failed_attempts = 0
|
172
176
|
quantity = bp_values['quantity'].to_i
|
173
177
|
quantity.times do |node_name|
|
174
178
|
node_name = rand(900000000)
|
@@ -180,18 +184,26 @@ class Chef
|
|
180
184
|
Chef::Config[:environment] = bp_values['chef_env']
|
181
185
|
create_server.config[:run_list] = bp_values['run_list']
|
182
186
|
Chef::Config[:knife][:flavor] = bp_values['flavor']
|
183
|
-
|
184
|
-
bootstrap_nodes << Thread.new { Thread.current['server_return'] = create_server.run }
|
185
|
-
rescue
|
186
|
-
ui.msg "Bootstrapping failed"
|
187
|
-
end
|
187
|
+
bootstrap_nodes << Thread.new { Thread.current['server_return'] = create_server.run }
|
188
188
|
end
|
189
189
|
quantity.times do |times|
|
190
190
|
if quantity > 20
|
191
|
-
sleep_interval =
|
191
|
+
sleep_interval = 6
|
192
|
+
else
|
193
|
+
sleep_interval = 4
|
192
194
|
end
|
193
195
|
sleep(sleep_interval)
|
194
|
-
|
196
|
+
begin
|
197
|
+
bootstrap_nodes[times].join
|
198
|
+
rescue
|
199
|
+
failed_attempts += 1
|
200
|
+
if failed_attempts == quantity
|
201
|
+
ui.fatal "All servers failed to bootstrap, check network connectivy and vet all cookbooks used"
|
202
|
+
exit(1)
|
203
|
+
else
|
204
|
+
next
|
205
|
+
end
|
206
|
+
end
|
195
207
|
instances << {"server_name" => bootstrap_nodes[times]['server_return']['server_name'],
|
196
208
|
"ip_address" => bootstrap_nodes[times]['server_return']['private_ip'],
|
197
209
|
"uuid" => bootstrap_nodes[times]['server_return']['server_id'],
|
@@ -200,11 +212,23 @@ class Chef
|
|
200
212
|
"run_list" => bp_values['run_list']
|
201
213
|
}
|
202
214
|
end
|
203
|
-
|
215
|
+
end
|
204
216
|
if update_cluster
|
205
|
-
|
217
|
+
instance_return = {}
|
218
|
+
if failed_attempts > 0
|
219
|
+
instance_return = {'instances' => instances, "error_text" => true}
|
220
|
+
else
|
221
|
+
instance_return = {'instances' => instances, "error_text" => false}
|
222
|
+
end
|
223
|
+
|
224
|
+
return instance_return
|
206
225
|
else
|
207
|
-
|
226
|
+
if failed_attempts > 0
|
227
|
+
create_lb(instances,true)
|
228
|
+
else
|
229
|
+
create_lb(instances)
|
230
|
+
end
|
231
|
+
|
208
232
|
end
|
209
233
|
end
|
210
234
|
def run
|
@@ -21,15 +21,14 @@ class Chef
|
|
21
21
|
:description => "Load balancer region (only supports ORD || DFW)",
|
22
22
|
:proc => Proc.new { |lb_region| Chef::Config[:knife][:lb_region] = lb_region},
|
23
23
|
:default => "ORD"
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
=begin
|
25
|
+
Looks up all nodes from lb meta data, deletes them from chef and nova
|
26
|
+
Via knife rackspace method
|
27
|
+
AFter node deletion it will delete the LB
|
28
|
+
=end
|
29
29
|
def delete_cluster
|
30
30
|
lb_authenticate = authenticate()
|
31
31
|
lb_url = ""
|
32
|
-
puts config[:lb_region]
|
33
32
|
headers = {"x-auth-token" => lb_authenticate['auth_token'], "content-type" => "application/json"}
|
34
33
|
lb_authenticate['lb_urls'].each {|lb|
|
35
34
|
if config[:lb_region].to_s.downcase == lb['region'].to_s.downcase
|
@@ -33,16 +33,18 @@ class Chef
|
|
33
33
|
:description => "Load balancer region (only supports ORD || DFW)",
|
34
34
|
:proc => Proc.new { |lb_region| Chef::Config[:knife][:lb_region] = lb_region},
|
35
35
|
:default => "ORD"
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
=begin
|
37
|
+
This will take a blueprint file and call the raxClusterCreate
|
38
|
+
Class to handle parsing and building the nodes. It will then
|
39
|
+
update the LB ID passed on the CLI with the nodes and meta data
|
40
|
+
=end
|
41
41
|
def expand_cluster
|
42
42
|
rs_cluster = RaxClusterCreate.new
|
43
43
|
rs_cluster.config[:blue_print] = config[:blue_print]
|
44
44
|
rs_cluster.lb_name = @name_args[0]
|
45
45
|
instance_return = rs_cluster.deploy(config[:blue_print],'update_cluster')
|
46
|
+
instance_errors = instance_return['error_text']
|
47
|
+
instance_return = instance_return['instances']
|
46
48
|
lb_auth = authenticate()
|
47
49
|
puts lb_auth['auth_token']
|
48
50
|
headers = {"x-auth-token" => lb_auth['auth_token'], "content-type" => "application/json"}
|
@@ -77,7 +79,10 @@ class Chef
|
|
77
79
|
lb_stats = make_web_call("get", lb_status, headers)
|
78
80
|
lb_stats = JSON.parse(lb_stats.body)
|
79
81
|
end
|
80
|
-
node_request = make_web_call("post", node_url, headers, node_data_request.to_json)
|
82
|
+
node_request = make_web_call("post", node_url, headers, node_data_request.to_json)
|
83
|
+
if instance_errors
|
84
|
+
ui.msg "There were problems bootstrapping/booting nodes, verify with knife node list or nova list to track down issues"
|
85
|
+
end
|
81
86
|
ui.msg "Load balancer id #{@lb_id} has been updated"
|
82
87
|
|
83
88
|
end
|
@@ -22,9 +22,9 @@ class Chef
|
|
22
22
|
:default => "ORD"
|
23
23
|
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
=begin
|
26
|
+
Looks for lb's named $variable_cluster and lists them
|
27
|
+
=end
|
28
28
|
def run
|
29
29
|
lb_auth = authenticate
|
30
30
|
headers = {"x-auth-token" => lb_auth['auth_token'], "content-type" => "application/json"}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'chef/knife/rax_cluster_base'
|
2
|
+
class Chef
|
3
|
+
class Knife
|
4
|
+
class RaxClusterShow < Knife
|
5
|
+
|
6
|
+
include Knife::RaxClusterBase
|
7
|
+
|
8
|
+
banner "knife rax cluster show LB_ID -r lb_region"
|
9
|
+
deps do
|
10
|
+
require 'fog'
|
11
|
+
require 'readline'
|
12
|
+
require 'chef/json_compat'
|
13
|
+
require 'chef/knife/bootstrap'
|
14
|
+
Chef::Knife::Bootstrap.load_deps
|
15
|
+
end
|
16
|
+
|
17
|
+
option :lb_region,
|
18
|
+
:short => "-r lb_region",
|
19
|
+
:long => "--load-balancer-region lb_region",
|
20
|
+
:description => "Load balancer region (only supports ORD || DFW)",
|
21
|
+
:proc => Proc.new { |lb_region| Chef::Config[:knife][:lb_region] = lb_region},
|
22
|
+
:default => "ORD"
|
23
|
+
|
24
|
+
def run
|
25
|
+
if @name_args.empty?
|
26
|
+
ui.fatal "Please specify Load balancer ID to add nodes too"
|
27
|
+
exit(1)
|
28
|
+
end
|
29
|
+
lb_auth = authenticate
|
30
|
+
headers = {"x-auth-token" => lb_auth['auth_token'], "content-type" => "application/json"}
|
31
|
+
lb_url = ""
|
32
|
+
lb_auth['lb_urls'].each {|lb|
|
33
|
+
if config[:lb_region].to_s.downcase == lb['region'].to_s.downcase
|
34
|
+
lb_url = lb['publicURL']
|
35
|
+
break
|
36
|
+
end
|
37
|
+
lb_url = lb['publicURL']
|
38
|
+
}
|
39
|
+
@name_args.each {|arg|
|
40
|
+
lb_url = lb_url + "/loadbalancers/#{arg}.json"
|
41
|
+
lb_data = make_web_call("get", lb_url, headers)
|
42
|
+
lb_data = JSON.parse(lb_data.body)
|
43
|
+
lb = lb_data['loadBalancer']
|
44
|
+
msg_pair("LB Details for #{lb['name']}", " ")
|
45
|
+
msg_pair("\s\s\s\sLB ID", "#{lb['id']}")
|
46
|
+
msg_pair("\s\s\s\sLB Port", "#{lb['port']}")
|
47
|
+
msg_pair("\s\s\s\sLB Algorithm", "#{lb['algorithm']}")
|
48
|
+
msg_pair("\s\s\s\sLB Status", "#{lb['status']}")
|
49
|
+
msg_pair("\s\s\s\sLB timeout", "#{lb['timeout']}")
|
50
|
+
msg_pair("\s\s\s\sVirtual IPs", " ")
|
51
|
+
lb['virtualIps'].each {|ip|
|
52
|
+
msg_pair("\s\s\s\s\s\s\s\sAddress", "#{ip['address']}")
|
53
|
+
msg_pair("\s\s\s\s\s\s\s\sType", "#{ip['type']}")
|
54
|
+
ui.msg "\n"
|
55
|
+
}
|
56
|
+
msg_pair("\s\s\s\sNodes", " ")
|
57
|
+
lb['nodes'].each {|node|
|
58
|
+
msg_pair("\s\s\s\s\s\s\s\sNode Address", "#{node['address']}")
|
59
|
+
msg_pair("\s\s\s\s\s\s\s\sType", "#{node['type']}")
|
60
|
+
msg_pair("\s\s\s\s\s\s\s\sCondition", "#{node['condition']}")
|
61
|
+
msg_pair("\s\s\s\s\s\s\s\sPort", "#{node['port']}")
|
62
|
+
msg_pair("\s\s\s\s\s\s\s\sStatus", "#{node['status']}")
|
63
|
+
ui.msg "\n"
|
64
|
+
}
|
65
|
+
|
66
|
+
}
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-rackspace-cluster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 17
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 7
|
10
|
-
version: 0.0.7
|
5
|
+
version: 0.0.8
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- zack feldstein
|
@@ -25,11 +20,6 @@ dependencies:
|
|
25
20
|
requirements:
|
26
21
|
- - "="
|
27
22
|
- !ruby/object:Gem::Version
|
28
|
-
hash: 55
|
29
|
-
segments:
|
30
|
-
- 1
|
31
|
-
- 8
|
32
|
-
- 0
|
33
23
|
version: 1.8.0
|
34
24
|
type: :runtime
|
35
25
|
version_requirements: *id001
|
@@ -41,9 +31,6 @@ dependencies:
|
|
41
31
|
requirements:
|
42
32
|
- - ">="
|
43
33
|
- !ruby/object:Gem::Version
|
44
|
-
hash: 3
|
45
|
-
segments:
|
46
|
-
- 0
|
47
34
|
version: "0"
|
48
35
|
type: :runtime
|
49
36
|
version_requirements: *id002
|
@@ -63,6 +50,7 @@ files:
|
|
63
50
|
- lib/chef/knife/rax_cluster_delete.rb
|
64
51
|
- lib/chef/knife/rax_cluster_expand.rb
|
65
52
|
- lib/chef/knife/rax_cluster_list.rb
|
53
|
+
- lib/chef/knife/rax_cluster_show.rb
|
66
54
|
- lib/chef/knife/super_rax.rb
|
67
55
|
homepage: http://github.com/jrcloud/knife_rax_cluster
|
68
56
|
licenses: []
|
@@ -77,23 +65,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
65
|
requirements:
|
78
66
|
- - ">="
|
79
67
|
- !ruby/object:Gem::Version
|
80
|
-
hash: 3
|
81
|
-
segments:
|
82
|
-
- 0
|
83
68
|
version: "0"
|
84
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
70
|
none: false
|
86
71
|
requirements:
|
87
72
|
- - ">="
|
88
73
|
- !ruby/object:Gem::Version
|
89
|
-
hash: 3
|
90
|
-
segments:
|
91
|
-
- 0
|
92
74
|
version: "0"
|
93
75
|
requirements: []
|
94
76
|
|
95
77
|
rubyforge_project:
|
96
|
-
rubygems_version: 1.8.
|
78
|
+
rubygems_version: 1.8.23
|
97
79
|
signing_key:
|
98
80
|
specification_version: 3
|
99
81
|
summary: Knife rax cluster
|