summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/leap_cli/commands/list.rb2
-rw-r--r--lib/leap_cli/commands/node.rb30
2 files changed, 28 insertions, 4 deletions
diff --git a/lib/leap_cli/commands/list.rb b/lib/leap_cli/commands/list.rb
index c562b59b..aa425432 100644
--- a/lib/leap_cli/commands/list.rb
+++ b/lib/leap_cli/commands/list.rb
@@ -52,7 +52,7 @@ module LeapCli; module Commands
elsif prop_value == ""
"empty"
elsif prop_value.is_a? LeapCli::Config::Object
- node[prop].dump_json(:compact) # TODO: add option of getting pre-evaluation values.
+ node[prop].dump_json(:format => :compact) # TODO: add option of getting pre-evaluation values.
else
prop_value.to_s
end
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