cap-rightscale 0.1.0 → 0.2.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 +1 -1
- data/cap-rightscale.gemspec +1 -1
- data/lib/cap-rightscale/configuration/rightscale.rb +30 -11
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/cap-rightscale.gemspec
CHANGED
@@ -44,7 +44,7 @@ module Capistrano
|
|
44
44
|
logger.info("SETTING ROLE: #{role}")
|
45
45
|
|
46
46
|
# Set rightscale's parameters
|
47
|
-
|
47
|
+
_array_id = params[:array_id]
|
48
48
|
|
49
49
|
params.delete(:array_id) # remove rightscale's parameters
|
50
50
|
|
@@ -56,10 +56,10 @@ module Capistrano
|
|
56
56
|
else
|
57
57
|
# Request RightScale API
|
58
58
|
start = Time.now
|
59
|
-
|
60
|
-
array = ServerArray.show(_array)
|
59
|
+
array = get_array(_array_id)
|
61
60
|
logger.info("querying rightscale for server_array #{array.nickname}...")
|
62
|
-
|
61
|
+
dept = get_deployment(array.deployment_href.match(/[0-9]+$/).to_s, :server_settings => 'true')
|
62
|
+
deployment_name = dept.nickname
|
63
63
|
logger.info("Deployment #{deployment_name}:")
|
64
64
|
|
65
65
|
host_list = ServerArray.instances(array.id).select {|i| i[:state] == "operational"}.map do |instance|
|
@@ -100,7 +100,7 @@ puts "Time: #{Time.now - start}"
|
|
100
100
|
logger.info("SETTING ROLE: #{role}")
|
101
101
|
|
102
102
|
# Set rightscale's parameters
|
103
|
-
|
103
|
+
_dept_id = params[:deployment]
|
104
104
|
_name_prefix = params[:name_prefix]
|
105
105
|
|
106
106
|
params.delete(:deployment)
|
@@ -114,8 +114,7 @@ puts "Time: #{Time.now - start}"
|
|
114
114
|
else
|
115
115
|
# Request RightScale API
|
116
116
|
start = Time.now
|
117
|
-
|
118
|
-
dept = Deployment.show(_dept, :server_settings => 'true')
|
117
|
+
dept = get_deployment(_dept_id, :server_settings => 'true')
|
119
118
|
logger.info("querying rightscale for servers #{_name_prefix} in deployment #{dept.nickname}...")
|
120
119
|
srvs = dept.servers.select {|s| s[:state] == "operational"}
|
121
120
|
srvs = srvs.select {|s| /#{_name_prefix}/ =~ s[:nickname]} if _name_prefix
|
@@ -159,7 +158,7 @@ puts "Time: #{Time.now - start}"
|
|
159
158
|
logger.info("SETTING ROLE: #{role}")
|
160
159
|
|
161
160
|
# Set rightscale's parameters
|
162
|
-
|
161
|
+
_dept_id = params[:deployment]
|
163
162
|
_tags = params[:tags]
|
164
163
|
|
165
164
|
params.delete(:deployment)
|
@@ -173,15 +172,14 @@ puts "Time: #{Time.now - start}"
|
|
173
172
|
else
|
174
173
|
# Request RightScale API
|
175
174
|
start = Time.now
|
176
|
-
|
177
|
-
dept = Deployment.show(_dept, :server_settings => 'true')
|
175
|
+
dept = get_deployment(_dept_id, :server_settings => 'true')
|
178
176
|
logger.info("querying rightscale for servers matching tags #{_tags} in deployment #{dept.nickname}...")
|
179
177
|
srvs = dept.servers.select {|s| s[:state] == "operational"}
|
180
178
|
|
181
179
|
ts_params = {:resource_type => "ec2_instance", :tags => [_tags]}
|
182
180
|
ts = Tag.search(ts_params).
|
183
181
|
select {|s| s.state == "operational"}.
|
184
|
-
select {|s| s.deployment_href.match(/[0-9]+$/).to_s ==
|
182
|
+
select {|s| s.deployment_href.match(/[0-9]+$/).to_s == _dept_id.to_s}
|
185
183
|
|
186
184
|
# diff servers in deployment and servers matching tags in deployment
|
187
185
|
srvs_ids = srvs.map {|s| s[:href].match(/[0-9]+$/).to_s}
|
@@ -213,6 +211,27 @@ puts "Time: #{Time.now - start}"
|
|
213
211
|
end
|
214
212
|
|
215
213
|
private
|
214
|
+
def get_array(id)
|
215
|
+
array = self.instance_variable_get("@array_#{id}")
|
216
|
+
|
217
|
+
unless array
|
218
|
+
connect
|
219
|
+
array = self.instance_variable_set("@array_#{id}", ServerArray.show(id))
|
220
|
+
end
|
221
|
+
array
|
222
|
+
end
|
223
|
+
|
224
|
+
def get_deployment(id, params)
|
225
|
+
dept = self.instance_variable_get("@deployment_#{id}")
|
226
|
+
|
227
|
+
unless dept
|
228
|
+
connect
|
229
|
+
self.instance_variable_set("@deployment_#{id}", Deployment.show(id, params))
|
230
|
+
dept = self.instance_variable_get("@deployment_#{id}")
|
231
|
+
end
|
232
|
+
dept
|
233
|
+
end
|
234
|
+
|
216
235
|
def connect
|
217
236
|
@auth ||= open(get_rs_confpath) {|f| YAML.load(f)}
|
218
237
|
@conn ||= RightResource::Connection.new do |c|
|
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:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Satoshi Ohki
|