Class: Paknife::Context
- Inherits:
-
Object
- Object
- Paknife::Context
- Defined in:
- lib/paknife/context.rb
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#knife_options ⇒ Object
readonly
Returns the value of attribute knife_options.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#subcommand ⇒ Object
readonly
Returns the value of attribute subcommand.
Instance Method Summary collapse
- #command ⇒ Object
-
#initialize(index, backend, subcommand, node, knife_options, options = {}) ⇒ Context
constructor
A new instance of Context.
- #run ⇒ Object
Constructor Details
#initialize(index, backend, subcommand, node, knife_options, options = {}) ⇒ Context
Returns a new instance of Context.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/paknife/context.rb', line 9 def initialize(index, backend, subcommand, node, , = {}) @index = index @backend = backend @subcommand = subcommand @node = node = = setup_logger end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
7 8 9 |
# File 'lib/paknife/context.rb', line 7 def backend @backend end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
7 8 9 |
# File 'lib/paknife/context.rb', line 7 def index @index end |
#knife_options ⇒ Object (readonly)
Returns the value of attribute knife_options.
7 8 9 |
# File 'lib/paknife/context.rb', line 7 def end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/paknife/context.rb', line 7 def logger @logger end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
7 8 9 |
# File 'lib/paknife/context.rb', line 7 def node @node end |
#subcommand ⇒ Object (readonly)
Returns the value of attribute subcommand.
7 8 9 |
# File 'lib/paknife/context.rb', line 7 def subcommand @subcommand end |
Instance Method Details
#command ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/paknife/context.rb', line 45 def command [ [:knife], backend, subcommand, node, , ].flatten.compact.join(" ") end |
#run ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/paknife/context.rb', line 20 def run logger.info command Open3.popen3(command) do |stdin, stdout, stderr, wait_thr| stdin.close_write begin loop do IO.select([stdout, stderr]).flatten.compact.each do |io| io.each do |line| next if line.nil? || line.empty? if io == stdout logger.info line elsif io == stderr logger.warn line end end end break if stdout.eof? && stderr.eof? end rescue EOFError end end end |