cap-ec2 1.0.0 → 1.1.1

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: 561fc6eba6d90d38c0505fd710820765574bd56a
4
- data.tar.gz: 89421224859dc12c7877479343f6a0261b488b04
3
+ metadata.gz: a5de758bdde1c4ff1f1b7976e3e9c831b399ff31
4
+ data.tar.gz: 17a252437d8183443a230c7ff64a0e83bdda0823
5
5
  SHA512:
6
- metadata.gz: 7f2863971ee1400fecc4d3a3784c674b177735ca14f778ef94da650e21461756b8f552d4f0ca5696e6065a9f70a52395891fe96be1728801bf2591142826089c
7
- data.tar.gz: d19528a9920f318dd148f6500bf52bc5cb6e81b8820a8647cbe5bfe805fce4596fefc0638553ff7bc2b016c410590169f0a3b12274ff331fbfaca56ec981a5cd
6
+ metadata.gz: d11cf987ba64b1eb66ca0cec01f70fe1141bbdc60ffcb836ec5774644cc30e2e72b06d24eb22fe1085253579ce0417f3bace43e59a64a14d96a2f1173405285c
7
+ data.tar.gz: 7376b1916b7a6e1a7a912c9a5788b8d305d53b3a5d0a506cab550704c637043090378c6171131e7da21c6b8c1680e1eb0cf1e40dc3d5f6025d244637e542f0f2
@@ -1,5 +1,17 @@
1
1
  # Cap-EC2 changelog
2
2
 
3
+ ## 1.1.1
4
+
5
+ Require aws-sdk v2 instead of v1
6
+
7
+ * Require aws-sdk v2 instead of v1 [@hajder](https://github.com/hajder)
8
+
9
+ ## 1.1.0
10
+
11
+ Upgrade to AWS's v2 SDK
12
+
13
+ * Upgrade to AWS's v2 SDK [@kylev](https://github.com/kylev)
14
+
3
15
  ## 1.0.0
4
16
 
5
17
  Cap-EC2 is pretty stable, and the rate of PRs has decreased, so I've
@@ -28,7 +40,7 @@ decided to bump the version to 1.0.0.
28
40
 
29
41
  ## 0.0.15
30
42
 
31
- * Add `ec2_filter_by_status_ok?` to filter out instances that aren't returning `OK`
43
+ * Add `ec2_filter_by_status_ok?` to filter out instances that aren't returning `OK`
32
44
  for their EC2 status checks. [@tomconroy](https://github.com/tomconroy)
33
45
 
34
46
  ## 0.0.14
data/README.md CHANGED
@@ -50,30 +50,36 @@ set :ec2_stages_tag, 'Stages'
50
50
 
51
51
  set :ec2_access_key_id, nil
52
52
  set :ec2_secret_access_key, nil
53
- set :ec2_region, %w{}
53
+ set :ec2_region, %w{} # REQUIRED
54
54
  set :ec2_contact_point, nil
55
55
 
56
56
  set :ec2_filter_by_status_ok?, nil
57
57
  ```
58
58
 
59
59
  #### Order of inheritance
60
+
60
61
  `cap-ec2` supports multiple methods of configuration. The order of inheritance is:
61
62
  YAML File > User Capistrano Config > Default Capistrano Config > ENV variables.
62
63
 
63
64
  #### Regions
64
- `:ec2_region` is an array of [AWS regions](http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region), if not present all regions will be checked for matching instances - this the default behavior and can be slow, if speed is an issue consider setting your required regions.
65
65
 
66
- If`:ec2_access_key_id` or `:ec2_secret_access_key` are not set in any configuration the environment variables
67
- `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_REGION` will be checked.
68
- If running on EC2 the IAM instance profile credentials will be used if credentials are not set by any other method.
66
+ `:ec2_region` is an array of
67
+ [AWS regions](http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region)
68
+ and is required. Only list regions which you wish to query for
69
+ instances; extra values simply slow down queries.
69
70
 
71
+ If `:ec2_access_key_id` or `:ec2_secret_access_key` are not set in any
72
+ configuration the environment variables `AWS_ACCESS_KEY_ID`,
73
+ `AWS_SECRET_ACCESS_KEY` and `AWS_REGION` will be checked and the
74
+ default credential load order (including instance profiles
75
+ credentials) will be honored.
70
76
 
71
77
  #### Misc settings
72
78
 
73
79
  * project_tag
74
80
 
75
- Cap-EC2 will look for a tag with this name when searching for instances that belong to this project.
76
- Cap-EC2 will look for a value which matches the :application setting in your deploy.rb.
81
+ Cap-EC2 will look for a tag with this name when searching for instances that belong to this project.
82
+ Cap-EC2 will look for a value which matches the :application setting in your deploy.rb.
77
83
  The tag name defaults to "Project" and must be set on your instances.
78
84
 
79
85
  * stages_tag
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
 
24
- spec.add_dependency "aws-sdk-v1"
24
+ spec.add_dependency "aws-sdk", "~> 2.0"
25
25
  spec.add_dependency "capistrano", ">= 3.0"
26
26
  spec.add_dependency "terminal-table"
27
27
  spec.add_dependency "colorize"
@@ -1,5 +1,5 @@
1
1
  require 'capistrano/configuration'
2
- require 'aws-sdk-v1'
2
+ require 'aws-sdk'
3
3
  require 'colorize'
4
4
  require 'terminal-table'
5
5
  require 'yaml'
@@ -1,3 +1,5 @@
1
+ require 'aws-sdk'
2
+
1
3
  module CapEC2
2
4
  class EC2Handler
3
5
  include CapEC2::Utils
@@ -12,8 +14,7 @@ module CapEC2
12
14
  end
13
15
 
14
16
  def ec2_connect(region=nil)
15
- AWS.start_memoizing
16
- AWS::EC2.new(
17
+ Aws::EC2::Client.new(
17
18
  access_key_id: fetch(:ec2_access_key_id),
18
19
  secret_access_key: fetch(:ec2_secret_access_key),
19
20
  region: region
@@ -30,7 +31,7 @@ module CapEC2
30
31
  puts defined_roles.map {|r| get_servers_for_role(r)}
31
32
  .flatten
32
33
  .uniq {|i| i.instance_id}
33
- .map {|i| i.tags["Name"]}
34
+ .map {|i| tag_value(i, 'Name')}
34
35
  .join("\n")
35
36
  end
36
37
 
@@ -59,19 +60,25 @@ module CapEC2
59
60
  end
60
61
 
61
62
  def get_servers_for_role(role)
63
+ filters = [
64
+ {name: 'tag-key', values: [stages_tag, project_tag]},
65
+ {name: tag(project_tag), values: ["*#{application}*"]},
66
+ {name: 'instance-state-name', values: %w(running)}
67
+ ]
68
+
62
69
  servers = []
63
70
  @ec2.each do |_, ec2|
64
- instances = ec2.instances
65
- .filter(tag(project_tag), "*#{application}*")
66
- .filter('instance-state-name', 'running')
67
- servers << instances.select do |i|
68
- instance_has_tag?(i, roles_tag, role) &&
69
- instance_has_tag?(i, stages_tag, stage) &&
70
- instance_has_tag?(i, project_tag, application) &&
71
- (fetch(:ec2_filter_by_status_ok?) ? instance_status_ok?(i) : true)
71
+ ec2.describe_instances(filters: filters).reservations.each do |r|
72
+ servers += r.instances.select do |i|
73
+ instance_has_tag?(i, roles_tag, role) &&
74
+ instance_has_tag?(i, stages_tag, stage) &&
75
+ instance_has_tag?(i, project_tag, application) &&
76
+ (fetch(:ec2_filter_by_status_ok?) ? instance_status_ok?(i) : true)
77
+ end
72
78
  end
73
79
  end
74
- servers.flatten.sort_by {|s| s.tags["Name"] || ''}
80
+
81
+ servers.sort_by { |s| tag_value(s, 'Name') || '' }
75
82
  end
76
83
 
77
84
  def get_server(instance_id)
@@ -83,16 +90,15 @@ module CapEC2
83
90
  private
84
91
 
85
92
  def instance_has_tag?(instance, key, value)
86
- (instance.tags[key] || '').split(',').map(&:strip).include?(value.to_s)
93
+ (tag_value(instance, key) || '').split(',').map(&:strip).include?(value.to_s)
87
94
  end
88
95
 
89
96
  def instance_status_ok?(instance)
90
97
  @ec2.any? do |_, ec2|
91
- response = ec2.client.describe_instance_status(
92
- instance_ids: [instance.id],
98
+ ec2.describe_instance_status(
99
+ instance_ids: [instance.instance_id],
93
100
  filters: [{ name: 'instance-status.status', values: %w(ok) }]
94
- )
95
- response.data.has_key?(:instance_status_set) && response.data[:instance_status_set].any?
101
+ ).instance_statuses.length == 1
96
102
  end
97
103
  end
98
104
  end
@@ -1,12 +1,12 @@
1
1
  module CapEC2
2
2
  class StatusTable
3
3
  include CapEC2::Utils
4
-
4
+
5
5
  def initialize(instances)
6
6
  @instances = instances
7
7
  output
8
8
  end
9
-
9
+
10
10
  def header_row
11
11
  [
12
12
  bold("Num"),
@@ -19,7 +19,7 @@ module CapEC2
19
19
  bold("Stages")
20
20
  ]
21
21
  end
22
-
22
+
23
23
  def output
24
24
  table = Terminal::Table.new(
25
25
  :style => {
@@ -38,13 +38,13 @@ module CapEC2
38
38
  def instance_to_row(instance, index)
39
39
  [
40
40
  sprintf("%02d:", index),
41
- green(instance.tags["Name"] || ''),
42
- red(instance.id),
41
+ green(tag_value(instance, 'Name') || ''),
42
+ red(instance.instance_id),
43
43
  cyan(instance.instance_type),
44
44
  bold(blue(CapEC2::Utils.contact_point(instance))),
45
- magenta(instance.availability_zone),
46
- yellow(instance.tags[roles_tag]),
47
- yellow(instance.tags[stages_tag])
45
+ magenta(instance.placement.availability_zone),
46
+ yellow(tag_value(instance, roles_tag)),
47
+ yellow(tag_value(instance, stages_tag))
48
48
  ]
49
49
  end
50
50
 
@@ -62,4 +62,3 @@ module CapEC2
62
62
 
63
63
  end
64
64
  end
65
-
@@ -20,6 +20,10 @@ module CapEC2
20
20
  fetch(:ec2_stages_tag)
21
21
  end
22
22
 
23
+ def tag_value(instance, key)
24
+ instance.tags.find({}) { |t| t[:key] == key.to_s }[:value]
25
+ end
26
+
23
27
  def self.contact_point_mapping
24
28
  {
25
29
  :public_dns => :public_dns_name,
@@ -57,8 +61,7 @@ module CapEC2
57
61
  unless regions_array.nil? || regions_array.empty?
58
62
  return regions_array
59
63
  else
60
- @ec2 = ec2_connect
61
- @ec2.regions.map(&:name)
64
+ fail "You must specify at least one EC2 region."
62
65
  end
63
66
  end
64
67
 
@@ -1,3 +1,3 @@
1
1
  module CapEC2
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cap-ec2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Sykes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-31 00:00:00.000000000 Z
12
+ date: 2018-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -40,19 +40,19 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: aws-sdk-v1
43
+ name: aws-sdk
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0'
48
+ version: '2.0'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: '2.0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: capistrano
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  version: '0'
140
140
  requirements: []
141
141
  rubyforge_project:
142
- rubygems_version: 2.4.6
142
+ rubygems_version: 2.4.5
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: Cap-EC2 is used to generate Capistrano namespaces and tasks from Amazon EC2