knife-rackspace-cluster 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -107,11 +107,10 @@ class Chef
107
107
  }
108
108
  #Get to work boy! This is Ruby!
109
109
  uri = URI.parse(uri)
110
-
111
110
  http = Net::HTTP.new(uri.host, uri.port)
112
- #if uri.host =~ /https/
111
+ if uri.host =~ /https/
113
112
  http.use_ssl = true
114
- #end
113
+ end
115
114
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
116
115
  request = eval verbs[httpVerb]
117
116
  if httpVerb == 'post' or httpVerb == 'put'
@@ -1,4 +1,7 @@
1
-
1
+ #=====================================================================
2
+ # Had to subclass this from knife-rackspace, neeeded to return the
3
+ # Instance data after build/bootstrap
4
+ #=====================================================================
2
5
  require 'chef/knife/rackspace_server_create'
3
6
  class Chef
4
7
  class Knife
@@ -29,7 +29,11 @@ class Chef
29
29
  :long => "--chef-env environment",
30
30
  :description => "Pass a comma delimted run list --run-list 'recipe[apt],role[base]'",
31
31
  :proc => Proc.new { |chef_env| Chef::Config[:knife][:chef_env] = chef_env}
32
-
32
+ #=====================================================================
33
+ # Takes an array of hashes of instance data and a block that provides
34
+ # what work should be done. This function will look up the chef object
35
+ # For the node and pass that object into the calling block.
36
+ #=====================================================================
33
37
  def change_chef_vars(instances, &block)
34
38
  instances.each { |inst|
35
39
  query = "name:#{inst['server_name']}"
@@ -39,6 +43,11 @@ class Chef
39
43
  end
40
44
  }
41
45
  end
46
+ #=====================================================================
47
+ # Looks up the LB meta data and grabs the server name for every node
48
+ # In the LB pool
49
+ # Looks them up in chef and changes there run_list or chef_env
50
+ #=====================================================================
42
51
  def run
43
52
  if !config[:run_list] and !config[:chef_env]
44
53
  ui.fatal "Please specify either --run-list or --chef-env to change on your cluster"
@@ -66,7 +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
-
69
+ #================================================================
70
+ # Generates a template json file in the current dir called
71
+ # map_template.json
72
+ #================================================================
70
73
  def generate_map_template
71
74
  file_name = "./map_template.json"
72
75
  template = %q(
@@ -89,6 +92,12 @@ class Chef
89
92
 
90
93
  File.open(file_name, 'w') { |file| file.write(template)}
91
94
  end
95
+ #================================================================
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
+ #================================================================
92
101
  def create_lb(instances)
93
102
  lb_request = {
94
103
  "loadBalancer" => {
@@ -131,14 +140,34 @@ class Chef
131
140
  lb_details['loadBalancer']['virtualIps'].each {|lb| (lb['ipVersion'] == "IPV4") ? lb_ip = lb['address'] : "not_found"}
132
141
  ui.msg "Load Balancer IP Address: #{lb_ip}"
133
142
  end
134
-
135
-
143
+ #============================================================
144
+ # Parses json, creates blue_prints w/ specified chef vars
145
+ # If ruby 1.9 is used builds will be spun up with Threads
146
+ # If update_cluster is specified, an LB will not be created
147
+ # an array of instance data will be returned to the caller
148
+ #============================================================
136
149
  def deploy(blue_print,update_cluster=nil)
137
150
  (File.exist?(blue_print)) ? map_contents = JSON.parse(File.read(blue_print)) : map_contents = JSON.parse(blue_print)
138
151
  sleep_interval = 1
139
152
  instances = []
140
153
  if map_contents.has_key?("blue_print")
141
154
  bp_values = map_contents['blue_print']
155
+ unless bp_values.has_key?("image_ref")
156
+ ui.fatal "You must specify an image_ref, run the -G command to generate a template blueprint"
157
+ exit(1)
158
+ end
159
+ unless bp_values.has_key?("name_convention")
160
+ ui.fatal "You must specify a name_convention, run the -G command to generate a template blueprint"
161
+ exit(1)
162
+ end
163
+ unless bp_values.has_key?("flavor")
164
+ ui.fatal "You must specify a flavor, run the -G command to generate a template blueprint"
165
+ exit(1)
166
+ end
167
+ unless bp_values.has_key?("quantity")
168
+ ui.fatal "You must specify a quantity of servers, run the -G command to generate a template blueprint"
169
+ exit(1)
170
+ end
142
171
  bootstrap_nodes = []
143
172
  quantity = bp_values['quantity'].to_i
144
173
  quantity.times do |node_name|
@@ -156,7 +185,6 @@ class Chef
156
185
  rescue
157
186
  ui.msg "Bootstrapping failed"
158
187
  end
159
-
160
188
  end
161
189
  quantity.times do |times|
162
190
  if quantity > 20
@@ -178,11 +206,7 @@ class Chef
178
206
  else
179
207
  create_lb(instances)
180
208
  end
181
-
182
-
183
-
184
209
  end
185
-
186
210
  def run
187
211
  #Generate template config
188
212
  if config[:generate_map_template]
@@ -190,8 +214,6 @@ class Chef
190
214
  ui.msg "Map template saved as ./map_template.json"
191
215
  exit()
192
216
  end
193
-
194
-
195
217
  if @name_args.empty? or @name_args.size > 1
196
218
  ui.fatal "Please specify a single name for your cluster"
197
219
  exit(1)
@@ -21,7 +21,11 @@ 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
-
24
+ #=====================================================================
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
+ #=====================================================================
25
29
  def delete_cluster
26
30
  lb_authenticate = authenticate()
27
31
  lb_url = ""
@@ -34,7 +34,11 @@ class Chef
34
34
  :description => "Load balancer region (only supports ORD || DFW)",
35
35
  :proc => Proc.new { |lb_region| Chef::Config[:knife][:lb_region] = lb_region},
36
36
  :default => "ORD"
37
-
37
+ #================================================================
38
+ # This will take a blueprint file and call the raxClusterCreate
39
+ # Class to handle parsing and building the nodes. It will then
40
+ # update the LB ID passed on the CLI with the nodes and meta data
41
+ #================================================================
38
42
  def expand_cluster
39
43
  rs_cluster = RaxClusterCreate.new
40
44
  rs_cluster.config[:blue_print] = config[:blue_print]
@@ -20,8 +20,10 @@ class Chef
20
20
  :proc => Proc.new { |lb_region| Chef::Config[:knife][:lb_region] = lb_region},
21
21
  :default => "ORD"
22
22
 
23
-
24
-
23
+
24
+ #=====================================================================
25
+ # Looks for lb's named $variable_cluster and lists them
26
+ #=====================================================================
25
27
  def run
26
28
  lb_auth = authenticate
27
29
  headers = {"x-auth-token" => lb_auth['auth_token'], "content-type" => "application/json"}
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-rackspace-cluster
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease:
5
- version: 0.0.5
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 6
10
+ version: 0.0.6
6
11
  platform: ruby
7
12
  authors:
8
13
  - zack feldstein
@@ -20,6 +25,11 @@ dependencies:
20
25
  requirements:
21
26
  - - "="
22
27
  - !ruby/object:Gem::Version
28
+ hash: 55
29
+ segments:
30
+ - 1
31
+ - 8
32
+ - 0
23
33
  version: 1.8.0
24
34
  type: :runtime
25
35
  version_requirements: *id001
@@ -31,6 +41,9 @@ dependencies:
31
41
  requirements:
32
42
  - - ">="
33
43
  - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
34
47
  version: "0"
35
48
  type: :runtime
36
49
  version_requirements: *id002
@@ -64,17 +77,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
77
  requirements:
65
78
  - - ">="
66
79
  - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
67
83
  version: "0"
68
84
  required_rubygems_version: !ruby/object:Gem::Requirement
69
85
  none: false
70
86
  requirements:
71
87
  - - ">="
72
88
  - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
73
92
  version: "0"
74
93
  requirements: []
75
94
 
76
95
  rubyforge_project:
77
- rubygems_version: 1.8.23
96
+ rubygems_version: 1.8.10
78
97
  signing_key:
79
98
  specification_version: 3
80
99
  summary: Knife rax cluster