aboutsummaryrefslogtreecommitdiff
path: root/lib/leap_cli/config/manager.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2012-12-12 22:40:59 -0800
committerelijah <elijah@riseup.net>2012-12-12 22:40:59 -0800
commit6e5d404bdd1a8f56fdfb0eee865f9029ae12b616 (patch)
tree89214d8fc93d675695af6ec8920cf2b8e8ed2cf0 /lib/leap_cli/config/manager.rb
parentde196e66c1b7c3b5e1e38d6d5ea024aac3fbe3bd (diff)
downloadleap_cli-6e5d404bdd1a8f56fdfb0eee865f9029ae12b616.tar.gz
leap_cli-6e5d404bdd1a8f56fdfb0eee865f9029ae12b616.tar.bz2
auto compile before deploy (as needed)
Diffstat (limited to 'lib/leap_cli/config/manager.rb')
-rw-r--r--lib/leap_cli/config/manager.rb36
1 files changed, 26 insertions, 10 deletions
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