aws-opsworks_cssh 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8ef459aa7cbd81a21dcc4c1264eea3ed5e23f67b
4
+ data.tar.gz: 56976a4982686382f54881b9824efe7cce2ecdcb
5
+ SHA512:
6
+ metadata.gz: bb47e5c9cf828056d8380e2f9823ec3f797c7c2c2dccb2d7874bc2c19e3ab1e58bec6be9ac55381e0a65e4cb36ad7bab206aec8c1f723e6f639f9ba8b434ab30
7
+ data.tar.gz: 13056362f6a06b630ba4ad939eef10630bbb529bac820d8a7fe33971cc228f4e6ef68e0675d34d235aaceccfc54ff94f4e478108f74ff32af66d2a3aa6700c37
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aws-opsworks_cssh.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Adnan H
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.
@@ -0,0 +1,55 @@
1
+ # Aws::OpsworksCssh
2
+
3
+ This gem can be used to ssh into all the instances of a given OpsWorks stack (cssh into all instances), by specifying the stack name and the user name.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'aws-opsworks_cssh'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install aws-opsworks_cssh
18
+
19
+ ## Usage
20
+
21
+ Before starting use, a config and credentials file needs to be setup along with a config which look like this:
22
+
23
+ ~/.aws/config
24
+
25
+ [default]
26
+ output = json
27
+ region = (Eg. us-east-1)
28
+
29
+
30
+ ~/.aws/credentials
31
+
32
+ [default]
33
+ aws_access_key_id = (20 char key)
34
+ aws_secret_access_key = (40 char secret)
35
+
36
+
37
+
38
+ Need to provide a username and stack. It picks up the aws key and aws secret from your ".aws" config file.
39
+
40
+ Usage:
41
+
42
+ $ aws-opsworks_cssh -u "USERNAME" -s "STACKNAME" -p
43
+
44
+ By default it uses public IP addresses.
45
+ If -p is passed along as an option then it would "force_private" and take private IP addresses for the instances.
46
+
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it ( https://github.com/[my-github-username]/aws-opsworks_cssh/fork )
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create a new Pull Request
55
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aws/opsworks_cssh/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "aws-opsworks_cssh"
8
+ spec.version = Aws::OpsworksCssh::VERSION
9
+ spec.authors = ["Adnan H"]
10
+ spec.email = ["adnan.husain+aws_gem@metoda.com"]
11
+ spec.summary = "CSSH into OpsWorks instances"
12
+ spec.description = "CSSH into all OpsWorks instances specified by a stack name"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_runtime_dependency "aws-sdk", "~> 2.1"
24
+ end
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'aws/opsworks_cssh'
4
+ require 'optparse'
5
+
6
+
7
+
8
+
9
+ options = {:ip => "public"}
10
+ opts = OptionParser.new do |opts|
11
+ opts.banner = "Usage: example.rb [options]"
12
+
13
+ opts.separator ""
14
+ opts.separator "Specific options:"
15
+
16
+ # Mandatory argument.
17
+ opts.on("-u", "--username USER",
18
+ "Require the USER before executing your script") do |user|
19
+ options[:user] = user
20
+ end
21
+ opts.on("-s", "--stackname STACK",
22
+ "Require the STACK before executing the script") do |stack|
23
+ options[:stack] = stack
24
+ end
25
+
26
+ opts.on("-p","--private",
27
+ "Optional. Specify the ipAddress to be public or private") do |ip|
28
+ options[:force_private] = "private"
29
+ end
30
+
31
+
32
+ opts.on_tail("-h","--help","Usage for AWS cssh gem script") do
33
+ puts opts
34
+ exit
35
+ end
36
+ end
37
+
38
+ opts.parse!
39
+ unless options[:stack]
40
+ puts opts
41
+ exit 1
42
+ end
43
+ puts "Executing cssh for user #{options[:user]} stack #{options[:stack]} "
44
+
45
+
46
+ Aws::OpsworksCssh.start_opsworks_cssh(options[:stack],options[:user],options[:force_private])
@@ -0,0 +1,50 @@
1
+ require "aws-sdk"
2
+ require "aws/opsworks_cssh/version"
3
+
4
+ module Aws
5
+ module OpsworksCssh
6
+
7
+
8
+
9
+ def self.start_opsworks_cssh(stack_name,user,force_private)
10
+
11
+ @resp_instances
12
+ options = {}
13
+ options['user'] = user
14
+
15
+
16
+ opsworks = Aws::OpsWorks::Client.new(region: 'us-east-1')
17
+ # sample stack_id = 'c06853f8-428e-44f7-8f6e-326703bf501e'
18
+ #sample stack name = 'Redcoon'
19
+ resp_stacks = opsworks.describe_stacks
20
+ #resp = opsworks.describe_instances({:stack_id => stack_id})
21
+ resp_stacks.stacks.each do |stack|
22
+ if stack.name == stack_name
23
+ @resp_instances = opsworks.describe_instances({:stack_id => stack.stack_id})
24
+ break
25
+ end
26
+ end
27
+
28
+ unless @resp_instances
29
+ $stderr.puts "No such stack: #{stack_name}"
30
+ exit 1
31
+ end
32
+
33
+ dns = @resp_instances.instances.map { |instance|
34
+ if force_private == "private"
35
+ instance.private_ip || instance.public_ip
36
+ else
37
+ instance.public_ip || instance.private_ip
38
+ end
39
+ }
40
+
41
+ cssh = (/darwin/ =~ RUBY_PLATFORM) ? 'csshX' : 'cssh'
42
+
43
+ cmd = "#{cssh} -l #{options['user']} #{dns.join ' '}"
44
+ puts "Connecting to #{dns.length} instances"
45
+ puts cmd
46
+ exec cmd
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,5 @@
1
+ module Aws
2
+ module OpsworksCssh
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws-opsworks_cssh
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Adnan H
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-04 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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: aws-sdk
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ description: CSSH into all OpsWorks instances specified by a stack name
56
+ email:
57
+ - adnan.husain+aws_gem@metoda.com
58
+ executables:
59
+ - aws-opsworks-cssh
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - aws-opsworks_cssh.gemspec
69
+ - bin/aws-opsworks-cssh
70
+ - lib/aws/opsworks_cssh.rb
71
+ - lib/aws/opsworks_cssh/version.rb
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: CSSH into OpsWorks instances
96
+ test_files: []