simple_deploy 0.8.1.beta1 → 0.8.2.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef642027dcd39feaf45207dd2ed7df8cf5d26616
4
- data.tar.gz: 4bd38248f760e1ef7b5feea6a3ccd479182864ed
3
+ metadata.gz: c432864cff995bd0f3e5b64c571f81833f476410
4
+ data.tar.gz: b94faf1e112f9b83d06220aef5c2b2c8f0a66c7e
5
5
  SHA512:
6
- metadata.gz: a7bb87ccf61a0650a40b6669b0abd9a920f9c30b587fd0cbb185787fb28d75d6a84de30e0c3ebcf0ecf3e003d8454e08b9267b4627f55a972f4c6bbda5600f50
7
- data.tar.gz: 2ba87b2d56034443a4ba4e39d8e986bc03660a336f37a834a770b685ef0d458477744a28f8b526142c40e776a804cd31bd20536c9c6cb0ac25e1165c7325546f
6
+ metadata.gz: ff8d95d380fa89690dc6a00234035d1227a7c59ad77fe36568e6e78194a76f4982d9657f764f2b3a982473604f49f20a2e9387c6a7fe5deea4c644966d46e641
7
+ data.tar.gz: dd8d0c74e36fb84c2d152904d172784d693afafb092b3553dea57cede1bb86b2cc08a2d28ea5c69199c6bad51d907ec10c3296f2fe4fea255ca797399565505b
data/.travis.yml CHANGED
@@ -2,4 +2,5 @@ rvm:
2
2
  - 1.9.2
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ - 2.1.0
5
6
  script: "rake spec"
data/CHANGELOG.md CHANGED
@@ -1,4 +1,7 @@
1
- ## HEAD:
1
+ ## v0.8.2 (04/02/14):
2
+
3
+ * Support instances in nested stacks (thanks @liwenbing)
4
+ * Support instances created by instance resource (thanks @liwenbing)
2
5
 
3
6
  ## v0.8.1 (03/25/14):
4
7
 
@@ -7,15 +7,22 @@ module SimpleDeploy
7
7
 
8
8
  def list_stack_instances(stack_name)
9
9
 
10
- asg_ids = auto_scaling_group_id(stack_name)
11
-
12
- return [] unless asg_ids
10
+ instances = []
11
+
12
+ #Nested stack
13
+ nested_stacks = nested_stacks_names(stack_name)
14
+ instances = nested_stacks.map {|stack| list_stack_instances stack }.flatten if nested_stacks.any?
13
15
 
16
+ #Auto Scaling Group
17
+ asg_ids = auto_scaling_group_id(stack_name)
14
18
  asg_instances = asg_ids.map { |asg_id| list_instances asg_id }.flatten
15
19
 
16
- return [] unless asg_instances.any?
20
+ #EC2 instance
21
+ stack_instances = instance_names(stack_name)
22
+
23
+ instances += (describe_instances (asg_instances + stack_instances)) if (asg_instances + stack_instances).any?
17
24
 
18
- describe_instances asg_instances
25
+ instances
19
26
  end
20
27
 
21
28
  private
@@ -54,7 +61,23 @@ module SimpleDeploy
54
61
  asgs = cf_stack_resources.select do |r|
55
62
  r['ResourceType'] == 'AWS::AutoScaling::AutoScalingGroup'
56
63
  end
57
- asgs.any? ? asgs.map {|asg| asg['PhysicalResourceId'] } : false
64
+ asgs.any? ? asgs.map {|asg| asg['PhysicalResourceId'] } : []
65
+ end
66
+
67
+ def nested_stacks_names(stack_name)
68
+ cf_stack_resources = cloud_formation.stack_resources stack_name
69
+ asgs = cf_stack_resources.select do |r|
70
+ r['ResourceType'] == 'AWS::CloudFormation::Stack'
71
+ end
72
+ asgs.any? ? asgs.map {|asg| asg['PhysicalResourceId'] } : []
73
+ end
74
+
75
+ def instance_names(stack_name)
76
+ cf_stack_resources = cloud_formation.stack_resources stack_name
77
+ asgs = cf_stack_resources.select do |r|
78
+ r['ResourceType'] == 'AWS::EC2::Instance'
79
+ end
80
+ asgs.any? ? asgs.map {|asg| asg['PhysicalResourceId'] } : []
58
81
  end
59
82
 
60
83
  end
@@ -49,7 +49,7 @@ EOS
49
49
  if instances.nil? || instances.empty?
50
50
  logger.info "Stack '#{@opts[:name]}' does not have any instances."
51
51
  else
52
- puts stack.instances
52
+ puts instances
53
53
  end
54
54
  end
55
55
 
@@ -1,3 +1,3 @@
1
1
  module SimpleDeploy
2
- VERSION = "0.8.1.beta1"
2
+ VERSION = "0.8.2.beta1"
3
3
  end
@@ -35,6 +35,7 @@ describe SimpleDeploy::AWS::InstanceReader do
35
35
  context "with no ASGs" do
36
36
  before do
37
37
  @cloud_formation_mock.should_receive(:stack_resources).
38
+ exactly(3).times.
38
39
  with('stack').
39
40
  and_return []
40
41
  end
@@ -55,6 +56,7 @@ describe SimpleDeploy::AWS::InstanceReader do
55
56
  end
56
57
 
57
58
  @cloud_formation_mock.should_receive(:stack_resources).
59
+ exactly(3).times.
58
60
  with('stack').
59
61
  and_return stack_resource_results
60
62
 
@@ -100,5 +102,104 @@ describe SimpleDeploy::AWS::InstanceReader do
100
102
  end
101
103
  end
102
104
  end
105
+
106
+ context "with nested stacks and ASGs and EC2 instances" do
107
+ before do
108
+ stack_resource_results = []
109
+ @nested_stacks = ['nested_stack1', 'nested_stack2'].each do |nested_stack|
110
+ stack_resource_results << { 'StackName' => 'stack',
111
+ 'ResourceType' => 'AWS::CloudFormation::Stack',
112
+ 'PhysicalResourceId' => nested_stack }
113
+ end
114
+ @asgs = ['asg1', 'asg2'].each do |asg|
115
+ stack_resource_results << { 'StackName' => 'stack',
116
+ 'ResourceType' => 'AWS::AutoScaling::AutoScalingGroup',
117
+ 'PhysicalResourceId' => asg }
118
+ end
119
+
120
+ @instances = ['i-instance1', 'i-instance2'].each do |instance|
121
+ stack_resource_results << { 'StackName' => 'stack',
122
+ 'ResourceType' => 'AWS::EC2::Instance',
123
+ 'PhysicalResourceId' => instance }
124
+ end
125
+
126
+ @cloud_formation_mock.should_receive(:stack_resources).
127
+ exactly(3).times.
128
+ with('stack').
129
+ and_return stack_resource_results
130
+
131
+ Fog::AWS::AutoScaling.stub(:new).
132
+ and_return @auto_scaling_groups_mock
133
+ end
134
+
135
+ context "with running instances in nested stack and ASG and EC2 instances" do
136
+ it "should return the reservation set for each running instance" do
137
+
138
+
139
+ @cloud_formation_mock.should_receive(:stack_resources).
140
+ exactly(3).times.
141
+ with('nested_stack1').
142
+ and_return []
143
+
144
+ nested_stack2_resource_results = []
145
+ @asgs = ['nested_stack2_asg1', 'nested_stack2_asg2'].each do |nested_stack2_resource_asg|
146
+ nested_stack2_resource_results << { 'StackName' => 'nested_stack2',
147
+ 'ResourceType' => 'AWS::AutoScaling::AutoScalingGroup',
148
+ 'PhysicalResourceId' => nested_stack2_resource_asg }
149
+ end
150
+
151
+ @cloud_formation_mock.should_receive(:stack_resources).
152
+ exactly(3).times.
153
+ with('nested_stack2').
154
+ and_return nested_stack2_resource_results
155
+ nested_list_response = stub 'Fog::Response', :body => { 'DescribeAutoScalingGroupsResult' =>
156
+ { 'AutoScalingGroups' => ['first',
157
+ { 'Instances' => [{ 'InstanceId' => 'i-stack001' },
158
+ { 'InstanceId' => 'i-stack002' }] }] } },
159
+ :any? => true
160
+ @auto_scaling_groups_mock.should_receive(:describe_auto_scaling_groups).
161
+ with('AutoScalingGroupNames' => ['nested_stack2_asg1']).
162
+ and_return(nested_list_response)
163
+
164
+ @auto_scaling_groups_mock.should_receive(:describe_auto_scaling_groups).
165
+ with('AutoScalingGroupNames' => ['nested_stack2_asg2']).
166
+ and_return(@empty_response)
167
+
168
+
169
+ @auto_scaling_groups_mock.should_receive(:describe_auto_scaling_groups).
170
+ with('AutoScalingGroupNames' => ['asg1']).
171
+ and_return(@list_response)
172
+ @auto_scaling_groups_mock.should_receive(:describe_auto_scaling_groups).
173
+ with('AutoScalingGroupNames' => ['asg2']).
174
+ and_return(@empty_response)
175
+
176
+ Fog::Compute::AWS.stub(:new).
177
+ and_return @ec2_mock
178
+
179
+ @ec2_mock.should_receive(:describe_instances).
180
+ with('instance-state-name' => 'running',
181
+ 'instance-id' => ['i-stack001', 'i-stack002']).
182
+ and_return @describe_response
183
+
184
+ @ec2_mock.should_receive(:describe_instances).
185
+ with('instance-state-name' => 'running',
186
+ 'instance-id' => ['i-000001', 'i-000002','i-instance1', 'i-instance2'] ).
187
+ and_return @describe_response
188
+
189
+ instance_reader = SimpleDeploy::AWS::InstanceReader.new
190
+ instance_reader.list_stack_instances('stack').should == [{
191
+ 'instanceSet' => [{'instanceState' => {'name' => 'running'}},
192
+ {'ipAddress' => '54.10.10.1'},
193
+ {'instanceId' => 'i-123456'},
194
+ {'privateIpAddress' => '192.168.1.1'}]},
195
+ {
196
+ 'instanceSet' => [{'instanceState' => {'name' => 'running'}},
197
+ {'ipAddress' => '54.10.10.1'},
198
+ {'instanceId' => 'i-123456'},
199
+ {'privateIpAddress' => '192.168.1.1'}]}]
200
+ end
201
+ end
202
+ end
203
+
103
204
  end
104
205
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1.beta1
4
+ version: 0.8.2.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Weaver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-25 00:00:00.000000000 Z
11
+ date: 2014-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fakefs