Class: Pero::CLI
- Inherits:
-
Thor
- Object
- Thor
- Pero::CLI
- Defined in:
- lib/pero/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #apply(name_regexp) ⇒ Object
- #bootstrap(*hosts) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #versions ⇒ Object
Constructor Details
Class Method Details
.exit_on_failure? ⇒ Boolean
8 9 10 |
# File 'lib/pero/cli.rb', line 8 def exit_on_failure? true end |
.shared_options ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pero/cli.rb', line 18 def self. option :log_level, type: :string, aliases: ['-l'], default: 'info' option :user, type: :string, aliases: ['-x'], desc: 'ssh user' option :key, type: :string, aliases: ['-i'], desc: 'ssh private key' option :port, type: :numeric, aliases: ['-p'], desc: 'ssh port' option 'timeout', default: 10, type: :numeric, desc: 'ssh connect timeout' option :ssh_config, type: :string, desc: 'ssh config path' option :environment, type: :string, desc: 'puppet environment' option :ask_password, type: :boolean, default: false, desc: 'ask ssh or sudo password' option :vagrant, type: :boolean, default: false, desc: 'use vagrarant' option :sudo, type: :boolean, default: true, desc: 'use sudo' option 'concurrent', aliases: '-C', default: 3, type: :numeric, desc: 'running concurrent' end |
Instance Method Details
#apply(name_regexp) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/pero/cli.rb', line 49 def apply(name_regexp) if !['image-name'] && !['server-version'] Pero.log.error 'image-name or server-version are required' return end prepare nodes = Pero::History.search(name_regexp) if nodes.empty? Pero.log.info 'No matching node found.' return end m = Mutex.new begin Parallel.each(nodes, in_threads: ['concurrent']) do |n| opt = (n, ) puppet = Pero::Puppet.new(opt['host'], opt, m) puppet.apply end rescue StandardError => e Pero.log.error e.backtrace.join("\n") Pero.log.error e.inspect ensure if ['one-shot'] Pero.log.info 'stop puppet master container' opt = (nodes.first, ) Pero::Puppet.new(opt['host'], opt, m).stop_master else Pero.log.info 'puppet master container keep running' end end end |
#bootstrap(*hosts) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/pero/cli.rb', line 87 def bootstrap(*hosts) ['environment'] = 'production' if ['environment'].nil? || ['environment'].empty? m = Mutex.new Parallel.each(hosts, in_threads: ['concurrent']) do |host| raise "unknown option #{host}" if host =~ /^-/ puppet = Pero::Puppet.new(host, , m) Pero.log.info "bootstrap pero #{host}" puppet.install end rescue StandardError => e Pero.log.error e.backtrace.join("\n") Pero.log.error e.inspect end |