From 8eec2d89983934868c9be07d55825cbe3bdcdaaf Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 2 Feb 2016 17:58:44 -0800 Subject: added templates for `leap node add`, so that new nodes can get default values set in their initial .json file. --- lib/leap_cli/commands/node.rb | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'lib/leap_cli/commands/node.rb') diff --git a/lib/leap_cli/commands/node.rb b/lib/leap_cli/commands/node.rb index ecd11f5e..cc352762 100644 --- a/lib/leap_cli/commands/node.rb +++ b/lib/leap_cli/commands/node.rb @@ -33,11 +33,13 @@ module LeapCli; module Commands if options[:local] node['ip_address'] = pick_next_vagrant_ip_address end - seed_node_data(node, args[1..-1]) + seed_node_data_from_cmd_line(node, args[1..-1]) + seed_node_data_from_template(node) validate_ip_address(node) begin - write_file! [:node_config, name], node.dump_json + "\n" node['name'] = name + json = node.dump_json(:exclude => ['name']) + write_file!([:node_config, name], json + "\n") if file_exists? :ca_cert, :ca_key generate_cert_for_node(manager.reload_node!(node)) end @@ -91,7 +93,7 @@ module LeapCli; module Commands node end - def seed_node_data(node, args) + def seed_node_data_from_cmd_line(node, args) args.each do |seed| key, value = seed.split(':', 2) value = format_seed_value(value) @@ -111,6 +113,23 @@ module LeapCli; module Commands end end + # + # load "new node template" information into the `node`, modifying `node`. + # values in the template will not override existing node values. + # + def seed_node_data_from_template(node) + return unless manager.respond_to?(:template) + node.inherit_from!(manager.template('common')) + [node['services']].flatten.each do |service| + if service + template = manager.template(service) + if template + node.inherit_from!(template) + end + end + end + end + def remove_node_files(node_name) (Leap::Platform.node_files + [:node_files_dir]).each do |path| remove_file! [path, node_name] @@ -142,6 +161,11 @@ module LeapCli; module Commands end def validate_ip_address(node) + if node['ip_address'] == "REQUIRED" + bail! do + log :error, "ip_address is not set. Specify with `leap node add NAME ip_address:ADDRESS`." + end + end IPAddr.new(node['ip_address']) rescue ArgumentError bail! do -- cgit v1.2.3