ey_cloud_awareness 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +33 -1
- data/VERSION +1 -1
- data/ey_cloud_awareness.gemspec +1 -1
- data/lib/engine_yard_cloud_instance.rb +2 -1
- data/lib/ey_cloud_awareness.rb +9 -1
- data/lib/tasks/capistrano_tasks.rb +48 -0
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -30,12 +30,44 @@ Put this in your <tt>config/deploy.rb</tt> (or wherever your deploy-related Capf
|
|
30
30
|
|
31
31
|
# add more tasks if you have more cloud environments
|
32
32
|
|
33
|
+
That should be all.
|
34
|
+
|
35
|
+
== Running capistrano tasks on your instances
|
36
|
+
|
33
37
|
Now you should be able to eycap stuff like:
|
34
38
|
|
35
39
|
cap my_app_production monit:status
|
36
40
|
|
37
41
|
...and <b>capistrano will always have a fresh list of your environment's instances</b>. Roles like <tt>:app</tt>, <tt>:db</tt>, and <tt>:utility</tt> are set properly.
|
38
42
|
|
43
|
+
== SSH into your instances
|
44
|
+
|
45
|
+
If you want to update your <tt>~/.ssh/config</tt> with hosts from a particular environment, run
|
46
|
+
|
47
|
+
cap my_app_production eyc:ssh
|
48
|
+
|
49
|
+
and it will magically add or update a block like
|
50
|
+
|
51
|
+
# START StringReplacer my_app_production -- DO NOT MODIFY
|
52
|
+
|
53
|
+
Host my_app_production0
|
54
|
+
Hostname ec2-67-202-43-40.compute-1.amazonaws.com
|
55
|
+
User my_user
|
56
|
+
StrictHostKeyChecking no
|
57
|
+
|
58
|
+
Host my_app_production1
|
59
|
+
Hostname ec2-222-222-22-22.compute-1.amazonaws.com
|
60
|
+
User my_user
|
61
|
+
StrictHostKeyChecking no
|
62
|
+
|
63
|
+
# END StringReplacer my_app_production -- DO NOT MODIFY
|
64
|
+
|
65
|
+
Now you can just ssh like this:
|
66
|
+
|
67
|
+
ssh my_app_production0
|
68
|
+
|
69
|
+
Note that you can run it for different environments (my_app_production, my_app_staging, etc.) and they won't overwrite each other.
|
70
|
+
|
39
71
|
== Just dumping information about your instances
|
40
72
|
|
41
73
|
Once you've done the quickstart, try:
|
@@ -64,7 +96,7 @@ Or whatever you want:
|
|
64
96
|
>> pp all_app_instances.first.to_hash
|
65
97
|
{:dns_name=>"ec2-67-202-43-40.compute-1.amazonaws.com",
|
66
98
|
:instance_role=>"app",
|
67
|
-
:aws_groups=>["ey-
|
99
|
+
:aws_groups=>["ey-my_app_production-1256085955-3205-13340"],
|
68
100
|
:aws_instance_id=>"i-50cf5838",
|
69
101
|
:private_dns_name=>"domU-12-31-39-01-99-D3.compute-1.internal",
|
70
102
|
:aws_state=>"running"}
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
data/ey_cloud_awareness.gemspec
CHANGED
@@ -114,7 +114,8 @@ class EngineYardCloudInstance
|
|
114
114
|
current[:aws_state] = instance_description[:aws_state]
|
115
115
|
current[:aws_groups] = instance_description[:aws_groups]
|
116
116
|
current[:aws_instance_id] = instance_description[:aws_instance_id]
|
117
|
-
current[:users] = dna[:users]
|
117
|
+
current[:users] = dna[:users]
|
118
|
+
current[:environment] = dna[:environment]
|
118
119
|
end
|
119
120
|
@_data = hash.recursive_symbolize_keys!
|
120
121
|
end
|
data/lib/ey_cloud_awareness.rb
CHANGED
@@ -8,7 +8,15 @@ class Hash
|
|
8
8
|
# http://pragmatig.wordpress.com/2009/04/14/recursive-symbolize_keys/
|
9
9
|
def recursive_symbolize_keys!
|
10
10
|
symbolize_keys!
|
11
|
-
values.select { |v| v.is_a?(Hash) }.each
|
11
|
+
values.select { |v| v.is_a?(Hash) }.each do |hsh|
|
12
|
+
hsh.recursive_symbolize_keys!
|
13
|
+
end
|
14
|
+
# burst thru at least one level of arrays
|
15
|
+
values.select { |v| v.is_a?(Array) }.each do |ary|
|
16
|
+
ary.each do |v|
|
17
|
+
v.recursive_symbolize_keys! if v.is_a?(Hash)
|
18
|
+
end
|
19
|
+
end
|
12
20
|
self
|
13
21
|
end
|
14
22
|
|
@@ -37,3 +37,51 @@ namespace :eyc do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
class StringReplacer
|
42
|
+
NEWLINE = "AijQA6tD1wkWqgvLzXD"
|
43
|
+
START_MARKER = '# START StringReplacer %s -- DO NOT MODIFY'
|
44
|
+
END_MARKER = "# END StringReplacer %s -- DO NOT MODIFY#{NEWLINE}"
|
45
|
+
|
46
|
+
attr_accessor :path
|
47
|
+
def initialize(path)
|
48
|
+
@path = path
|
49
|
+
end
|
50
|
+
|
51
|
+
def replace!(replacement, id = 1)
|
52
|
+
new_path = "#{path}.new"
|
53
|
+
backup_path = "#{path}.bak"
|
54
|
+
current_start_marker = START_MARKER % id.to_s
|
55
|
+
current_end_marker = END_MARKER % id.to_s
|
56
|
+
replacement_with_markers = current_start_marker + NEWLINE + replacement + NEWLINE + current_end_marker
|
57
|
+
text = IO.read(path).gsub("\n", NEWLINE)
|
58
|
+
if text.include? current_start_marker
|
59
|
+
text.gsub! /#{Regexp.escape current_start_marker}.*#{Regexp.escape current_end_marker}/, replacement_with_markers
|
60
|
+
else
|
61
|
+
text << NEWLINE << replacement_with_markers
|
62
|
+
end
|
63
|
+
text.gsub! NEWLINE, "\n"
|
64
|
+
File.open(new_path, 'w') { |f| f.write text }
|
65
|
+
FileUtils.mv path, backup_path
|
66
|
+
FileUtils.mv new_path, path
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
namespace :eyc do
|
71
|
+
task :ssh, :roles => :app_master do
|
72
|
+
replacement = []
|
73
|
+
environment_name = ''
|
74
|
+
eyc_proxy.app.each_with_index do |instance, index|
|
75
|
+
environment_name = instance.environment[:name]
|
76
|
+
replacement << %{
|
77
|
+
Host #{environment_name}#{index}
|
78
|
+
Hostname #{instance.dns_name}
|
79
|
+
User #{instance.users.first[:username]}
|
80
|
+
StrictHostKeyChecking no
|
81
|
+
}
|
82
|
+
end
|
83
|
+
replacement = replacement.join
|
84
|
+
r = StringReplacer.new File.expand_path("~/.ssh/config")
|
85
|
+
r.replace! replacement, environment_name
|
86
|
+
end
|
87
|
+
end
|