From 6e5d404bdd1a8f56fdfb0eee865f9029ae12b616 Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 12 Dec 2012 22:40:59 -0800 Subject: auto compile before deploy (as needed) --- lib/leap_cli/config/manager.rb | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'lib/leap_cli/config') diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb index 39dbcd2..adda9bd 100644 --- a/lib/leap_cli/config/manager.rb +++ b/lib/leap_cli/config/manager.rb @@ -53,23 +53,39 @@ module LeapCli # # save compiled hiera .yaml files # - def export_nodes - existing_hiera = Dir.glob(Path.named_path([:hiera, '*'], @provider_dir)) - existing_files = Dir.glob(Path.named_path([:node_files_dir, '*'], @provider_dir)) + # if a node_list is specified, only update those .yaml files. + # otherwise, update all files, destroying files that are no longer used. + # + def export_nodes(node_list=nil) updated_hiera = [] updated_files = [] - self.each_node do |node| + existing_hiera = nil + existing_files = nil + + unless node_list + node_list = self.nodes + existing_hiera = Dir.glob(Path.named_path([:hiera, '*'], @provider_dir)) + existing_files = Dir.glob(Path.named_path([:node_files_dir, '*'], @provider_dir)) + end + + node_list.each_node do |node| filepath = Path.named_path([:node_files_dir, node.name], @provider_dir) - updated_files << filepath hierapath = Path.named_path([:hiera, node.name], @provider_dir) - updated_hiera << hierapath Util::write_file!(hierapath, node.dump) + updated_files << filepath + updated_hiera << hierapath end - (existing_hiera - updated_hiera).each do |filepath| - Util::remove_file!(filepath) + + # remove files that are no longer needed + if existing_hiera + (existing_hiera - updated_hiera).each do |filepath| + Util::remove_file!(filepath) + end end - (existing_files - updated_files).each do |filepath| - Util::remove_directory!(filepath) + if existing_files + (existing_files - updated_files).each do |filepath| + Util::remove_directory!(filepath) + end end end -- cgit v1.2.3