capify-ec2 1.2.6.pre → 1.2.6.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +1 -1
- data/lib/capify-ec2.rb +16 -7
- data/lib/capify-ec2/capistrano.rb +15 -12
- data/lib/capify-ec2/version.rb +1 -1
- metadata +8 -8
data/Changelog.md
CHANGED
data/lib/capify-ec2.rb
CHANGED
@@ -9,8 +9,16 @@ class CapifyEc2
|
|
9
9
|
attr_accessor :load_balancer, :instances
|
10
10
|
SLEEP_COUNT = 5
|
11
11
|
|
12
|
-
def initialize()
|
13
|
-
|
12
|
+
def initialize(ec2_config = "config/ec2.yml")
|
13
|
+
case ec2_config
|
14
|
+
when Hash
|
15
|
+
@ec2_config = ec2_config
|
16
|
+
when String
|
17
|
+
@ec2_config = YAML.load_file ec2_config
|
18
|
+
else
|
19
|
+
raise ArgumentError, "Invalid ec2_config: #{ec2_config.inspect}"
|
20
|
+
end
|
21
|
+
|
14
22
|
regions = determine_regions()
|
15
23
|
|
16
24
|
@instances = []
|
@@ -29,10 +37,11 @@ class CapifyEc2
|
|
29
37
|
|
30
38
|
def display_instances
|
31
39
|
desired_instances.each_with_index do |instance, i|
|
32
|
-
puts sprintf "%-11s: %-40s %-20s %-20s %-62s %-20s (%s)",
|
40
|
+
puts sprintf "%-11s: %-40s %-20s %-20s %-62s %-20s (%s) (%s)",
|
33
41
|
i.to_s.magenta, instance.name, instance.id.red, instance.flavor_id.cyan,
|
34
|
-
instance.contact_point.blue, instance.availability_zone.green, (instance.tags["Roles"] || "").yellow
|
35
|
-
|
42
|
+
instance.contact_point.blue, instance.availability_zone.green, (instance.tags["Roles"] || "").yellow,
|
43
|
+
(instance.tags["Options"] || "").yellow
|
44
|
+
end
|
36
45
|
end
|
37
46
|
|
38
47
|
def server_names
|
@@ -48,7 +57,7 @@ class CapifyEc2
|
|
48
57
|
end
|
49
58
|
|
50
59
|
def get_instances_by_role(role)
|
51
|
-
desired_instances.select {|instance| instance.tags['Roles'].split(%r{
|
60
|
+
desired_instances.select {|instance| instance.tags['Roles'].split(%r{[, ]+}).include?(role.to_s) rescue false}
|
52
61
|
end
|
53
62
|
|
54
63
|
def get_instances_by_region(roles, region)
|
@@ -121,4 +130,4 @@ class CapifyEc2
|
|
121
130
|
STDERR.puts "#{instance.name}: tests timed out after #{time_elapsed} seconds."
|
122
131
|
end
|
123
132
|
end
|
124
|
-
end
|
133
|
+
end
|
@@ -2,24 +2,28 @@ require File.join(File.dirname(__FILE__), '../capify-ec2')
|
|
2
2
|
require 'colored'
|
3
3
|
|
4
4
|
Capistrano::Configuration.instance(:must_exist).load do
|
5
|
+
def capify_ec2
|
6
|
+
@capify_ec2 ||= CapifyEc2.new(fetch(:ec2_config, 'config/ec2.yml'))
|
7
|
+
end
|
8
|
+
|
5
9
|
namespace :ec2 do
|
6
10
|
|
7
11
|
desc "Prints out all ec2 instances. index, name, instance_id, size, DNS/IP, region, tags"
|
8
12
|
task :status do
|
9
|
-
|
13
|
+
capify_ec2.display_instances
|
10
14
|
end
|
11
15
|
|
12
16
|
desc "Deregisters instance from its ELB"
|
13
17
|
task :deregister_instance do
|
14
18
|
instance_name = variables[:logger].instance_variable_get("@options")[:actions].first
|
15
|
-
|
19
|
+
capify_ec2.deregister_instance_from_elb(instance_name)
|
16
20
|
end
|
17
21
|
|
18
22
|
desc "Registers an instance with an ELB."
|
19
23
|
task :register_instance do
|
20
24
|
instance_name = variables[:logger].instance_variable_get("@options")[:actions].first
|
21
25
|
load_balancer_name = variables[:logger].instance_variable_get("@options")[:vars][:loadbalancer]
|
22
|
-
|
26
|
+
capify_ec2.register_instance_in_elb(instance_name, load_balancer_name)
|
23
27
|
end
|
24
28
|
|
25
29
|
task :date do
|
@@ -28,13 +32,13 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
28
32
|
|
29
33
|
desc "Prints list of ec2 server names"
|
30
34
|
task :server_names do
|
31
|
-
puts
|
35
|
+
puts capify_ec2.server_names.sort
|
32
36
|
end
|
33
37
|
|
34
38
|
desc "Allows ssh to instance by id. cap ssh <INSTANCE NAME>"
|
35
39
|
task :ssh do
|
36
40
|
server = variables[:logger].instance_variable_get("@options")[:actions][1]
|
37
|
-
instance = numeric?(server) ?
|
41
|
+
instance = numeric?(server) ? capify_ec2.desired_instances[server.to_i] : capify_ec2.get_instance_by_name(server)
|
38
42
|
port = ssh_options[:port] || 22
|
39
43
|
command = "ssh -p #{port} #{user}@#{instance.contact_point}"
|
40
44
|
puts "Running `#{command}`"
|
@@ -49,9 +53,8 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
49
53
|
end
|
50
54
|
|
51
55
|
def ec2_roles(*roles)
|
52
|
-
@capify_ec2 = CapifyEc2.new
|
53
56
|
server_name = variables[:logger].instance_variable_get("@options")[:actions].first unless variables[:logger].instance_variable_get("@options")[:actions][1].nil?
|
54
|
-
named_instance =
|
57
|
+
named_instance = capify_ec2.get_instance_by_name(server_name)
|
55
58
|
|
56
59
|
task named_instance.name.to_sym do
|
57
60
|
remove_default_roles
|
@@ -68,13 +71,13 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
68
71
|
role = role_name_or_hash.is_a?(Hash) ? role_name_or_hash : {:name => role_name_or_hash,:options => {}}
|
69
72
|
@roles[role[:name]]
|
70
73
|
|
71
|
-
instances =
|
74
|
+
instances = capify_ec2.get_instances_by_role(role[:name])
|
72
75
|
if role[:options].delete(:default)
|
73
76
|
instances.each do |instance|
|
74
77
|
define_role(role, instance)
|
75
78
|
end
|
76
79
|
end
|
77
|
-
regions =
|
80
|
+
regions = capify_ec2.determine_regions
|
78
81
|
regions.each do |region|
|
79
82
|
define_regions(region, role)
|
80
83
|
end unless regions.nil?
|
@@ -87,7 +90,7 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
87
90
|
def define_regions(region, role)
|
88
91
|
instances = []
|
89
92
|
@roles.each do |role_name, junk|
|
90
|
-
region_instances =
|
93
|
+
region_instances = capify_ec2.get_instances_by_region(role_name, region)
|
91
94
|
region_instances.each {|instance| instances << instance} unless region_instances.nil?
|
92
95
|
end
|
93
96
|
task region.to_sym do
|
@@ -120,7 +123,7 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
120
123
|
options = role[:options]
|
121
124
|
new_options = {}
|
122
125
|
options.each {|key, value| new_options[key] = true if value.to_s == instance.name}
|
123
|
-
instance.tags["Options"].split(%r{
|
126
|
+
instance.tags["Options"].split(%r{[, ]+}).each { |option| new_options[option.to_sym] = true} rescue false
|
124
127
|
|
125
128
|
if new_options
|
126
129
|
role role[:name].to_sym, instance.contact_point, new_options
|
@@ -138,4 +141,4 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
138
141
|
end
|
139
142
|
|
140
143
|
|
141
|
-
end
|
144
|
+
end
|
data/lib/capify-ec2/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capify-ec2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.6.pre
|
4
|
+
version: 1.2.6.pre.2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-03-06 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: fog
|
17
|
-
requirement: &
|
17
|
+
requirement: &2156458380 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - =
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 1.1.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2156458380
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: colored
|
28
|
-
requirement: &
|
28
|
+
requirement: &2156513440 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - =
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '1.2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2156513440
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: capistrano
|
39
|
-
requirement: &
|
39
|
+
requirement: &2156513060 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2156513060
|
48
48
|
description: Grabs roles from ec2's tags and autogenerates capistrano tasks
|
49
49
|
email:
|
50
50
|
- noah.cantor@forward.co.uk
|