From ab406d6f9a8487b2ac837adc3eeae01788fb2a93 Mon Sep 17 00:00:00 2001 From: elijah Date: Fri, 10 Jul 2015 18:04:08 -0700 Subject: improve `leap facts update`. closes bugs #7236 and #7237 --- lib/leap_cli/commands/deploy.rb | 2 +- lib/leap_cli/commands/facts.rb | 8 ++++---- lib/leap_cli/config/filter.rb | 3 +++ lib/leap_cli/config/manager.rb | 4 ++-- lib/leap_cli/remote/leap_plugin.rb | 3 ++- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/leap_cli/commands/deploy.rb b/lib/leap_cli/commands/deploy.rb index f5c47fe..c2a70af 100644 --- a/lib/leap_cli/commands/deploy.rb +++ b/lib/leap_cli/commands/deploy.rb @@ -34,7 +34,7 @@ module LeapCli init_submodules end - nodes = manager.filter!(args) + nodes = manager.filter!(args, :disabled => false) if nodes.size > 1 say "Deploying to these nodes: #{nodes.keys.join(', ')}" if !global[:yes] && !agree("Continue? ") diff --git a/lib/leap_cli/commands/facts.rb b/lib/leap_cli/commands/facts.rb index 65eda61..11329cc 100644 --- a/lib/leap_cli/commands/facts.rb +++ b/lib/leap_cli/commands/facts.rb @@ -49,7 +49,7 @@ module LeapCli; module Commands if overwrite || content.nil? || content.empty? old_facts = {} else - old_facts = JSON.parse(content) + old_facts = manager.facts end facts = old_facts.merge(new_facts) facts.each do |name, value| @@ -57,7 +57,7 @@ module LeapCli; module Commands if value == "" value = nil else - value = JSON.parse(value) + value = JSON.parse(value) rescue JSON::ParserError end end if value.is_a? Hash @@ -69,7 +69,7 @@ module LeapCli; module Commands value.nil? || value.empty? end if facts.empty? - nil + "{}\n" else JSON.sorted_generate(facts) + "\n" end @@ -79,7 +79,7 @@ module LeapCli; module Commands private def update_facts(global_options, options, args) - nodes = manager.filter(args, :local => false) + nodes = manager.filter(args, :local => false, :disabled => false) new_facts = {} ssh_connect(nodes) do |ssh| ssh.leap.run_with_progress(facter_cmd) do |response| diff --git a/lib/leap_cli/config/filter.rb b/lib/leap_cli/config/filter.rb index 0a7e91c..2c80be8 100644 --- a/lib/leap_cli/config/filter.rb +++ b/lib/leap_cli/config/filter.rb @@ -97,6 +97,9 @@ module LeapCli if @options[:local] === false node_list = node_list[:environment => '!local'] end + if @options[:disabled] === false + node_list = node_list[:environment => '!disabled'] + end node_list end diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb index 2b4d0f5..b8343fe 100644 --- a/lib/leap_cli/config/manager.rb +++ b/lib/leap_cli/config/manager.rb @@ -255,8 +255,8 @@ module LeapCli # # same as filter(), but exits if there is no matching nodes # - def filter!(filters) - node_list = filter(filters) + def filter!(filters, options={}) + node_list = filter(filters, options) Util::assert! node_list.any?, "Could not match any nodes from '#{filters.join ' '}'" return node_list end diff --git a/lib/leap_cli/remote/leap_plugin.rb b/lib/leap_cli/remote/leap_plugin.rb index e425842..3e33a61 100644 --- a/lib/leap_cli/remote/leap_plugin.rb +++ b/lib/leap_cli/remote/leap_plugin.rb @@ -184,7 +184,8 @@ module LeapCli; module Remote; module LeapPlugin private def progress(str='.') - $stdout.print str; $stdout.flush; + print str + STDOUT.flush end #def mkdir(dir) -- cgit v1.2.3