capify-ec2 1.1.8.pre → 1.1.12.pre
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/lib/capify-ec2.rb +3 -3
- data/lib/capify-ec2/capistrano.rb +15 -21
- data/lib/capify-ec2/version.rb +1 -1
- metadata +4 -4
data/lib/capify-ec2.rb
CHANGED
@@ -53,13 +53,13 @@ class CapifyEc2
|
|
53
53
|
elb.describe_instance_health(load_balancer.id, instance.id).body['DescribeInstanceHealthResult']['InstanceStates'][0]['State']
|
54
54
|
end
|
55
55
|
|
56
|
-
def self.get_instances_by_role(role, region = nil)
|
56
|
+
def self.get_instances_by_role(role, server_type, region = nil)
|
57
57
|
selected_instances = running_instances(region).select do |instance|
|
58
58
|
server_roles = [instance.case_insensitive_tag("Role")] || []
|
59
59
|
if (roles_tag = instance.case_insensitive_tag("Roles"))
|
60
60
|
server_roles += roles_tag.split(/\s*,\s*/)
|
61
61
|
end
|
62
|
-
server_roles.member?(role.to_s)
|
62
|
+
server_type.nil? ? server_roles.member?(role.to_s) : (server_roles.member?(role.to_s) && server_type == role.to_s)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -71,7 +71,7 @@ class CapifyEc2
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def self.server_names
|
74
|
-
running_instances.map {|instance| instance.
|
74
|
+
running_instances.map {|instance| instance.case_insensitive_tag("Name")}
|
75
75
|
end
|
76
76
|
|
77
77
|
def self.elb
|
@@ -4,10 +4,9 @@ require 'colored'
|
|
4
4
|
Capistrano::Configuration.instance(:must_exist).load do
|
5
5
|
def ec2_role(role_name_or_hash)
|
6
6
|
role = role_name_or_hash.is_a?(Hash) ? role_name_or_hash : {:name => role_name_or_hash,:options => {}}
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
server_type = variables[:logger].instance_variable_get("@options")[:actions].first unless variables[:logger].instance_variable_get("@options")[:actions][1].nil?
|
8
|
+
instances = CapifyEc2.get_instances_by_role(role[:name], server_type)
|
9
|
+
|
11
10
|
if role[:options].delete(:default)
|
12
11
|
instances.each do |instance|
|
13
12
|
define_role(role, instance)
|
@@ -16,17 +15,16 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
16
15
|
|
17
16
|
regions = CapifyEc2.ec2_config[:aws_params][:regions] || [CapifyEc2.ec2_config[:aws_params][:region]]
|
18
17
|
regions.each do |region|
|
19
|
-
define_regions(region, role)
|
18
|
+
define_regions(region, role, server_type)
|
20
19
|
end unless regions.nil?
|
21
20
|
|
22
|
-
define_instance_roles(role, instances)
|
21
|
+
define_instance_roles(role, instances)
|
23
22
|
define_role_roles(role, instances)
|
24
23
|
end
|
25
24
|
|
26
|
-
def define_regions(region, role)
|
27
|
-
instances = CapifyEc2.get_instances_by_role(role[:name], region)
|
25
|
+
def define_regions(region, role, server_type)
|
26
|
+
instances = CapifyEc2.get_instances_by_role(role[:name], server_type, region)
|
28
27
|
task region.to_sym do
|
29
|
-
remove_default_roles
|
30
28
|
instances.each do |instance|
|
31
29
|
define_role(role, instance)
|
32
30
|
end
|
@@ -36,8 +34,6 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
36
34
|
def define_instance_roles(role, instances)
|
37
35
|
instances.each do |instance|
|
38
36
|
task instance.name.to_sym do
|
39
|
-
specified_roles << role[:name]
|
40
|
-
remove_default_roles
|
41
37
|
define_role(role, instance)
|
42
38
|
end
|
43
39
|
end
|
@@ -45,18 +41,12 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
45
41
|
|
46
42
|
def define_role_roles(role, instances)
|
47
43
|
task role[:name].to_sym do
|
48
|
-
specified_roles << role[:name]
|
49
44
|
instances.each do |instance|
|
50
|
-
remove_default_roles
|
51
45
|
define_role(role, instance)
|
52
46
|
end
|
53
47
|
end
|
54
48
|
end
|
55
49
|
|
56
|
-
def remove_default_roles
|
57
|
-
roles.reject! { |role_name, v| !specified_roles.member?(role_name) }
|
58
|
-
end
|
59
|
-
|
60
50
|
def define_role(role, instance)
|
61
51
|
subroles = role[:options]
|
62
52
|
new_options = {}
|
@@ -73,6 +63,10 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
73
63
|
roles.each {|role| ec2_role(role)}
|
74
64
|
end
|
75
65
|
|
66
|
+
def numeric?(object)
|
67
|
+
true if Float(object) rescue false
|
68
|
+
end
|
69
|
+
|
76
70
|
desc "Deregisters instance from its ELB"
|
77
71
|
task :deregister_instance do
|
78
72
|
servers = variables[:logger].instance_variable_get("@options")[:actions].first
|
@@ -99,15 +93,15 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
99
93
|
task :ec2_status do
|
100
94
|
CapifyEc2.running_instances.each_with_index do |instance, i|
|
101
95
|
puts sprintf "%-11s: %-40s %-20s %-20s %-62s %-20s (%s)",
|
102
|
-
i.to_s.magenta, instance.
|
96
|
+
i.to_s.magenta, instance.case_insensitive_tag("Name"), instance.id.red, instance.flavor_id.cyan,
|
103
97
|
instance.dns_name.blue, instance.availability_zone.green, instance.roles.join(", ").yellow
|
104
98
|
end
|
105
99
|
end
|
106
100
|
|
107
|
-
desc "Allows ssh to instance by id. cap ssh
|
101
|
+
desc "Allows ssh to instance by id. cap ssh <INSTANCE NAME>"
|
108
102
|
task :ssh do
|
109
|
-
|
110
|
-
instance =
|
103
|
+
server = variables[:logger].instance_variable_get("@options")[:actions][1]
|
104
|
+
instance = numeric?(server) ? CapifyEc2.running_instances[server.to_i] : CapifyEc2.get_instance_by_name(server).first
|
111
105
|
port = ssh_options[:port] || 22
|
112
106
|
command = "ssh -p #{port} #{user}@#{instance.dns_name}"
|
113
107
|
puts "Running `#{command}`"
|
data/lib/capify-ec2/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capify-ec2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 961916012
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
9
|
+
- 12
|
10
10
|
- pre
|
11
|
-
version: 1.1.
|
11
|
+
version: 1.1.12.pre
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Noah Cantor
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-08-
|
20
|
+
date: 2011-08-05 00:00:00 +01:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|