capify-cloud 1.5.0.pre.1 → 1.5.0.pre.3
Sign up to get free protection for your applications and to get access to all the features.
- data/capify-cloud.gemspec +1 -1
- data/lib/capify-cloud.rb +15 -81
- data/lib/capify-cloud/capistrano.rb +1 -20
- data/lib/capify-cloud/version.rb +1 -1
- data/readme.md +8 -31
- metadata +5 -5
data/capify-cloud.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Noah Cantor"]
|
10
10
|
s.email = ["ncantor@gmail.com"]
|
11
|
-
s.homepage = "http://github.com/
|
11
|
+
s.homepage = "http://github.com/forward/capify-cloud"
|
12
12
|
s.summary = %q{Grabs roles from clouds' meta-data and autogenerates capistrano tasks}
|
13
13
|
s.description = %q{Grabs roles from clouds' meta-data and autogenerates capistrano tasks}
|
14
14
|
|
data/lib/capify-cloud.rb
CHANGED
@@ -6,8 +6,7 @@ require File.expand_path(File.dirname(__FILE__) + '/capify-cloud/server')
|
|
6
6
|
|
7
7
|
class CapifyCloud
|
8
8
|
|
9
|
-
attr_accessor :
|
10
|
-
SLEEP_COUNT = 5
|
9
|
+
attr_accessor :instances
|
11
10
|
|
12
11
|
def initialize(cloud_config = "config/cloud.yml")
|
13
12
|
case cloud_config
|
@@ -18,34 +17,31 @@ class CapifyCloud
|
|
18
17
|
else
|
19
18
|
raise ArgumentError, "Invalid cloud_config: #{cloud_config.inspect}"
|
20
19
|
end
|
21
|
-
|
20
|
+
|
22
21
|
@cloud_providers = @cloud_config[:cloud_providers]
|
23
|
-
|
24
22
|
@instances = []
|
25
23
|
@cloud_providers.each do |cloud_provider|
|
26
24
|
config = @cloud_config[cloud_provider.to_sym]
|
27
|
-
|
28
|
-
when 'Brightbox'
|
29
|
-
servers = Fog::Compute.new(:provider => cloud_provider, :brightbox_client_id => config[:brightbox_client_id],
|
30
|
-
:brightbox_secret => config[:brightbox_secret]).servers
|
31
|
-
servers.each do |server|
|
32
|
-
@instances << server if server.ready?
|
33
|
-
end
|
34
|
-
else
|
25
|
+
config[:provider] = cloud_provider
|
35
26
|
regions = determine_regions(cloud_provider)
|
36
|
-
regions
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
27
|
+
config.delete(:regions)
|
28
|
+
if regions
|
29
|
+
regions.each do |region|
|
30
|
+
config.delete(:region)
|
31
|
+
config[:region] = region
|
32
|
+
populate_instances(config)
|
41
33
|
end
|
42
|
-
|
34
|
+
else populate_instances(config)
|
43
35
|
end
|
44
36
|
end
|
45
37
|
end
|
46
38
|
|
39
|
+
def populate_instances(config)
|
40
|
+
Fog::Compute.new(config).servers.each {|server| @instances << server if server.ready? }
|
41
|
+
end
|
42
|
+
|
47
43
|
def determine_regions(cloud_provider = 'AWS')
|
48
|
-
|
44
|
+
regions = @cloud_config[cloud_provider.to_sym][:regions]
|
49
45
|
end
|
50
46
|
|
51
47
|
def display_instances
|
@@ -81,66 +77,4 @@ class CapifyCloud
|
|
81
77
|
def get_instance_by_name(name)
|
82
78
|
desired_instances.select {|instance| instance.name == name}.first
|
83
79
|
end
|
84
|
-
|
85
|
-
def instance_health(load_balancer, instance)
|
86
|
-
elb.describe_instance_health(load_balancer.id, instance.id).body['DescribeInstanceHealthResult']['InstanceStates'][0]['State']
|
87
|
-
end
|
88
|
-
|
89
|
-
def elb
|
90
|
-
Fog::AWS::ELB.new(:aws_access_key_id => @cloud_config[:aws_access_key_id], :aws_secret_access_key => @cloud_config[:aws_secret_access_key], :region => @cloud_config[:aws_params][:region])
|
91
|
-
end
|
92
|
-
|
93
|
-
def get_load_balancer_by_instance(instance_id)
|
94
|
-
hash = elb.load_balancers.inject({}) do |collect, load_balancer|
|
95
|
-
load_balancer.instances.each {|load_balancer_instance_id| collect[load_balancer_instance_id] = load_balancer}
|
96
|
-
collect
|
97
|
-
end
|
98
|
-
hash[instance_id]
|
99
|
-
end
|
100
|
-
|
101
|
-
def get_load_balancer_by_name(load_balancer_name)
|
102
|
-
lbs = {}
|
103
|
-
elb.load_balancers.each do |load_balancer|
|
104
|
-
lbs[load_balancer.id] = load_balancer
|
105
|
-
end
|
106
|
-
lbs[load_balancer_name]
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
def deregister_instance_from_elb(instance_name)
|
111
|
-
return unless @cloud_config[:load_balanced]
|
112
|
-
instance = get_instance_by_name(instance_name)
|
113
|
-
return if instance.nil?
|
114
|
-
@@load_balancer = get_load_balancer_by_instance(instance.id)
|
115
|
-
return if @@load_balancer.nil?
|
116
|
-
|
117
|
-
elb.deregister_instances_from_load_balancer(instance.id, @@load_balancer.id)
|
118
|
-
end
|
119
|
-
|
120
|
-
def register_instance_in_elb(instance_name, load_balancer_name = '')
|
121
|
-
return if !@cloud_config[:load_balanced]
|
122
|
-
instance = get_instance_by_name(instance_name)
|
123
|
-
return if instance.nil?
|
124
|
-
load_balancer = get_load_balancer_by_name(load_balancer_name) || @@load_balancer
|
125
|
-
return if load_balancer.nil?
|
126
|
-
|
127
|
-
elb.register_instances_with_load_balancer(instance.id, load_balancer.id)
|
128
|
-
|
129
|
-
fail_after = @cloud_config[:fail_after] || 30
|
130
|
-
state = instance_health(load_balancer, instance)
|
131
|
-
time_elapsed = 0
|
132
|
-
|
133
|
-
while time_elapsed < fail_after
|
134
|
-
break if state == "InService"
|
135
|
-
sleep SLEEP_COUNT
|
136
|
-
time_elapsed += SLEEP_COUNT
|
137
|
-
STDERR.puts 'Verifying Instance Health'
|
138
|
-
state = instance_health(load_balancer, instance)
|
139
|
-
end
|
140
|
-
if state == 'InService'
|
141
|
-
STDERR.puts "#{instance.name}: Healthy"
|
142
|
-
else
|
143
|
-
STDERR.puts "#{instance.name}: tests timed out after #{time_elapsed} seconds."
|
144
|
-
end
|
145
|
-
end
|
146
80
|
end
|
@@ -13,19 +13,6 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
13
13
|
capify_cloud.display_instances
|
14
14
|
end
|
15
15
|
|
16
|
-
desc "Deregisters instance from its ELB"
|
17
|
-
task :deregister_instance do
|
18
|
-
instance_name = variables[:logger].instance_variable_get("@options")[:actions].first
|
19
|
-
capify_cloud.deregister_instance_from_elb(instance_name)
|
20
|
-
end
|
21
|
-
|
22
|
-
desc "Registers an instance with an ELB."
|
23
|
-
task :register_instance do
|
24
|
-
instance_name = variables[:logger].instance_variable_get("@options")[:actions].first
|
25
|
-
load_balancer_name = variables[:logger].instance_variable_get("@options")[:vars][:loadbalancer]
|
26
|
-
capify_cloud.register_instance_in_elb(instance_name, load_balancer_name)
|
27
|
-
end
|
28
|
-
|
29
16
|
task :date do
|
30
17
|
run "date"
|
31
18
|
end
|
@@ -45,13 +32,7 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
45
32
|
exec(command)
|
46
33
|
end
|
47
34
|
end
|
48
|
-
|
49
|
-
namespace :deploy do
|
50
|
-
before "deploy", "cloud:deregister_instance"
|
51
|
-
after "deploy", "cloud:register_instance"
|
52
|
-
after "deploy:rollback", "cloud:register_instance"
|
53
|
-
end
|
54
|
-
|
35
|
+
|
55
36
|
def cloud_roles(*roles)
|
56
37
|
server_name = variables[:logger].instance_variable_get("@options")[:actions].first unless variables[:logger].instance_variable_get("@options")[:actions][1].nil?
|
57
38
|
|
data/lib/capify-cloud/version.rb
CHANGED
data/readme.md
CHANGED
@@ -72,23 +72,6 @@ will run the date command on all server's tagged with the web role
|
|
72
72
|
|
73
73
|
Running
|
74
74
|
|
75
|
-
```ruby
|
76
|
-
cap server-1 cloud:register_instance -s loadbalancer=elb-1
|
77
|
-
```
|
78
|
-
|
79
|
-
will register server-1 to be used by elb-1
|
80
|
-
|
81
|
-
Running
|
82
|
-
|
83
|
-
```ruby
|
84
|
-
cap server-1 cloud:deregister_instance
|
85
|
-
```
|
86
|
-
|
87
|
-
will remove server-1 from whatever instance it is currently
|
88
|
-
registered against.
|
89
|
-
|
90
|
-
Running
|
91
|
-
|
92
75
|
```ruby
|
93
76
|
cap cloud:status
|
94
77
|
```
|
@@ -161,36 +144,30 @@ The yml file needs to look something like this:
|
|
161
144
|
|
162
145
|
```ruby
|
163
146
|
:cloud_providers: ['AWS', 'Brightbox']
|
164
|
-
|
147
|
+
:project_tag: "YOUR APP NAME"
|
148
|
+
|
165
149
|
:AWS:
|
166
150
|
:aws_access_key_id: "YOUR ACCESS KEY"
|
167
151
|
:aws_secret_access_key: "YOUR SECRET"
|
168
|
-
:
|
169
|
-
:region: 'eu-west-1'
|
170
|
-
:load_balanced: true
|
171
|
-
:project_tag: "YOUR APP NAME"
|
152
|
+
:regions: 'eu-west-1'
|
172
153
|
|
173
154
|
:Brightbox:
|
174
155
|
:brightbox_client_id: "YOUR CLIENT ID"
|
175
156
|
:brightbox_secret: "YOUR SECRET"
|
176
157
|
```
|
177
|
-
aws_access_key_id, aws_secret_access_key, and region are required for AWS.
|
158
|
+
aws_access_key_id, aws_secret_access_key, and region are required for AWS.
|
178
159
|
brightbox_client_id and brightbox_secret: are required for Brightbox.
|
160
|
+
Other settings are optional.
|
179
161
|
If you do not specify a cloud_provider, AWS is assumed.
|
180
162
|
|
181
|
-
If :load_balanced is set to true, the gem uses pre and post-deploy
|
182
|
-
hooks to deregister the instance, reregister it, and validate its
|
183
|
-
health.
|
184
|
-
:load_balanced only works for individual instances, not for roles.
|
185
|
-
|
186
163
|
The :project_tag parameter is optional. It will limit any commands to
|
187
164
|
running against those instances with a "Project" tag set to the value
|
188
165
|
"YOUR APP NAME".
|
189
166
|
|
190
167
|
## Development
|
191
168
|
|
192
|
-
Source hosted at [GitHub](http://github.com/
|
193
|
-
Report Issues/Feature requests on [GitHub Issues](http://github.com/
|
169
|
+
Source hosted at [GitHub](http://github.com/forward/capify-cloud).
|
170
|
+
Report Issues/Feature requests on [GitHub Issues](http://github.com/forward/capify-cloud/issues).
|
194
171
|
|
195
172
|
### Note on Patches/Pull Requests
|
196
173
|
|
@@ -204,4 +181,4 @@ Report Issues/Feature requests on [GitHub Issues](http://github.com/ncantor/capi
|
|
204
181
|
|
205
182
|
## Copyright
|
206
183
|
|
207
|
-
Original version: Copyright (c) 2012 Forward. See [LICENSE](https://github.com/
|
184
|
+
Original version: Copyright (c) 2012 Forward. See [LICENSE](https://github.com/forward/capify-cloud/blob/master/LICENSE) for details.
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capify-cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: -1081488662
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 5
|
9
9
|
- 0
|
10
10
|
- pre
|
11
|
-
-
|
12
|
-
version: 1.5.0.pre.
|
11
|
+
- 3
|
12
|
+
version: 1.5.0.pre.3
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Noah Cantor
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2012-07-
|
20
|
+
date: 2012-07-13 00:00:00 Z
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: fog
|
@@ -85,7 +85,7 @@ files:
|
|
85
85
|
- lib/capify-cloud/server.rb
|
86
86
|
- lib/capify-cloud/version.rb
|
87
87
|
- readme.md
|
88
|
-
homepage: http://github.com/
|
88
|
+
homepage: http://github.com/forward/capify-cloud
|
89
89
|
licenses: []
|
90
90
|
|
91
91
|
post_install_message:
|