From cdc037ed47e6d2a2816601e55e3966c4240e432a Mon Sep 17 00:00:00 2001 From: elijah Date: Sat, 5 Apr 2014 13:58:37 -0700 Subject: more graceful handling of error for `leap node add` (closes https://leap.se/code/issues/3725) --- lib/leap_cli/commands/node.rb | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 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 5f5c4b8..304d86b 100644 --- a/lib/leap_cli/commands/node.rb +++ b/lib/leap_cli/commands/node.rb @@ -32,12 +32,14 @@ module LeapCli; module Commands end seed_node_data(node, args[1..-1]) validate_ip_address(node) - - # write the file - write_file! [:node_config, name], node.dump_json + "\n" - node['name'] = name - if file_exists? :ca_cert, :ca_key - generate_cert_for_node(manager.reload_node(node)) + begin + write_file! [:node_config, name], node.dump_json + "\n" + node['name'] = name + if file_exists? :ca_cert, :ca_key + generate_cert_for_node(manager.reload_node!(node)) + end + rescue LeapCli::ConfigError => exc + remove_node_files(name) end end end @@ -102,9 +104,7 @@ module LeapCli; module Commands node.command :rm do |rm| rm.action do |global_options,options,args| node = get_node_from_args(args) - (Leap::Platform.node_files + [:node_files_dir]).each do |path| - remove_file! [path, node.name] - end + remove_node_files(node.name) if node.vagrant? vagrant_command("destroy --force", [node.name]) end @@ -236,8 +236,14 @@ module LeapCli; module Commands end end + def remove_node_files(node_name) + (Leap::Platform.node_files + [:node_files_dir]).each do |path| + remove_file! [path, node_name] + end + end + # - # conversations: + # conversions: # # "x,y,z" => ["x","y","z"] # -- cgit v1.2.3