pec2 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +3 -0
- data/.gitignore +9 -0
- data/.rspec +1 -0
- data/.travis.yml +18 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +4 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +49 -0
- data/Rakefile +25 -0
- data/bin/pec2 +6 -0
- data/lib/pec2.rb +3 -0
- data/lib/pec2/cli.rb +63 -0
- data/lib/pec2/constants.rb +2 -0
- data/lib/pec2/core.rb +24 -0
- data/lib/pec2/version.rb +4 -0
- data/pec2.gemspec +30 -0
- data/spec/cli_spec.rb +24 -0
- data/spec/core_spec.rb +19 -0
- data/spec/pec2_spec.rb +8 -0
- data/spec/spec_helper.rb +26 -0
- metadata +195 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d78ae8aeefe586ab7ffad3c3d155e68f4d76559d
|
4
|
+
data.tar.gz: bd3c40bfa4f23402926065952e0616509441cdc3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c418e888f41e8fa968cdcdbbf9338c735a09bc561b996dc800b6bcc97ab1d805411f9079a542c5da52647c26867de091bc96c614a58421c48638e7cec4c4aa8f
|
7
|
+
data.tar.gz: ffe4f76a5056989b6aa8b12d15b219b8c24e5225585efa649c38326e386a34a435e09abdddd88b5d0eb12eb73bc53c22f56fb5696480002cba875b3f10b0e780
|
data/.document
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format documentation
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown --title "pec2 Documentation" --protected
|
data/ChangeLog.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 toyama0919
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# pec2 [![Build Status](https://secure.travis-ci.org/toyama0919/pec2.png?branch=master)](http://travis-ci.org/toyama0919/pec2)
|
2
|
+
|
3
|
+
TODO: Summary
|
4
|
+
|
5
|
+
TODO: Description
|
6
|
+
|
7
|
+
## Examples
|
8
|
+
|
9
|
+
$ pec2 sample
|
10
|
+
#=> hoge
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'pec2'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install pec2
|
25
|
+
|
26
|
+
## Synopsis
|
27
|
+
|
28
|
+
$ pec2
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new [Pull Request](../../pull/new/master)
|
37
|
+
|
38
|
+
## Information
|
39
|
+
|
40
|
+
* [Homepage](https://github.com/toyama0919/pec2)
|
41
|
+
* [Issues](https://github.com/toyama0919/pec2/issues)
|
42
|
+
* [Documentation](http://rubydoc.info/gems/pec2/frames)
|
43
|
+
* [Email](mailto:toyama0919@gmail.com)
|
44
|
+
|
45
|
+
## Copyright
|
46
|
+
|
47
|
+
Copyright (c) 2016 toyama0919
|
48
|
+
|
49
|
+
See [LICENSE.txt](../LICENSE.txt) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bundler/setup'
|
7
|
+
rescue LoadError => e
|
8
|
+
abort e.message
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
|
14
|
+
require 'rubygems/tasks'
|
15
|
+
Gem::Tasks.new
|
16
|
+
|
17
|
+
require 'rspec/core/rake_task'
|
18
|
+
RSpec::Core::RakeTask.new
|
19
|
+
|
20
|
+
task :test => :spec
|
21
|
+
task :default => :spec
|
22
|
+
|
23
|
+
require 'yard'
|
24
|
+
YARD::Rake::YardocTask.new
|
25
|
+
task :doc => :yard
|
data/bin/pec2
ADDED
data/lib/pec2.rb
ADDED
data/lib/pec2/cli.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "thor"
|
2
|
+
require "tempfile"
|
3
|
+
|
4
|
+
module Pec2
|
5
|
+
class CLI < Thor
|
6
|
+
|
7
|
+
map '-v' => :version
|
8
|
+
default_task :search_tag
|
9
|
+
|
10
|
+
def initialize(args = [], options = {}, config = {})
|
11
|
+
super(args, options, config)
|
12
|
+
@global_options = config[:shell].base.options
|
13
|
+
@core = Core.new
|
14
|
+
@pssh_path = `which pssh`.strip
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'search_tag', 'search tag'
|
18
|
+
option :command, aliases: '-c', type: :string, required: true, desc: 'command'
|
19
|
+
option :sudo_password, aliases: '-s', type: :string, desc: 'sudo_password'
|
20
|
+
option :tag, aliases: '-t', type: :hash, default: {}, desc: 'tag'
|
21
|
+
option :user, aliases: '-u', type: :string, desc: 'user'
|
22
|
+
option :log, aliases: '-o', type: :string, desc: 'log'
|
23
|
+
option :print, aliases: '-P', type: :boolean, default: false, desc: 'print stdout.'
|
24
|
+
def search_tag
|
25
|
+
Tempfile.create("pec2") do |f|
|
26
|
+
addresses = @core.instances_hash(options[:tag]).map do |instance|
|
27
|
+
instance.private_ip_address
|
28
|
+
end
|
29
|
+
|
30
|
+
if addresses.empty?
|
31
|
+
raise "no host."
|
32
|
+
end
|
33
|
+
|
34
|
+
File.write(f.path, addresses.join("\n"))
|
35
|
+
cmd = "#{@pssh_path} -t 0 -x '-tt' -h #{f.path} -O StrictHostKeyChecking=no"
|
36
|
+
|
37
|
+
if options[:print]
|
38
|
+
cmd = "#{cmd} -P"
|
39
|
+
end
|
40
|
+
|
41
|
+
if options[:user]
|
42
|
+
cmd = "#{cmd} -l #{options[:user]}"
|
43
|
+
end
|
44
|
+
|
45
|
+
if options[:log]
|
46
|
+
cmd = "#{cmd} -o #{options[:log]}"
|
47
|
+
end
|
48
|
+
|
49
|
+
if options[:sudo_password]
|
50
|
+
cmd = %Q{(echo #{options[:sudo_password]}) | #{cmd} -I '#{options[:command]}'}
|
51
|
+
else
|
52
|
+
cmd = %Q{#{cmd} -i '#{options[:command]}'}
|
53
|
+
end
|
54
|
+
system(cmd)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
desc 'version', 'show version'
|
59
|
+
def version
|
60
|
+
puts VERSION
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/pec2/core.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
require 'hashie'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module Pec2
|
6
|
+
class Core
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@logger = Logger.new(STDOUT)
|
10
|
+
@ec2 = Aws::EC2::Client.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def instances_hash(condition)
|
14
|
+
filter = []
|
15
|
+
condition.each do |key, value|
|
16
|
+
filter << { name: "tag:#{key}", values: ["#{value}"] }
|
17
|
+
end
|
18
|
+
filter << { name: 'instance-state-name', values: ['running'] }
|
19
|
+
@ec2.describe_instances(
|
20
|
+
filters: filter
|
21
|
+
).data.to_h[:reservations].map { |instance| Hashie::Mash.new(instance[:instances].first) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/pec2/version.rb
ADDED
data/pec2.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path('../lib/pec2/version', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "pec2"
|
7
|
+
gem.version = Pec2::VERSION
|
8
|
+
gem.summary = %q{run parallel ssh command. ec2 tag base operation.}
|
9
|
+
gem.description = %q{run parallel ssh command. ec2 tag base operation.}
|
10
|
+
gem.license = "MIT"
|
11
|
+
gem.authors = ["toyama0919"]
|
12
|
+
gem.email = "toyama0919@gmail.com"
|
13
|
+
gem.homepage = "https://github.com/toyama0919/pec2"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_dependency 'thor', '~> 0.19.1'
|
21
|
+
gem.add_dependency 'aws-sdk'
|
22
|
+
|
23
|
+
gem.add_development_dependency 'bundler'
|
24
|
+
gem.add_development_dependency 'pry'
|
25
|
+
gem.add_development_dependency 'rake'
|
26
|
+
gem.add_development_dependency 'rspec'
|
27
|
+
gem.add_development_dependency 'rubocop'
|
28
|
+
gem.add_development_dependency 'rubygems-tasks'
|
29
|
+
gem.add_development_dependency 'yard'
|
30
|
+
end
|
data/spec/cli_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pec2'
|
3
|
+
|
4
|
+
describe Pec2::CLI do
|
5
|
+
before do
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should stdout sample" do
|
9
|
+
output = capture_stdout do
|
10
|
+
Pec2::CLI.start(['help'])
|
11
|
+
end
|
12
|
+
expect(output).not_to eq(nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "include" do
|
16
|
+
output = capture_stdout do
|
17
|
+
Pec2::CLI.start(['help', 'sample'])
|
18
|
+
end
|
19
|
+
expect(output).to include('--fields')
|
20
|
+
end
|
21
|
+
|
22
|
+
after do
|
23
|
+
end
|
24
|
+
end
|
data/spec/core_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pec2'
|
3
|
+
|
4
|
+
describe Pec2::Core do
|
5
|
+
before do
|
6
|
+
@core = Core.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "core not nil" do
|
10
|
+
expect(@core).not_to eq(nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "private method" do
|
14
|
+
@core.send(:sample, []).should == []
|
15
|
+
end
|
16
|
+
|
17
|
+
after do
|
18
|
+
end
|
19
|
+
end
|
data/spec/pec2_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'pec2/version'
|
3
|
+
|
4
|
+
include Pec2
|
5
|
+
|
6
|
+
def capture_stdout
|
7
|
+
out = StringIO.new
|
8
|
+
$stdout = out
|
9
|
+
yield
|
10
|
+
return out.string
|
11
|
+
ensure
|
12
|
+
$stdout = STDOUT
|
13
|
+
end
|
14
|
+
|
15
|
+
def capture_stderr
|
16
|
+
out = StringIO.new
|
17
|
+
$stderr = out
|
18
|
+
yield
|
19
|
+
return out.string
|
20
|
+
ensure
|
21
|
+
$stderr = STDERR
|
22
|
+
end
|
23
|
+
|
24
|
+
def clear_env
|
25
|
+
ENV['PASSPHRASE'] = nil
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pec2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- toyama0919
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-22 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.19.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.19.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sdk
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
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: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
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: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubygems-tasks
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: yard
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: run parallel ssh command. ec2 tag base operation.
|
140
|
+
email: toyama0919@gmail.com
|
141
|
+
executables:
|
142
|
+
- pec2
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".document"
|
147
|
+
- ".gitignore"
|
148
|
+
- ".rspec"
|
149
|
+
- ".travis.yml"
|
150
|
+
- ".yardopts"
|
151
|
+
- ChangeLog.md
|
152
|
+
- Gemfile
|
153
|
+
- LICENSE.txt
|
154
|
+
- README.md
|
155
|
+
- Rakefile
|
156
|
+
- bin/pec2
|
157
|
+
- lib/pec2.rb
|
158
|
+
- lib/pec2/cli.rb
|
159
|
+
- lib/pec2/constants.rb
|
160
|
+
- lib/pec2/core.rb
|
161
|
+
- lib/pec2/version.rb
|
162
|
+
- pec2.gemspec
|
163
|
+
- spec/cli_spec.rb
|
164
|
+
- spec/core_spec.rb
|
165
|
+
- spec/pec2_spec.rb
|
166
|
+
- spec/spec_helper.rb
|
167
|
+
homepage: https://github.com/toyama0919/pec2
|
168
|
+
licenses:
|
169
|
+
- MIT
|
170
|
+
metadata: {}
|
171
|
+
post_install_message:
|
172
|
+
rdoc_options: []
|
173
|
+
require_paths:
|
174
|
+
- lib
|
175
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - ">="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '0'
|
185
|
+
requirements: []
|
186
|
+
rubyforge_project:
|
187
|
+
rubygems_version: 2.5.1
|
188
|
+
signing_key:
|
189
|
+
specification_version: 4
|
190
|
+
summary: run parallel ssh command. ec2 tag base operation.
|
191
|
+
test_files:
|
192
|
+
- spec/cli_spec.rb
|
193
|
+
- spec/core_spec.rb
|
194
|
+
- spec/pec2_spec.rb
|
195
|
+
- spec/spec_helper.rb
|