ec2-cli 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bfb27bf9c00d31c8e4877d8f201d9937b0427423
4
+ data.tar.gz: d64e49221a5f933b1c817a354c93bec005ac512f
5
+ SHA512:
6
+ metadata.gz: e858dde8a358a8bfe6dafd33863756244295046a41f185cff2bcfe80b7df4163e6e1791a070e508d49c0be0d17f660753c73a1136c6caa6db9a251f35554fee9
7
+ data.tar.gz: 8f02aded40d033cfb2fdf064c6a136b821e874d4c9dd819145dfea44f3c2d557885d9ecb0861a5e57a6d4de30675019b04db703c31fc19423cfbf2ca66c051e2
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ec2-cli (0.1.0)
5
+ thor
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ rake (11.3.0)
11
+ thor (0.19.1)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ ec2-cli!
18
+ rake
19
+
20
+ BUNDLED WITH
21
+ 1.12.5
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task default: [
4
+ :release,
5
+ ]
data/bin/ec2 ADDED
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+ require "http"
3
+ require "thor"
4
+ require "json"
5
+ require "tablelize"
6
+
7
+ module Ec2
8
+ class Cli < Thor
9
+ desc "version", "Show thois tool version"
10
+ def version
11
+ puts "v#{VERSION}"
12
+ end
13
+
14
+ desc "ls [FILTER]", "Lists all instances, optionally filtered by FILTER"
15
+ option :name, :type => :boolean
16
+ option :public, :type => :boolean
17
+ option :private, :type => :boolean
18
+ option :active, :type => :boolean
19
+ option :top, :type => :boolean
20
+ def ls filter = nil
21
+ rows = []
22
+ rows << ["PRIVATE IP", "PUBLIC IP", "INSTANCE ID", "LAUNCH TIME", "STATE", "NAME"]
23
+ data = _instances()
24
+ data.fetch("Reservations", {}).each do |v|
25
+ next unless v
26
+ v.fetch("Instances", {}).each do |i|
27
+ name = false
28
+ i.fetch("Tags", {}).each do |t|
29
+ name = t["Value"] if t["Key"] == "Name"
30
+ end
31
+ next unless name
32
+ state = i["State"]["Name"]
33
+ next if options["active"] and state != "running"
34
+ next if filter and not name.match filter
35
+ rows << [i["PrivateIpAddress"], i["PublicIpAddress"], i["InstanceId"], i["LaunchTime"], state, name]
36
+ end
37
+ end
38
+
39
+ if options["public"]
40
+ rows.shift
41
+ rows.each do |row|
42
+ puts row[1]
43
+ return if options["top"]
44
+ end
45
+ return
46
+ end
47
+
48
+ if options["private"]
49
+ rows.shift
50
+ rows.each do |row|
51
+ puts row[0]
52
+ return if options["top"]
53
+ end
54
+ return
55
+ end
56
+
57
+ if options["name"]
58
+ rows.shift
59
+ rows.each do |row|
60
+ puts row[4]
61
+ return if options["top"]
62
+ end
63
+ return
64
+ end
65
+
66
+ Tablelize::table rows
67
+ end
68
+
69
+ private
70
+ def _instances
71
+ json = `aws ec2 describe-instances`
72
+ data = JSON.load(json)
73
+ end
74
+ end
75
+ end
76
+
77
+ Ec2::Cli.start ARGV
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
3
+
4
+ require "ec2/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ec2-cli"
8
+ spec.version = Ec2::VERSION
9
+ spec.summary = "List your Ec2 instances"
10
+ spec.description = "List your Ec2 instances."
11
+ spec.homepage = "https://github.com/ptdorf/ec2-cli"
12
+ spec.authors = ["ptdorf"]
13
+ spec.email = ["ptdorf@gmail.com"]
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split $/
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "thor"
21
+ spec.add_development_dependency "rake"
22
+ end
@@ -0,0 +1,5 @@
1
+ module Ec2
2
+
3
+ VERSION = "0.1.1"
4
+
5
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ec2-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - ptdorf
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: List your Ec2 instances.
42
+ email:
43
+ - ptdorf@gmail.com
44
+ executables:
45
+ - ec2
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - Rakefile
52
+ - bin/ec2
53
+ - ec2-cli.gemspec
54
+ - lib/ec2/version.rb
55
+ homepage: https://github.com/ptdorf/ec2-cli
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.6.6
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: List your Ec2 instances
79
+ test_files: []