aws_interactive_cli 0.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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDc0OTVjODcxYzhlYzliNzg4YmNhMTQ0OTA3YWM0YTZkZmMxYWQ2OQ==
5
+ data.tar.gz: !binary |-
6
+ YzEwZDc2NGJiMDU4ODc4YTMxNGNmMTRkNjVkMjYxYjZmMmFkNTFiNg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MDA5NDQxMTk1NjJlMDUzYzM0ZjFhYzdiNDA5MjcwOTQ3NThlNjE4YTQ1M2I3
10
+ ZDY4ZmE1NTA5M2E5MTA5YWNjOWMxM2I3ZGY2YjNmYTg2NTFiZjBjODY1MjAw
11
+ YmI0ZTE5MmIyNTBhMDYwNmMxMDQ2ZjcyNGQ3ODU2OGRlMWUzZGM=
12
+ data.tar.gz: !binary |-
13
+ Y2MyNWNjNmU4MGMwMjQyODIzMDNjODYzYzExMjQ4YTRkMDMzN2RlODk4MGVm
14
+ NmVjMjEzMzM4NWNiNTFmNDRkNDhmOWE1ODY3YzE3YzdlMjkwNGFlMmRjZGU2
15
+ MmNmOTllOTQwMWM4MzBlMTAxMzNjMzkzMGFjM2U3MmY1NGVlZWI=
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aws_interactive_cli.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jack Ellis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Cthulhu
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cthulhu'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cthulhu
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aws_interactive_cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "aws_interactive_cli"
8
+ spec.version = AWSInteractiveCLI::VERSION
9
+ spec.authors = ["Jack Ellis"]
10
+ spec.email = ["andellis@amazon.com"]
11
+ spec.description = ["Interactive AWS CLI"]
12
+ spec.summary = ["Easy way to start, stop, and ssh into instances"]
13
+ spec.homepage = ""
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.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_runtime_dependency "highline"
24
+ spec.add_runtime_dependency "aws-sdk"
25
+ spec.add_runtime_dependency "terminal-table"
26
+
27
+ end
28
+
@@ -0,0 +1,10 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'configuration'
4
+ require 'base_methods'
5
+
6
+ configuration = StartingConfiguration.config
7
+
8
+ BaseMethods.start_over("none")
9
+
10
+ exit
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,3 @@
1
+ module AWSInteractiveCLI
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,16 @@
1
+ # require 'rubygems'
2
+ # require 'highline/import'
3
+ # # require 'aws-sdk'
4
+ # # require 'terminal-table'
5
+ # require '../lib/configuration'
6
+ require '../lib/base_methods'
7
+ # require '../lib/questions'
8
+
9
+ # Sets the Access Key, Secret key, and Keypair path
10
+ configuration = StartingConfiguration.config
11
+
12
+ BaseMethods.start_over("none")
13
+
14
+ #TODO Add Elastic Beanstalk Management
15
+ #TODO Terminate all "Daily" instances
16
+ #TODO Remove SSH if keypair is not given
@@ -0,0 +1,78 @@
1
+ require 'aws-sdk'
2
+ require 'questions'
3
+
4
+ class BaseMethods
5
+
6
+ # Returns array of regions
7
+ def self.describe_regions
8
+ regions = AWS::Core::RegionCollection.new
9
+ @array = []
10
+ regions.each do | region |
11
+ @array << region.name
12
+ end
13
+ end
14
+
15
+ # Returns array of instances in specific region
16
+ def self.describe_instance_by_region(region)
17
+ # TODO Refactor
18
+ @instances = []
19
+ client = AWS::EC2::Client.new(:region => region)
20
+ instances = client.describe_instances
21
+ instances[:reservation_set].each do | instance |
22
+ @tags = []
23
+ instance[:instances_set].first[:tag_set].each do |tag|
24
+ @tags << {tag[:key] => tag[:value]}
25
+ if tag[:key] == "Name"
26
+ @name = tag[:value]
27
+ end
28
+ end
29
+
30
+ hash = {
31
+ :instance_id => instance[:instances_set].first[:instance_id],
32
+ :ip_address => instance[:instances_set].first[:ip_address],
33
+ :instance_state => instance[:instances_set].first[:instance_state][:name],
34
+ :launch_time => instance[:instances_set].first[:launch_time],
35
+ :name => @name,
36
+ :keypair => instance[:instances_set].first[:key_name]
37
+ }
38
+ @tags.each do |tag|
39
+ hash.merge!(tag)
40
+ end
41
+
42
+ @instances << hash
43
+ end
44
+ return @instances
45
+ end
46
+
47
+ def self.instance_action(instance_id, action, region)
48
+ ec2 = AWS::EC2.new(:region => region)
49
+ i = ec2.instances[instance_id]
50
+ if action == "start"
51
+ i.start
52
+ elsif action == "stop"
53
+ i.stop
54
+ elsif action == "terminate"
55
+ i.terminate
56
+ else
57
+ end
58
+ end
59
+
60
+ def self.start_over(region)
61
+
62
+ question = Questions.new
63
+
64
+ # Start Process
65
+ if region == "none"
66
+ # Select a region
67
+ @region = question.region
68
+ else
69
+ @region = region
70
+ end
71
+
72
+ # Select an Instance
73
+ @selected_instance = question.select_instance(@region)
74
+
75
+ # Select the action
76
+ @instance = question.instance_action(@selected_instance)
77
+ end
78
+ end
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'highline/import'
3
+ require 'aws-sdk'
4
+ require 'base_methods'
5
+
6
+ class StartingConfiguration
7
+
8
+ def self.config
9
+
10
+ # Setting the Config file Location
11
+ config_file = "#{Dir.home}/.aws-config.yml"
12
+
13
+
14
+ unless File.file?(config_file)
15
+ begin
16
+ entry = Hash.new
17
+
18
+ say("Configuration Details:")
19
+
20
+ entry[:access_key] = ask("Access Key: ")
21
+ entry[:secret_key] = ask("Secret Key: ")
22
+ entry[:path_to_keypairs] = ask("Path to keypairs(/path/to/keypairs/): ")
23
+
24
+ end
25
+
26
+ File.open("#{config_file}", "w") { |file| YAML.dump(entry, file) }
27
+
28
+ end
29
+
30
+ AWS.config(YAML.load(File.read(config_file)))
31
+ hash = YAML.load(File.read(config_file))
32
+
33
+ end
34
+
35
+ def self.path_to_keypair
36
+
37
+ hash = YAML.load(File.read("#{Dir.home}/.aws-config.yml"))
38
+ @path_to_keypairs = hash[:path_to_keypairs]
39
+
40
+ end
41
+ end
42
+
43
+
44
+
data/lib/questions.rb ADDED
@@ -0,0 +1,154 @@
1
+ require 'rubygems'
2
+ require 'highline/import'
3
+ require 'aws-sdk'
4
+ require 'terminal-table'
5
+ require 'configuration'
6
+ require 'base_methods'
7
+
8
+
9
+ class Questions
10
+ def region
11
+
12
+ #Select a region
13
+ choose do |menu|
14
+
15
+ menu.header= "Select a region"
16
+
17
+ BaseMethods.describe_regions.each do | region |
18
+ menu.choice(region){
19
+ @@region = region
20
+ return region
21
+ }
22
+ end
23
+
24
+ menu.choice("Exit!"){
25
+ exit
26
+ }
27
+ end
28
+
29
+ end
30
+
31
+ def select_instance(region)
32
+ # Select an instance
33
+ @instances = BaseMethods.describe_instance_by_region(region)
34
+
35
+ choose do |menu|
36
+ if @instances == []
37
+ menu.prompt = "No instances in this region"
38
+ else
39
+ menu.prompt = "Select an instance"
40
+
41
+ @instances.each do | instance |
42
+
43
+ hash = {
44
+ :instance_id => instance[:instance_id],
45
+ :status => instance[:instance_state],
46
+ :name => instance[:name],
47
+ :launch_time => instance[:launch_time]
48
+ }
49
+
50
+ table = Terminal::Table.new :rows => hash
51
+ menu.choice(table){
52
+ table = Terminal::Table.new :rows => instance
53
+ puts table
54
+ @selected_instance = instance
55
+ }
56
+ end
57
+ end
58
+ menu.choice("Change Regions"){
59
+ BaseMethods.start_over("none")
60
+ }
61
+
62
+ menu.choice("Exit!"){
63
+ exit
64
+ }
65
+ end
66
+ end
67
+
68
+ def instance_action(selected_instance)
69
+ @selected_instance = selected_instance
70
+ # Choose an Action
71
+ choose do | menu |
72
+
73
+ menu.prompt = "What would you like to do?"
74
+ unless @selected_instance[:instance_state] == "stopped" || @selected_instance[:instance_state] == "terminated"
75
+
76
+ #Sets @path_to_keypairs for access
77
+ @path_to_keypairs = StartingConfiguration.path_to_keypair
78
+ menu.choice("SSH"){
79
+ system "ssh -i #{@path_to_keypairs}#{@selected_instance[:keypair]}.pem ec2-user@#{@selected_instance[:ip_address]}"
80
+ BaseMethods.start_over(@@region)
81
+ }
82
+ end
83
+ menu.choice("Refresh"){
84
+ # Actually pull new data
85
+ table = Terminal::Table.new :rows => @selected_instance
86
+ puts table
87
+ # Back to the beginning!
88
+ self.instance_action(selected_instance)
89
+ }
90
+
91
+ if @selected_instance[:instance_state] == "running"
92
+ menu.choice("Terminate"){
93
+ choose do | menu2 |
94
+ menu2.header = "Are you sure?"
95
+
96
+ menu2.choice("Yes"){
97
+ BaseMethods.instance_action(@selected_instance[:instance_id], "terminate", @@region)
98
+ say("Instance #{@selected_instance[:instance_id]} has been TERMINATED")
99
+ self.instance_action(selected_instance)
100
+ }
101
+ menu2.choice("No"){
102
+ self.instance_action(selected_instance)
103
+ }
104
+ end
105
+ }
106
+ menu.choice("Stop"){
107
+ choose do | menu2 |
108
+ menu2.header = "Are you sure?"
109
+ menu2.choice("Yes"){
110
+ BaseMethods.instance_action(@selected_instance[:instance_id], "stop", @@region)
111
+ say("Instance #{@selected_instance[:instance_id]} has been Stopped")
112
+ self.instance_action(selected_instance)
113
+ }
114
+ menu2.choice("No"){
115
+ self.instance_action(selected_instance)
116
+ }
117
+ end
118
+ }
119
+ elsif @selected_instance[:instance_state] == "stopped"
120
+ menu.choice("Start"){
121
+ BaseMethods.instance_action(@selected_instance[:instance_id], "start", @@region)
122
+ say("Instance #{@selected_instance[:instance_id]} has been STARTED")
123
+ self.instance_action(selected_instance)
124
+ }
125
+ menu.choice("Terminate"){
126
+ choose do | menu2 |
127
+ menu2.header = "Are you sure?"
128
+ menu2.choice("Yes"){
129
+ BaseMethods.instance_action(@selected_instance[:instance_id], "terminate", @@region)
130
+ say("Instance #{@selected_instance[:instance_id]} has been TERMINATED")
131
+ self.instance_action(selected_instance)
132
+ }
133
+ menu2.choice("No"){
134
+ puts "No action taken"
135
+ self.instance_action(selected_instance)
136
+ }
137
+ end
138
+ }
139
+ end
140
+
141
+ menu.choice("Back to instances in #{@@region}"){
142
+ BaseMethods.start_over(@@region)
143
+ }
144
+ menu.choice("Change Regions"){
145
+ @@region=nil
146
+ BaseMethods.start_over("none")
147
+ }
148
+
149
+ menu.choice("Exit!"){
150
+ exit
151
+ }
152
+ end
153
+ end
154
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module AWSInteractiveCLI
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws_interactive_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jack Ellis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-22 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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
+ - !ruby/object:Gem::Dependency
42
+ name: highline
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: terminal-table
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: ! '["Interactive AWS CLI"]'
84
+ email:
85
+ - andellis@amazon.com
86
+ executables:
87
+ - aws_interactive_cli
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .DS_Store
92
+ - .gitignore
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - aws-interactive-cli.gemspec
98
+ - bin/aws_interactive_cli
99
+ - lib/.DS_Store
100
+ - lib/aws_interactive_cli.rb
101
+ - lib/aws_interactive_cli/version.rb
102
+ - lib/base_methods.rb
103
+ - lib/configuration.rb
104
+ - lib/questions.rb
105
+ - lib/version.rb
106
+ homepage: ''
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.0.9
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: ! '["Easy way to start, stop, and ssh into instances"]'
130
+ test_files: []