ec2-list 0.2.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 +7 -0
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/ec2-list.gemspec +34 -0
- data/exe/ec2-list +5 -0
- data/lib/ec2list/cli.rb +48 -0
- data/lib/ec2list/version.rb +3 -0
- data/lib/ec2list.rb +77 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 13eb14b2c27288a02389d66ebb0189ad8aca1132
|
4
|
+
data.tar.gz: a39d25a18ec55db12b9bcb24d891675fe6f85edb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1dbcb855f3aaf4420b2955c64bfc74c41b69ec526d9a7d470e4cf5e446d3b57a45f1cd051ec222f59e8eb887d0df1c9ff534dce4e87b8d742660ee5cb3cd3e21
|
7
|
+
data.tar.gz: 574613a0abf89a914157a3013a432365efe7bde1955f2bf1b7b5680777d94ac30db6702d3997554e4adeec19ca231e09d5015c53404b1b9986bc543d4ed9acef
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Ec2list
|
2
|
+
|
3
|
+
command line AWS EC2 instance list viewer.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ec2-list'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ec2-list
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
$ ec2-list
|
24
|
+
|
25
|
+
## Options
|
26
|
+
|
27
|
+
```
|
28
|
+
-p [PROFILE_NAME] (default)
|
29
|
+
-r [REGION] (ap-northeast-1)
|
30
|
+
-k [KEY]
|
31
|
+
-s [STATUS]
|
32
|
+
-t [TAG]
|
33
|
+
```
|
34
|
+
|
35
|
+
## Example
|
36
|
+
|
37
|
+
$ ec2-list -p myaws -r ap-northeast-1 -k fqdn -s running -t production
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nysalor/ec2-list.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ec2/list"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/ec2-list.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ec2list/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ec2-list"
|
8
|
+
spec.version = Ec2list::VERSION
|
9
|
+
spec.authors = ["Jun Yokoyama"]
|
10
|
+
spec.email = ["jun@larus.org"]
|
11
|
+
|
12
|
+
spec.summary = %q{display list of ec2 instances.}
|
13
|
+
spec.description = %q{display list of ec2 instances. inspired by ec2list gem.}
|
14
|
+
spec.homepage = "https://github.com/nysalor/ec2-list"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_dependency "thor"
|
32
|
+
spec.add_dependency "aws-sdk"
|
33
|
+
spec.add_dependency "formatador"
|
34
|
+
end
|
data/exe/ec2-list
ADDED
data/lib/ec2list/cli.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Ec2list
|
4
|
+
class CLI < Thor
|
5
|
+
default_command :display
|
6
|
+
|
7
|
+
option :p, type: :string, default: 'default'
|
8
|
+
option :r, type: :string, default: 'ap-northeast-1'
|
9
|
+
option :k, type: :string
|
10
|
+
option :s, type: :string
|
11
|
+
option :t, type: :string
|
12
|
+
option :l, type: :boolean, default: false
|
13
|
+
|
14
|
+
desc "display", "display instances list"
|
15
|
+
def display
|
16
|
+
if options[:k]
|
17
|
+
ec2_list.values(options[:k].to_sym).each do |v|
|
18
|
+
puts v if v.length > 0
|
19
|
+
end
|
20
|
+
elsif options[:l]
|
21
|
+
ec2_list.result.each do |instance|
|
22
|
+
puts display_columns.map { |column| instance[column] }.join(' ')
|
23
|
+
end
|
24
|
+
else
|
25
|
+
Formatador.display_compact_table ec2_list.result, display_columns
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def display_columns
|
32
|
+
[:id, :type, :tag, :status, :fqdn, :ip_addr, :since]
|
33
|
+
end
|
34
|
+
|
35
|
+
def ec2_list
|
36
|
+
@ec2_list ||= Ec2list::Instances.new(option_strings)
|
37
|
+
end
|
38
|
+
|
39
|
+
def option_strings
|
40
|
+
{
|
41
|
+
profile: options[:p],
|
42
|
+
region: options[:r],
|
43
|
+
status: options[:s],
|
44
|
+
tag: options[:t]
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/ec2list.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require "ec2list/version"
|
2
|
+
require "ec2list/cli"
|
3
|
+
require 'aws-sdk'
|
4
|
+
require 'formatador'
|
5
|
+
|
6
|
+
module Ec2list
|
7
|
+
class Instances
|
8
|
+
def initialize(opts)
|
9
|
+
@profile = opts[:profile]
|
10
|
+
@status = opts[:status]
|
11
|
+
@tag = opts[:tag]
|
12
|
+
Aws.config[:region] = opts[:region]
|
13
|
+
Aws.config[:credentials] = Aws::SharedCredentials.new(profile_name: @profile)
|
14
|
+
end
|
15
|
+
|
16
|
+
def ec2
|
17
|
+
@ec2 ||= Aws::EC2::Client.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def result
|
21
|
+
if @tag
|
22
|
+
instance_list.select { |instance| instance[:tag].include?(@tag) }
|
23
|
+
else
|
24
|
+
instance_list
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def instance_list
|
29
|
+
instances.map { |instance|
|
30
|
+
{
|
31
|
+
id: instance.instance_id,
|
32
|
+
type: instance.instance_type,
|
33
|
+
status: instance.state.name,
|
34
|
+
since: since_about(Time.now - instance.launch_time),
|
35
|
+
tag: instance.tags.find { |tag| tag.key == 'Name' }.value,
|
36
|
+
fqdn: instance.public_dns_name,
|
37
|
+
ip_addr: instance.public_ip_address
|
38
|
+
}
|
39
|
+
}.sort_by { |x| x[:tag] }
|
40
|
+
end
|
41
|
+
|
42
|
+
def values(key)
|
43
|
+
result.map { |x| x[key.to_sym] }.compact.sort
|
44
|
+
end
|
45
|
+
|
46
|
+
def reservations
|
47
|
+
ec2.describe_instances(filters: [filter]).reservations
|
48
|
+
end
|
49
|
+
|
50
|
+
def instances
|
51
|
+
ec2.describe_instances(filters: [filter]).reservations.map { |x| x.instances }.flatten
|
52
|
+
end
|
53
|
+
|
54
|
+
def filter
|
55
|
+
if @status
|
56
|
+
{
|
57
|
+
name: 'instance-state-name',
|
58
|
+
values: [@status]
|
59
|
+
}
|
60
|
+
else
|
61
|
+
{}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def since_about(second)
|
68
|
+
if second > 86400
|
69
|
+
"#{second.quo(86400).to_i}d"
|
70
|
+
elsif second > 3600
|
71
|
+
"#{second.quo(3600).to_i}h"
|
72
|
+
else
|
73
|
+
"#{second.quo(60).to_i}m"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ec2-list
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jun Yokoyama
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: aws-sdk
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: formatador
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: display list of ec2 instances. inspired by ec2list gem.
|
84
|
+
email:
|
85
|
+
- jun@larus.org
|
86
|
+
executables:
|
87
|
+
- ec2-list
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- ec2-list.gemspec
|
98
|
+
- exe/ec2-list
|
99
|
+
- lib/ec2list.rb
|
100
|
+
- lib/ec2list/cli.rb
|
101
|
+
- lib/ec2list/version.rb
|
102
|
+
homepage: https://github.com/nysalor/ec2-list
|
103
|
+
licenses: []
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.4.5
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: display list of ec2 instances.
|
125
|
+
test_files: []
|
126
|
+
has_rdoc:
|