cap-rightscale 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.2.5
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cap-rightscale}
8
- s.version = "0.2.4"
8
+ s.version = "0.2.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Satoshi Ohki"]
@@ -33,8 +33,10 @@ Gem::Specification.new do |s|
33
33
  "lib/cap-rightscale/configuration.rb",
34
34
  "lib/cap-rightscale/configuration/rightscale.rb",
35
35
  "lib/cap-rightscale/recipes.rb",
36
+ "lib/cap-rightscale/recipes/rightscale.rb",
36
37
  "lib/cap-rightscale/recipes/rightscale/cache.rb",
37
38
  "lib/cap-rightscale/utils/rs_utils.rb",
39
+ "rsapiconfig.yml.sample",
38
40
  "spec/cap-rightscale_spec.rb",
39
41
  "spec/spec_helper.rb"
40
42
  ]
@@ -4,7 +4,7 @@ require 'ping'
4
4
  module Capistrano
5
5
  class Configuration
6
6
  module RightScale
7
- attr_writer :validate_echo, :use_nickname, :use_public_ip
7
+ attr_writer :validate_echo, :use_nickname, :use_public_ip, :use_rs_cache
8
8
 
9
9
  def get_rs_confpath
10
10
  @rs_confpath ||= File.join(ENV['HOME'], ".rsconf", "rsapiconfig.yml")
@@ -55,20 +55,20 @@ start = Time.now
55
55
 
56
56
  params.delete(:array_id) # remove rightscale's parameters
57
57
 
58
- host_list = get_server_cache(role) # Get cache
58
+ host_list = use_rs_cache ? get_server_cache(role) : [] # Get cache
59
59
 
60
60
  if host_list && host_list.size > 0
61
61
  logger.info("restore cache of servers:\n#{host_list.pretty_inspect}")
62
62
  role(role, params) { host_list } # set cache to role()
63
63
  else
64
64
  # Request RightScale API
65
- array = get_array(_array_id)
65
+ array = rs_array(_array_id)
66
66
  logger.info("querying rightscale for server_array #{array.nickname}...")
67
- dept = get_deployment(array.deployment_href.match(/[0-9]+$/).to_s, :server_settings => 'true')
67
+ dept = rs_deployment(array.deployment_href.match(/[0-9]+$/).to_s, :server_settings => 'true')
68
68
  deployment_name = dept.nickname
69
69
  logger.info("Deployment #{deployment_name}:")
70
70
 
71
- host_list = ServerArray.instances(array.id).select {|i| i[:state] == "operational"}.map do |instance|
71
+ host_list = rs_array_instances(array.id).select {|i| i[:state] == "operational"}.map do |instance|
72
72
  hostname = instance[:nickname].sub(/ #[0-9]+$/, "-%03d" % instance[:nickname].match(/[0-9]+$/).to_s.to_i)
73
73
  hostname << ".#{_domain}" if _domain
74
74
  ip = use_public_ip ? instance[:ip_address] : instance[:private_ip_address]
@@ -83,7 +83,7 @@ start = Time.now
83
83
 
84
84
  if host_list && host_list.size > 0
85
85
  role(role, params) { host_list }
86
- dump_server_cache(role, host_list) # Dump cache
86
+ dump_server_cache(role, host_list) if use_rs_cache # Dump cache
87
87
  end
88
88
  end
89
89
  puts "Time: #{Time.now - start}"
@@ -114,14 +114,14 @@ start = Time.now
114
114
  params.delete(:deployment)
115
115
  params.delete(:name_prefix) if params.has_key?(:name_prefix)
116
116
 
117
- host_list = get_server_cache(role) # Get cache
117
+ host_list = use_rs_cache ? get_server_cache(role) : [] # Get cache
118
118
 
119
119
  if host_list && host_list.size > 0
120
120
  logger.info("restore cache of servers:\n#{host_list.pretty_inspect}")
121
121
  role(role, params) { host_list } # set cache to role()
122
122
  else
123
123
  # Request RightScale API
124
- dept = get_deployment(_dept_id, :server_settings => 'true')
124
+ dept = rs_deployment(_dept_id, :server_settings => 'true')
125
125
  logger.info("querying rightscale for servers #{_name_prefix} in deployment #{dept.nickname}...")
126
126
  srvs = dept.servers.select {|s| s[:state] == "operational"}
127
127
  srvs = srvs.select {|s| /#{_name_prefix}/ =~ s[:nickname]} if _name_prefix
@@ -141,7 +141,7 @@ start = Time.now
141
141
 
142
142
  if host_list && host_list.size > 0
143
143
  role(role, params) { host_list }
144
- dump_server_cache(role, host_list) # Dump cache
144
+ dump_server_cache(role, host_list) if use_rs_cache # Dump cache
145
145
  end
146
146
  end
147
147
  puts "Time: #{Time.now - start}"
@@ -173,14 +173,14 @@ start = Time.now
173
173
  params.delete(:deployment)
174
174
  params.delete(:tags)
175
175
 
176
- host_list = get_server_cache(role) # Get cache
176
+ host_list = use_rs_cache ? get_server_cache(role) : [] # Get cache
177
177
 
178
178
  if host_list && host_list.size > 0
179
179
  logger.info("restore cache of servers:\n#{host_list.pretty_inspect}")
180
180
  role(role, params) { host_list } # set cache to role()
181
181
  else
182
182
  # Request RightScale API
183
- dept = get_deployment(_dept_id, :server_settings => 'true')
183
+ dept = rs_deployment(_dept_id, :server_settings => 'true')
184
184
  logger.info("querying rightscale for servers matching tags #{_tags} in deployment #{dept.nickname}...")
185
185
  srvs = dept.servers.select {|s| s[:state] == "operational"}
186
186
 
@@ -211,7 +211,7 @@ start = Time.now
211
211
 
212
212
  if host_list && host_list.size > 0
213
213
  role(role, params) { host_list }
214
- dump_server_cache(role, host_list) # Dump cache
214
+ dump_server_cache(role, host_list) if use_rs_cache # Dump cache
215
215
  end
216
216
  end
217
217
  puts "Time: #{Time.now - start}"
@@ -225,13 +225,13 @@ puts "Time: #{Time.now - start}"
225
225
  return true
226
226
  end
227
227
 
228
- def get_array(id)
228
+ def rs_array(id, params={})
229
229
  array = self.instance_variable_get("@array_#{id}")
230
230
 
231
231
  unless array
232
232
  connect
233
233
  begin
234
- self.instance_variable_set("@array_#{id}", ServerArray.show(id))
234
+ self.instance_variable_set("@array_#{id}", ServerArray.show(id, params))
235
235
  rescue => e
236
236
  STDERR.puts("#{e.class}: #{e.pretty_inspect}")
237
237
  warn("Backtrace:\n#{e.backtrace.pretty_inspect}")
@@ -249,7 +249,31 @@ puts "Time: #{Time.now - start}"
249
249
  array
250
250
  end
251
251
 
252
- def get_deployment(id, params)
252
+ def rs_array_instances(id)
253
+ array_instances = self.instance_variable_get("@array_instances_#{id}")
254
+
255
+ unless array_instances
256
+ connect
257
+ begin
258
+ self.instance_variable_set("@array_instances_#{id}", ServerArray.instances(id))
259
+ rescue => e
260
+ STDERR.puts("#{e.class}: #{e.pretty_inspect}")
261
+ warn("Backtrace:\n#{e.backtrace.pretty_inspect}")
262
+ exit(1)
263
+ end
264
+
265
+ unless ServerArray.status_code == 200
266
+ STDERR.puts("Errors: STATUS is NOT 200 OK")
267
+ warn(ServerArray.headers)
268
+ exit(1)
269
+ end
270
+
271
+ array_instances = self.instance_variable_get("@array_instances_#{id}")
272
+ end
273
+ array_instances
274
+ end
275
+
276
+ def rs_deployment(id, params={})
253
277
  dept = self.instance_variable_get("@deployment_#{id}")
254
278
 
255
279
  unless dept
@@ -279,8 +303,17 @@ puts "Time: #{Time.now - start}"
279
303
  @conn ||= RightResource::Connection.new do |c|
280
304
  c.login(:username => @auth["username"], :password => @auth["password"], :account => @auth["account"])
281
305
  end
282
- rescue Errno::ENOENT => e
283
- STDERR.puts("Cannot loaded RightScale Auth data!!:\nusername: foo@example.com\npassword: password\naccount: 22329\n")
306
+ rescue => e
307
+ auth_data = open(File.join(File.expand_path(File.dirname(__FILE__)), '/../../../rsapiconfig.yml.sample')) {|f| f.read}
308
+ STDERR.puts <<-"USAGE"
309
+ Cannot load RightScale Auth data!!:
310
+ Put authfile:<rsapiconfig.yml> in <HOME>/.rsconf/
311
+ OR
312
+ Set param: set_rs_confpath <authfile_path>
313
+
314
+ Authfile contents:
315
+ #{auth_data}
316
+ USAGE
284
317
  exit(1)
285
318
  end
286
319
  RightResource::Base.connection = @conn
@@ -351,6 +384,15 @@ puts "Time: #{Time.now - start}"
351
384
  @use_public_ip ||= false
352
385
  end
353
386
 
387
+ def use_rs_cache
388
+ if @use_rs_cache.nil? && ENV['RSCACHE']
389
+ env = ENV['RSCACHE'].downcase
390
+ @use_rs_cache = false if env == "false"
391
+ end
392
+ @use_rs_cache = true if @use_rs_cache.nil?
393
+ @use_rs_cache
394
+ end
395
+
354
396
  def _domain
355
397
  @domain || nil
356
398
  end
@@ -0,0 +1,11 @@
1
+ namespace :rightscale do
2
+ desc "Dry run"
3
+ task :dry_run do
4
+ nil
5
+ end
6
+
7
+ desc "Dry run"
8
+ task :noop do
9
+ dry_run
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ username: user@example.com
2
+ password: yourpassword
3
+ account: 1
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cap-rightscale
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 4
10
- version: 0.2.4
9
+ - 5
10
+ version: 0.2.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Satoshi Ohki
@@ -151,8 +151,10 @@ files:
151
151
  - lib/cap-rightscale/configuration.rb
152
152
  - lib/cap-rightscale/configuration/rightscale.rb
153
153
  - lib/cap-rightscale/recipes.rb
154
+ - lib/cap-rightscale/recipes/rightscale.rb
154
155
  - lib/cap-rightscale/recipes/rightscale/cache.rb
155
156
  - lib/cap-rightscale/utils/rs_utils.rb
157
+ - rsapiconfig.yml.sample
156
158
  - spec/cap-rightscale_spec.rb
157
159
  - spec/spec_helper.rb
158
160
  has_rdoc: true