cap-rightscale 0.2.6 → 0.3.0

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.6
1
+ 0.3.0
@@ -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.6"
8
+ s.version = "0.3.0"
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"]
@@ -76,25 +76,13 @@ start = Time.now
76
76
 
77
77
  host_list = get_rs_instance.__send__(:array_instances, array.id).select {|i| i[:state] == "operational"}.map do |instance|
78
78
  hostname = instance[:nickname].sub(/ #[0-9]+$/, "-%03d" % instance[:nickname].match(/[0-9]+$/).to_s.to_i)
79
- hostname << ".#{_domain}" if _domain
79
+ hostname << ".#{_domain}" if _domain && hostname.match(/#{_domain}/).nil?
80
80
  ip = use_public_ip ? instance[:ip_address] : instance[:private_ip_address]
81
81
 
82
82
  logger.info("Found server: #{hostname}(#{ip})")
83
83
  use_nickname ? hostname : ip
84
84
  end
85
-
86
- if validate_echo
87
- threads = []
88
- host_list.each do |host|
89
- puts host
90
- threads << Thread.new {Ping.pingecho(host)}
91
- end
92
- threads.each.with_index do |t,i|
93
- host_list[i] = nil if t.value == false
94
- end
95
- threads.clear
96
- host_list.delete(nil)
97
- end
85
+ host_list = _valid_echo(host_list) if validate_echo
98
86
 
99
87
  if host_list && host_list.size > 0
100
88
  role(role, params) { host_list }
@@ -138,30 +126,18 @@ start = Time.now
138
126
  # Request RightScale API
139
127
  dept = get_rs_instance.__send__(:deployment, _dept_id, :server_settings => 'true')
140
128
  logger.info("querying rightscale for servers #{_name_prefix} in deployment #{dept.nickname}...")
141
- # srvs = dept.servers.select {|s| s[:state] == "operational"}
142
- srvs = dept.servers
129
+ srvs = dept.servers.select {|s| s[:state] == "operational"}
143
130
  srvs = srvs.select {|s| /#{_name_prefix}/ =~ s[:nickname]} if _name_prefix
144
131
 
145
132
  host_list = srvs.map do |server|
146
133
  hostname = server[:nickname]
147
- hostname << ".#{_domain}" if _domain
134
+ hostname << ".#{_domain}" if _domain && hostname.match(/#{_domain}/).nil?
148
135
  ip = use_public_ip ? server[:settings][:ip_address] : server[:settings][:private_ip_address]
149
136
 
150
137
  logger.info("Found server: #{hostname}(#{ip})")
151
138
  use_nickname ? hostname : ip
152
139
  end
153
-
154
- if validate_echo
155
- threads = []
156
- host_list.each do |host|
157
- threads << Thread.new {Ping.pingecho(host)}
158
- end
159
- threads.each.with_index do |t,i|
160
- host_list[i] = nil unless t.value
161
- end
162
- threads.clear
163
- host_list.delete(nil)
164
- end
140
+ host_list = _valid_echo(host_list) if validate_echo
165
141
 
166
142
  if host_list && host_list.size > 0
167
143
  role(role, params) { host_list }
@@ -221,16 +197,13 @@ start = Time.now
221
197
  if found_ids.size > 0
222
198
  host_list = srvs.select {|s| found_ids.include?(s[:href].match(/[0-9]+$/).to_s)}.map do |server|
223
199
  hostname = server[:nickname]
224
- hostname << ".#{_domain}" if _domain
200
+ hostname << ".#{_domain}" if _domain && hostname.match(/#{_domain}/).nil?
225
201
  ip = use_public_ip ? server[:settings][:ip_address] : server[:settings][:private_ip_address]
226
- if validate_echo
227
- next unless Ping.pingecho(ip)
228
- end
229
202
 
230
203
  logger.info("Found server: #{hostname}(#{ip})")
231
204
  use_nickname ? hostname : ip
232
205
  end
233
- host_list.delete(nil)
206
+ host_list = _valid_echo(host_list) if validate_echo
234
207
  end
235
208
 
236
209
  if host_list && host_list.size > 0
@@ -301,6 +274,26 @@ puts "Time: #{Time.now - start}"
301
274
  end
302
275
  end
303
276
 
277
+ def _valid_echo(host_list)
278
+ hosts = host_list
279
+ threads = []
280
+ hosts.each do |host|
281
+ threads << Thread.new {Ping.pingecho(host)}
282
+ end
283
+ threads.each_with_index do |t,i|
284
+ unless t.value
285
+ logger.info("Server dead: #{hosts[i]}")
286
+ hosts[i] = nil
287
+ else
288
+ logger.info("Server alive: #{hosts[i]}")
289
+ end
290
+ end
291
+ hosts.delete(nil)
292
+ threads.clear
293
+
294
+ hosts
295
+ end
296
+
304
297
  def validate_echo
305
298
  @validate_echo ||= false
306
299
  end
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: 27
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 6
10
- version: 0.2.6
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Satoshi Ohki