summaryrefslogtreecommitdiff
path: root/lib/leap_cli/config/manager.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2012-10-23 03:53:06 -0700
committerelijah <elijah@riseup.net>2012-10-23 03:53:06 -0700
commit628165fd0a4e03bb7bbef3a464447924195e10b8 (patch)
tree746280b6f4d6d488fcece4fff41b4addfb77d0c1 /lib/leap_cli/config/manager.rb
parent4f38e99c629f60d9524d1cf23efa7ab927ac9cf4 (diff)
added a bunch of new commands, including init-node and deploy
Diffstat (limited to 'lib/leap_cli/config/manager.rb')
-rw-r--r--lib/leap_cli/config/manager.rb28
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb
index 432ba0b..79ae5b8 100644
--- a/lib/leap_cli/config/manager.rb
+++ b/lib/leap_cli/config/manager.rb
@@ -18,12 +18,16 @@ module LeapCli
#
# load .json configuration files
#
- def load(dir)
- @services = load_all_json("#{dir}/services/*.json")
- @tags = load_all_json("#{dir}/tags/*.json")
- @common = load_all_json("#{dir}/common.json")['common']
- @provider = load_all_json("#{dir}/provider.json")['provider']
- @nodes = load_all_json("#{dir}/nodes/*.json")
+ def load(provider_dir=Path.provider)
+ @services = load_all_json(Path.named_path( [:service_config, '*'], provider_dir ))
+ @tags = load_all_json(Path.named_path( [:tag_config, '*'], provider_dir ))
+ @common = load_all_json(Path.named_path( :common_config, provider_dir ))['common']
+ @provider = load_all_json(Path.named_path( :provider_config, provider_dir ))['provider']
+ @nodes = load_all_json(Path.named_path( [:node_config, '*'], provider_dir ))
+
+ Util::assert!(@provider, "Failed to load provider.json")
+ Util::assert!(@common, "Failed to load common.json")
+
@nodes.each do |name, node|
@nodes[name] = apply_inheritance(node)
end
@@ -32,11 +36,10 @@ module LeapCli
#
# save compiled hiera .yaml files
#
- def export(dir)
+ def export(dir=Path.named_path(:hiera_dir))
existing_files = Dir.glob(dir + '/*.yaml')
updated_files = []
@nodes.each do |name, node|
- # not sure if people will approve of this change:
filepath = "#{dir}/#{name}.yaml"
updated_files << filepath
Util::write_file!(filepath, node.to_yaml)
@@ -86,6 +89,15 @@ module LeapCli
end
#
+ # same as filter(), but exits if there is no matching nodes
+ #
+ def filter!(filters)
+ node_list = filter(filters)
+ Util::assert! node_list.any?, "Could not match any nodes from '#{filters}'"
+ return node_list
+ end
+
+ #
# returns a single Config::Object that corresponds to a Node.
#
def node(name)