pec2 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb281220d6b29ff7d3fee0f3f981680855d5cc08
4
- data.tar.gz: de60d8338782ebc4214835e90aba81d7171b0959
3
+ metadata.gz: c423952fa8333500b2fd92609486eee8091bfd3e
4
+ data.tar.gz: 7ab971186c28854893605c0f7bb1ee68ad58d433
5
5
  SHA512:
6
- metadata.gz: '08a9d23eb9c518f2fd8edc23f19fc5f5077a83626545c40331e202e680f98606547e9c9ceb666013b4e92f754459f53a88a9f97a4f804c25ad31f4255996baff'
7
- data.tar.gz: b65d6d2e8b3f7f6a395e1cbd9d1a75b47d28eb828a1af7d49a33c9391eabe04ef309ca9bb6e8320822e4cfbbdf8baaf30d7e99da816928dcb968f1bc7ae8a26f
6
+ metadata.gz: e65faac1a7c3a5f36a4a49bbbe7f6c9455aafe1ab6f2a4d2cbdb43e4b067b221915174adec28a40a6395561e2b6995011995ad2980f445791be534851daa26e3
7
+ data.tar.gz: c6b0bbdd12c15b1b6a98e73c70f383e406ade474727adefab9d285fcdc1b387ab281b157ce57da25ebe2f9ad0522e0bf72b32fef96e8488a7eb0b0b5763d3420
data/.travis.yml CHANGED
@@ -1,17 +1,16 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.0.*
5
4
  - 2.1.*
6
5
  - 2.2.*
7
- - 2.3.0
6
+ - 2.3.3
7
+ - 2.4.0
8
8
 
9
9
  gemfile:
10
10
  - Gemfile
11
11
 
12
12
  os:
13
13
  - linux
14
- - osx
15
14
 
16
15
  before_install: gem update bundler
17
16
 
data/README.md CHANGED
@@ -8,15 +8,15 @@ required python.
8
8
 
9
9
  ## Examples
10
10
 
11
- $ bundle exec pec2 -t Project:project_a Stages:production -c 'hostname'
11
+ $ pec2 -t Project:project_a Stages:production -c 'hostname'
12
12
 
13
13
  ## sudo Examples
14
14
 
15
- $ bundle exec pec2 -t Project:project_a Stages:production -c 'sudo hostname' -P -s ${sudo_password}
15
+ $ pec2 -t Project:project_a Stages:production -c 'sudo hostname' -P -s ${sudo_password}
16
16
 
17
17
  ## Parallel number control(150 threads)
18
18
 
19
- $ bundle exec pec2 -t Project:embulk Stages:production -c 'hostname' -P -p 150
19
+ $ pec2 -t Project:embulk Stages:production -c 'hostname' -P -p 150
20
20
 
21
21
  ## Installation
22
22
 
@@ -50,9 +50,3 @@ Or install it yourself as:
50
50
  * [Issues](https://github.com/toyama0919/pec2/issues)
51
51
  * [Documentation](http://rubydoc.info/gems/pec2/frames)
52
52
  * [Email](mailto:toyama0919@gmail.com)
53
-
54
- ## Copyright
55
-
56
- Copyright (c) 2016 toyama0919
57
-
58
- See [LICENSE.txt](../LICENSE.txt) for details.
data/lib/pec2/cli.rb CHANGED
@@ -7,7 +7,7 @@ module Pec2
7
7
  class CLI < Thor
8
8
 
9
9
  map '-v' => :version
10
- default_task :search_tag
10
+ default_task :run_command
11
11
 
12
12
  def initialize(args = [], options = {}, config = {})
13
13
  super(args, options, config)
@@ -17,7 +17,7 @@ module Pec2
17
17
  @logger = Logger.new(STDOUT)
18
18
  end
19
19
 
20
- desc 'search_tag', 'search tag'
20
+ desc 'run_command', 'run command'
21
21
  option :command, aliases: '-c', type: :string, required: true, desc: 'command'
22
22
  option :sudo_password, aliases: '-s', type: :string, desc: 'sudo_password'
23
23
  option :tag, aliases: '-t', type: :hash, default: {}, desc: 'tag'
@@ -25,43 +25,49 @@ module Pec2
25
25
  option :log, aliases: '-o', type: :string, desc: 'log'
26
26
  option :parallel, aliases: '-p', type: :numeric, desc: 'parallel'
27
27
  option :print, aliases: '-P', type: :boolean, default: false, desc: 'print stdout.'
28
- def search_tag
29
- Tempfile.create("pec2") do |f|
30
- addresses = @core.instances_hash(options[:tag]).map do |instance|
31
- instance.private_ip_address
32
- end
28
+ def run_command
29
+ addresses = @core.instances_hash(options[:tag]).map do |instance|
30
+ instance.private_ip_address
31
+ end
32
+
33
+ if addresses.empty?
34
+ @logger.info(%Q{no host tag #{options[:tag]}.})
35
+ exit
36
+ end
33
37
 
34
- if addresses.empty?
35
- @logger.error(%Q{no host tag #{options[:tag]}.})
36
- raise
37
- end
38
+ tf = Tempfile.open("pec2") { |fp|
39
+ fp.puts(addresses.join("\n"))
40
+ fp
41
+ }
38
42
 
39
- File.write(f.path, addresses.join("\n"))
40
- cmd = "#{@pssh_path} -t 0 -x '-tt' -h #{f.path} -O StrictHostKeyChecking=no"
43
+ cmd = "#{@pssh_path} -t 0 -x '-tt' -h #{tf.path} -O StrictHostKeyChecking=no"
44
+ if options[:print]
45
+ cmd = "#{cmd} -P"
46
+ end
41
47
 
42
- if options[:print]
43
- cmd = "#{cmd} -P"
44
- end
48
+ if options[:user]
49
+ cmd = "#{cmd} -l #{options[:user]}"
50
+ end
45
51
 
46
- if options[:user]
47
- cmd = "#{cmd} -l #{options[:user]}"
48
- end
52
+ if options[:log]
53
+ cmd = "#{cmd} -o #{options[:log]}"
54
+ end
49
55
 
50
- if options[:log]
51
- cmd = "#{cmd} -o #{options[:log]}"
52
- end
56
+ if options[:parallel]
57
+ cmd = "#{cmd} -p #{options[:parallel]}"
58
+ end
53
59
 
54
- if options[:parallel]
55
- cmd = "#{cmd} -p #{options[:parallel]}"
56
- end
60
+ if options[:sudo_password]
61
+ cmd = %Q{(echo #{options[:sudo_password]}) | #{cmd} -I #{Shellwords.escape(options[:command])}}
62
+ else
63
+ cmd = %Q{#{cmd} -i #{Shellwords.escape(options[:command])}}
64
+ end
57
65
 
58
- if options[:sudo_password]
59
- cmd = %Q{(echo #{options[:sudo_password]}) | #{cmd} -I #{Shellwords.escape(options[:command])}}
60
- else
61
- cmd = %Q{#{cmd} -i #{Shellwords.escape(options[:command])}}
62
- end
63
- system(cmd)
66
+ unless system(cmd)
67
+ tf.close
68
+ exit 1
64
69
  end
70
+ tf.close
65
71
  end
66
72
 
67
73
  desc 'version', 'show version'
data/lib/pec2/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Pec2
2
2
  # pec2 version
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.1"
4
4
  end
data/spec/cli_spec.rb CHANGED
@@ -14,9 +14,15 @@ describe Pec2::CLI do
14
14
 
15
15
  it "include" do
16
16
  output = capture_stdout do
17
- Pec2::CLI.start(['help', 'sample'])
17
+ Pec2::CLI.start(['help', 'run_command'])
18
18
  end
19
- expect(output).to include('--fields')
19
+ expect(output).to include('--command')
20
+ expect(output).to include('--sudo-password')
21
+ expect(output).to include('--tag')
22
+ expect(output).to include('--user')
23
+ expect(output).to include('--log')
24
+ expect(output).to include('--parallel')
25
+ expect(output).to include('--print')
20
26
  end
21
27
 
22
28
  after do
data/spec/core_spec.rb CHANGED
@@ -6,14 +6,6 @@ describe Pec2::Core do
6
6
  @core = Core.new
7
7
  end
8
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
9
  after do
18
10
  end
19
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pec2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - toyama0919
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-10 00:00:00.000000000 Z
11
+ date: 2017-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -164,7 +164,6 @@ files:
164
164
  - ".yardopts"
165
165
  - ChangeLog.md
166
166
  - Gemfile
167
- - LICENSE.txt
168
167
  - README.md
169
168
  - Rakefile
170
169
  - bin/pec2
data/LICENSE.txt DELETED
@@ -1,20 +0,0 @@
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.