diff options
author | elijah <elijah@riseup.net> | 2016-07-21 00:55:12 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2016-08-23 13:37:34 -0700 |
commit | 205b61dfe721e6d88fc06b050a0497eeb35f4e02 (patch) | |
tree | 518b5799f56d9e224d7ca2d85b3d29ef0c01b3c6 /lib/leap_cli/commands/node.rb | |
parent | 6fab56fb40256fb2e541ee3ad61490f03254d38e (diff) |
added 'leap vm' command
Diffstat (limited to 'lib/leap_cli/commands/node.rb')
-rw-r--r-- | lib/leap_cli/commands/node.rb | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/lib/leap_cli/commands/node.rb b/lib/leap_cli/commands/node.rb index 15575d4f..60540de9 100644 --- a/lib/leap_cli/commands/node.rb +++ b/lib/leap_cli/commands/node.rb @@ -19,9 +19,14 @@ module LeapCli; module Commands "Separate multiple values for a single property with a comma, like so: `leap node add mynode services:webapp,dns`"].join("\n\n") node.arg_name 'NAME [SEED]' # , :optional => false, :multiple => false node.command :add do |add| - add.switch :local, :desc => 'Make a local testing node (by automatically assigning the next available local IP address). Local nodes are run as virtual machines on your computer.', :negatable => false + add.switch :local, :desc => 'Make a local testing node (by assigning the next available local IP address). Local nodes are run as virtual machines on your computer.', :negatable => false + add.switch :vm, :desc => 'Make a remote virtual machine for this node. Requires a valid cloud.json configuration.', :negatable => false add.action do |global_options,options,args| - add_node(global_options, options, args) + if options[:vm] + do_vm_add(global_options, options, args) + else + do_node_add(global_options, options, args) + end end end @@ -29,7 +34,7 @@ module LeapCli; module Commands node.arg_name 'OLD_NAME NEW_NAME' node.command :mv do |mv| mv.action do |global_options,options,args| - move_node(global_options, options, args) + do_node_move(global_options, options, args) end end @@ -37,7 +42,7 @@ module LeapCli; module Commands node.arg_name 'NAME' #:optional => false #, :multiple => false node.command :rm do |rm| rm.action do |global_options,options,args| - rm_node(global_options, options, args) + do_node_rm(global_options, options, args) end end end @@ -58,7 +63,10 @@ module LeapCli; module Commands protected - def add_node(global, options, args) + # + # additionally called by `leap vm add` + # + def do_node_add(global, options, args) name = args.first unless global[:force] assert_files_missing! [:node_config, name] @@ -81,7 +89,7 @@ module LeapCli; module Commands private - def move_node(global, options, args) + def do_node_move(global, options, args) node = get_node_from_args(args, include_disabled: true) new_name = args.last Config::Node.validate_name!(new_name, node.vagrant?) @@ -91,14 +99,30 @@ module LeapCli; module Commands end remove_directory! [:node_files_dir, node.name] rename_node_facts(node.name, new_name) + if node.vm_id? + node['name'] = new_name + bind_server_to_node(node.vm.id, node, options) + end end - def rm_node(global, options, args) + def do_node_rm(global, options, args) node = get_node_from_args(args, include_disabled: true) - node.remove_files - if node.vagrant? + if node.vm? + if !node.vm_id? + log :warning, "The node #{node.name} is missing a 'vm.id' property. "+ + "You may have a virtual machine instance that is left "+ + "running. Check `leap vm status`" + else + msg = "The node #{node.name} appears to be associated with a virtual machine. " + + "Do you want to also destroy this virtual machine? " + if global[:yes] || agree(msg) + do_vm_rm(global, options, args) + end + end + elsif node.vagrant? vagrant_command("destroy --force", [node.name]) end + node.remove_files remove_node_facts(node.name) end |