ec2ssh 3.0.0 → 3.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2a2ee78001eaabbf39624cff2c27a296e239e77
4
- data.tar.gz: e2b72fd81e19145a21d61a67bd10c6feb209c530
3
+ metadata.gz: 2a75305a65aa96b48c53656fbb89c875afc885ba
4
+ data.tar.gz: 5885b8f6f11a457a0ccdc3fa52179e6698fc182b
5
5
  SHA512:
6
- metadata.gz: 96d674315445326d0036e5e3cc535382d9aaa045fc1665df00261c24965a031d675a2cc2d91f655ae151325a4aac8b5deb749f29ff4fe358fb86eff17c027e78
7
- data.tar.gz: 427149ba39d20f9b132e241687c4b76e65fb8819ab91f0c075d22fc7be34c920679d9b5113f83fba51ec073e6c7ad3e201f307db36ecfd9f46cbb20b8031de9c
6
+ metadata.gz: c7c74269f0d19158ad49c49fcfd549a1649f1c416de30e5345d51cbe5fe4da928d761a11103b009d9e93c6f999bffedd7ba365e629b9e03ac21e78c58ea9243d
7
+ data.tar.gz: 7af6da18131dfbfe3654872587b0d57847a6cfc0959dc986dd76e379060e9afa79abc925c056196da7f1b1e39240ee05d83b3493aa2ef1a9e231baf175888b87
data/ChangeLog.md CHANGED
@@ -1,4 +1,8 @@
1
1
  # Change Log
2
+ ## 3.0.1
3
+ * Ignore unnamed instances as default (#22, #24, #25)
4
+ Thanks to @r7kamura and @kainoku
5
+
2
6
  ## 3.0.0
3
7
  * Dotfile (.ec2ssh) format has been changed from YAML to Ruby DSL.
4
8
  * Refactored
data/README.md CHANGED
@@ -35,6 +35,9 @@ aws_keys(
35
35
  )
36
36
  regions 'us-east-1'
37
37
 
38
+ # Ignore unnamed instances
39
+ reject {|instance| !instance.tags['Name'] }
40
+
38
41
  # You can use methods of AWS::EC2::Instance.
39
42
  # See http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Instance.html
40
43
  host_line <<END
@@ -31,7 +31,7 @@ module Ec2ssh
31
31
  ec2s[key_name][region].instances.
32
32
  filter('instance-state-name', 'running').
33
33
  to_a.
34
- sort_by {|ins| ins.tags['Name'] }
34
+ sort_by {|ins| ins.tags['Name'].to_s }
35
35
  }.flatten
36
36
  end
37
37
  end
@@ -47,6 +47,9 @@ module Ec2ssh
47
47
 
48
48
  out.puts <<-END
49
49
 
50
+ # Ignore unnamed instances
51
+ reject {|instance| !instance.tags['Name'] }
52
+
50
53
  # You can use methods of AWS::EC2::Instance.
51
54
  # See http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Instance.html
52
55
  host_line <<EOS
@@ -1,3 +1,3 @@
1
1
  module Ec2ssh
2
- VERSION = '3.0.0'
2
+ VERSION = '3.0.1'
3
3
  end
@@ -48,6 +48,9 @@ aws_keys(
48
48
  key1: { access_key_id: 'ACCESS_KEY1', secret_access_key: 'SECRET1' }
49
49
  )
50
50
 
51
+ # Ignore unnamed instances
52
+ reject {|instance| !instance.tags['Name'] }
53
+
51
54
  # You can use methods of AWS::EC2::Instance.
52
55
  # See http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Instance.html
53
56
  host_line <<EOS
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+ require 'ec2ssh/ec2_instances'
3
+
4
+ describe Ec2ssh::Ec2Instances do
5
+ describe '#instances' do
6
+ let(:key_name) {
7
+ "dummy_key_name"
8
+ }
9
+
10
+ let(:region) {
11
+ "ap-northeast-1"
12
+ }
13
+
14
+ let(:mock) do
15
+ described_class.new(aws_keys='', regions=[region]).tap do |e|
16
+ allow(e).to receive(:ec2s) { ec2s }
17
+ allow(e).to receive(:regions) { [region] }
18
+ end
19
+ end
20
+
21
+ let(:ec2s) {
22
+ {
23
+ "#{key_name}" => {
24
+ "#{region}" => instances.tap do |m|
25
+ allow(m).to receive(:instances) { m }
26
+ end
27
+ }
28
+ }
29
+ }
30
+
31
+ let(:instances) {
32
+ mock_instances.tap do |m|
33
+ allow(m).to receive(:filter) { m }
34
+ end
35
+ }
36
+
37
+ context 'with non-empty names' do
38
+ let(:mock_instances) {
39
+ [
40
+ double('instance', n: 1, tags: {'Name' => 'srvB' }),
41
+ double('instance', n: 2, tags: {'Name' => 'srvA' }),
42
+ double('instance', n: 3, tags: {'Name' => 'srvC' })
43
+ ]
44
+ }
45
+
46
+ it do
47
+ result = mock.instances(key_name)
48
+ expect(result.map {|ins| ins.n}).to match_array([2, 1, 3])
49
+ end
50
+ end
51
+
52
+ context 'with names including empty one' do
53
+ let(:mock_instances) {
54
+ [
55
+ double('instance', n: 1, tags: {'Name' => 'srvA'}),
56
+ double('instance', n: 2, tags: {}),
57
+ double('instance', n: 3, tags: {'Name' => 'srvC' })
58
+ ]
59
+ }
60
+
61
+ it do
62
+ result = mock.instances(key_name)
63
+ expect(result.map {|ins| ins.n}).to match_array([2, 1, 3])
64
+ end
65
+ end
66
+
67
+ end
68
+ end
@@ -32,6 +32,9 @@ aws_keys(
32
32
  )
33
33
  regions 'ap-northeast-1', 'us-east-1'
34
34
 
35
+ # Ignore unnamed instances
36
+ reject {|instance| !instance.tags['Name'] }
37
+
35
38
  # You can use methods of AWS::EC2::Instance.
36
39
  # See http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Instance.html
37
40
  host_line <<EOS
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Issei Naruta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-20 00:00:00.000000000 Z
11
+ date: 2015-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -92,6 +92,7 @@ files:
92
92
  - spec/lib/ec2ssh/command/remove_spec.rb
93
93
  - spec/lib/ec2ssh/command/update_spec.rb
94
94
  - spec/lib/ec2ssh/dsl_spec.rb
95
+ - spec/lib/ec2ssh/ec2_instances_spec.rb
95
96
  - spec/lib/ec2ssh/migrator_spec.rb
96
97
  - spec/lib/ec2ssh/ssh_config_spec.rb
97
98
  - spec/spec_helper.rb
@@ -125,6 +126,7 @@ test_files:
125
126
  - spec/lib/ec2ssh/command/remove_spec.rb
126
127
  - spec/lib/ec2ssh/command/update_spec.rb
127
128
  - spec/lib/ec2ssh/dsl_spec.rb
129
+ - spec/lib/ec2ssh/ec2_instances_spec.rb
128
130
  - spec/lib/ec2ssh/migrator_spec.rb
129
131
  - spec/lib/ec2ssh/ssh_config_spec.rb
130
132
  - spec/spec_helper.rb