pero 0.5.7 → 0.5.8

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
  SHA256:
3
- metadata.gz: 5f292ef6092bf2aadcccca0a70fbf2257d273f0e2fded39752b8817d6920c334
4
- data.tar.gz: 31d236c3533a6981aedf8d90d60b835561b64e50cfb5b643755f572e68003613
3
+ metadata.gz: 4a48e2786db38760a4c084182d6e8fa0d75ed4a8dc7a302bd019d66a58977e31
4
+ data.tar.gz: 85022aad2062db63dd56289a8b0a93998db0dc36a94cef79d46701e19f9e381e
5
5
  SHA512:
6
- metadata.gz: eccbb2a3cdf32be14329cc7e2386151c6943519cd5123066e35d04b7032206d6c066623fa87af0a6cf350e7a7b9027df0bf6320a1fac674bd3107c40fa66a9b4
7
- data.tar.gz: 8e179117e5ee50dc539a8f67d8308f9fe2928b6f1036eeddddd1f43e882e0784d8695c9aafa0d32c637953226dd9bb65091921bb7d0fe2a97c40a0d97b6b815d
6
+ metadata.gz: d4b82257f375edd65d5f336c5ea08289125c8fed6d0acad596a2e9ceedef6901c59c7c7d274dd41c8477f5a8bc44cb5f47d9a1df89d4ea44ff9ae2dea1f742f0
7
+ data.tar.gz: 4b541bd95a5c460f841ca63304e7141bc9390a3e20a93e6f7b1e463c522c40bf945c8512a0c6b755bdfbffe0099253d9dc28b406823695fb8a320a197b57efce
data/lib/pero/cli.rb CHANGED
@@ -1,6 +1,6 @@
1
- require "pero"
2
- require "thor"
3
- require "parallel"
1
+ require 'pero'
2
+ require 'thor'
3
+ require 'parallel'
4
4
 
5
5
  module Pero
6
6
  class CLI < Thor
@@ -17,41 +17,38 @@ module Pero
17
17
 
18
18
  def self.shared_options
19
19
  option :log_level, type: :string, aliases: ['-l'], default: 'info'
20
- option :user, type: :string, aliases: ['-x'], desc: "ssh user"
21
- option :key, type: :string, aliases: ['-i'], desc: "ssh private key"
22
- option :port, type: :numeric, aliases: ['-p'], desc: "ssh port"
23
- option "timeout", default: 10, type: :numeric, desc: "ssh connect timeout"
24
- option :ssh_config, type: :string, desc: "ssh config path"
25
- option :environment, type: :string, desc: "puppet environment"
26
- option :ask_password, type: :boolean, default: false, desc: "ask ssh or sudo password"
27
- option :vagrant, type: :boolean, default: false, desc: "use vagrarant"
28
- option :sudo, type: :boolean, default: true, desc: "use sudo"
29
- option "concurrent", aliases: '-C',default: 3, type: :numeric, desc: "running concurrent"
20
+ option :user, type: :string, aliases: ['-x'], desc: 'ssh user'
21
+ option :key, type: :string, aliases: ['-i'], desc: 'ssh private key'
22
+ option :port, type: :numeric, aliases: ['-p'], desc: 'ssh port'
23
+ option 'timeout', default: 10, type: :numeric, desc: 'ssh connect timeout'
24
+ option :ssh_config, type: :string, desc: 'ssh config path'
25
+ option :environment, type: :string, desc: 'puppet environment'
26
+ option :ask_password, type: :boolean, default: false, desc: 'ask ssh or sudo password'
27
+ option :vagrant, type: :boolean, default: false, desc: 'use vagrarant'
28
+ option :sudo, type: :boolean, default: true, desc: 'use sudo'
29
+ option 'concurrent', aliases: '-C', default: 3, type: :numeric, desc: 'running concurrent'
30
30
  end
31
31
 
32
- desc "versions", "show support version"
32
+ desc 'versions', 'show support version'
33
33
  def versions
34
- begin
35
- Pero::Puppet::Redhat.show_versions
36
- rescue => e
37
- Pero.log.error e.inspect
38
- end
34
+ Pero::Puppet::Redhat.show_versions
35
+ rescue StandardError => e
36
+ Pero.log.error e.inspect
39
37
  end
40
38
 
41
- desc "apply", "puppet apply"
39
+ desc 'apply', 'puppet apply'
42
40
  shared_options
43
- option "server-version", type: :string
44
- option "image-name", type: :string
41
+ option 'server-version', type: :string
42
+ option 'image-name', type: :string
45
43
  option :noop, aliases: '-n', default: false, type: :boolean
46
44
  option :test, aliases: '-t', default: false, type: :boolean
47
45
  option :verbose, aliases: '-v', default: true, type: :boolean
48
46
  option :tags, default: nil, type: :array
49
47
  option :volumes, default: nil, type: :array
50
- option "one-shot", default: false, type: :boolean, desc: "stop puppet server after run"
48
+ option 'one-shot', default: false, type: :boolean, desc: 'stop puppet server after run'
51
49
  def apply(name_regexp)
52
-
53
- if !options["image-name"] && !options["server-version"]
54
- Pero.log.error "image-name or server-version are required"
50
+ if !options['image-name'] && !options['server-version']
51
+ Pero.log.error 'image-name or server-version are required'
55
52
  return
56
53
  end
57
54
 
@@ -64,64 +61,60 @@ module Pero
64
61
  m = Mutex.new
65
62
 
66
63
  begin
67
- Parallel.each(nodes, in_threads: options["concurrent"]) do |n|
64
+ Parallel.each(nodes, in_threads: options['concurrent']) do |n|
68
65
  opt = merge_options(n, options)
69
- puppet = Pero::Puppet.new(opt["host"], opt, m)
66
+ puppet = Pero::Puppet.new(opt['host'], opt, m)
70
67
  puppet.apply
71
68
  end
72
- rescue => e
69
+ rescue StandardError => e
73
70
  Pero.log.error e.backtrace.join("\n")
74
71
  Pero.log.error e.inspect
75
-
76
72
  ensure
77
- if options["one-shot"]
78
- Pero.log.info "stop puppet master container"
79
- Parallel.each(nodes, in_threads: options["concurrent"]) do |n|
80
- opt = merge_options(n, options)
81
- Pero::Puppet.new(opt["host"], opt, m).stop_master
82
- end
73
+ if options['one-shot']
74
+ Pero.log.info 'stop puppet master container'
75
+ opt = merge_options(nodes.first, options)
76
+ Pero::Puppet.new(opt['host'], opt, m).stop_master
83
77
  else
84
- Pero.log.info "puppet master container keep running"
78
+ Pero.log.info 'puppet master container keep running'
85
79
  end
86
80
  end
87
81
  end
88
82
 
89
- desc "bootstrap", "bootstrap pero"
83
+ desc 'bootstrap', 'bootstrap pero'
90
84
  shared_options
91
- option "agent-version", type: :string
92
- option "node-name", aliases: '-N', default: "", type: :string, desc: "json node name(default hostname)"
85
+ option 'agent-version', type: :string
86
+ option 'node-name', aliases: '-N', default: '', type: :string, desc: 'json node name(default hostname)'
93
87
  def bootstrap(*hosts)
94
- begin
95
- options["environment"] = "production" if options["environment"].nil? || options["environment"].empty?
96
- m = Mutex.new
97
- Parallel.each(hosts, in_threads: options["concurrent"]) do |host|
98
- raise "unknown option #{host}" if host =~ /^-/
99
- puppet = Pero::Puppet.new(host, options, m)
88
+ options['environment'] = 'production' if options['environment'].nil? || options['environment'].empty?
89
+ m = Mutex.new
90
+ Parallel.each(hosts, in_threads: options['concurrent']) do |host|
91
+ raise "unknown option #{host}" if host =~ /^-/
100
92
 
101
- Pero.log.info "bootstrap pero #{host}"
102
- puppet.install
103
- end
104
- rescue => e
105
- Pero.log.error e.backtrace.join("\n")
106
- Pero.log.error e.inspect
93
+ puppet = Pero::Puppet.new(host, options, m)
94
+
95
+ Pero.log.info "bootstrap pero #{host}"
96
+ puppet.install
107
97
  end
98
+ rescue StandardError => e
99
+ Pero.log.error e.backtrace.join("\n")
100
+ Pero.log.error e.inspect
108
101
  end
109
102
 
110
103
  no_commands do
111
104
  def merge_options(node, options)
112
- opt = node["last_options"].merge(options)
113
- opt["environment"] = "production" if opt["environment"].nil? || opt["environment"].empty?
114
- if options["image-name"]
115
- opt.delete("server-version")
105
+ opt = node['last_options'].merge(options)
106
+ opt['environment'] = 'production' if opt['environment'].nil? || opt['environment'].empty?
107
+ if options['image-name']
108
+ opt.delete('server-version')
116
109
  else
117
- opt.delete("image-name")
110
+ opt.delete('image-name')
118
111
  end
119
112
  opt
120
113
  end
121
114
 
122
115
  def prepare
123
- `bundle install` if File.exist?("Gemfile")
124
- `bundle exec librarian-puppet install` if File.exist?("Puppetfile")
116
+ `bundle install` if File.exist?('Gemfile')
117
+ `bundle exec librarian-puppet install` if File.exist?('Puppetfile')
125
118
  end
126
119
  end
127
120
  end
data/lib/pero/puppet.rb CHANGED
@@ -94,7 +94,7 @@ module Pero
94
94
  @mutex.lock
95
95
  run_container.kill if docker.alerady_run?
96
96
  ensure
97
- @mutex.unlock if @mutex.owned?
97
+ @mutex.unlock
98
98
  end
99
99
 
100
100
  def serve_master
@@ -115,7 +115,7 @@ module Pero
115
115
  @mutex.lock
116
116
  docker.alerady_run? || docker.run
117
117
  ensure
118
- @mutex.unlock if @mutex.owned?
118
+ @mutex.unlock
119
119
  end
120
120
 
121
121
  def apply
data/lib/pero/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pero
2
- VERSION = '0.5.7'
2
+ VERSION = '0.5.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - pyama86