Class: Tenderloin::Commands
- Inherits:
-
Object
- Object
- Tenderloin::Commands
- Extended by:
- Util
- Defined in:
- lib/tenderloin/commands.rb
Overview
Contains all the command-line commands invoked by the binaries. Having them all in one location assists with documentation and also takes the commands out of some of the other classes.
Class Method Summary collapse
-
.box(argv) ⇒ Object
Manages the ‘tenderloin box` command, allowing the user to add and remove boxes.
-
.box_add(name, path) ⇒ Object
Adds a box to the local filesystem, given a URI.
-
.box_list ⇒ Object
Lists all added boxes.
-
.box_remove(name) ⇒ Object
Removes a box.
-
.destroy ⇒ Object
Tear down a tenderloin instance.
-
.halt ⇒ Object
Halts a running tenderloin instance.
-
.init ⇒ Object
Initializes a directory for use with tenderloin.
- .json_dump ⇒ Object
-
.provision ⇒ Object
Runs the provisioning script.
-
.reload ⇒ Object
Reload the environment.
-
.show_ip ⇒ Object
Gets the IP.
-
.ssh(command) ⇒ Object
SSH into the tenderloin instance.
-
.up(provision = nil) ⇒ Object
Bring up a tenderloin instance.
Methods included from Util
error_and_exit, included, logger, wrap_output
Class Method Details
.box(argv) ⇒ Object
Manages the ‘tenderloin box` command, allowing the user to add and remove boxes. This single command, given an array, determines which action to take and calls the respective action method (see box_add and box_remove)
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/tenderloin/commands.rb', line 96 def box(argv) Env.load! sub_commands = ["list", "add", "remove"] if !sub_commands.include?(argv[0]) error_and_exit(<<-error) Please specify a valid action to take on the boxes, either `add` or `remove`. Examples: tenderloin box add name uri tenderloin box remove name error end send("box_#{argv[0]}", *argv[1..-1]) end |
.box_add(name, path) ⇒ Object
Adds a box to the local filesystem, given a URI.
131 132 133 |
# File 'lib/tenderloin/commands.rb', line 131 def box_add(name, path) Box.add(name, path) end |
.box_list ⇒ Object
Lists all added boxes
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/tenderloin/commands.rb', line 115 def box_list boxes = Box.all.sort wrap_output do if !boxes.empty? puts "Installed Tenderloin Boxes:\n\n" boxes.each do |box| puts box end else puts "No Tenderloin Boxes Added!" end end end |
.box_remove(name) ⇒ Object
Removes a box.
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/tenderloin/commands.rb', line 136 def box_remove(name) box = Box.find(name) if box.nil? error_and_exit(<<-error) The box you're attempting to remove does not exist! error return # for tests end box.destroy end |
.destroy ⇒ Object
Tear down a tenderloin instance. This not only shuts down the instance (if its running), but also deletes it from the system, including the hard disks associated with it.
This command requires that an instance already be brought up with ‘tenderloin up`.
49 50 51 52 53 |
# File 'lib/tenderloin/commands.rb', line 49 def destroy Env.load! Env.require_persisted_vm Env.persisted_vm.destroy end |
.halt ⇒ Object
Halts a running tenderloin instance. This forcibly halts the instance; it is the equivalent of pulling the power on a machine. The instance can be restarted again with up.
This command requires than an instance already be brought up with ‘tenderloin up`.
86 87 88 89 90 |
# File 'lib/tenderloin/commands.rb', line 86 def halt Env.load! Env.require_persisted_vm Env.persisted_vm.execute!(Actions::VM::Halt) end |
.init ⇒ Object
Initializes a directory for use with tenderloin. This command copies an initial ‘Tenderfile` into the current working directory so you can begin using tenderloin. The configuration file contains some documentation to get you started.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tenderloin/commands.rb', line 14 def init rootfile_path = File.join(Dir.pwd, $ROOTFILE_NAME) if File.exist?(rootfile_path) error_and_exit(<<-error) It looks like this directory is already setup for tenderloin! (A #{$ROOTFILE_NAME} already exists.) error end # Copy over the rootfile template into this directory FileUtils.cp(File.join(PROJECT_ROOT, "templates", $ROOTFILE_NAME), rootfile_path) end |
.json_dump ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/tenderloin/commands.rb', line 162 def json_dump # Bump log level, don't want other output Tenderloin::Logger.set_level Logger::ERROR Env.load! ret = {:config => Tenderloin.config.to_hash} if Env.persisted_vm ret[:vm] = Env.persisted_vm.fusion_vm.to_hash else ret[:vm] = {:running => false} end puts ret.to_json end |
.provision ⇒ Object
Runs the provisioning script
149 150 151 152 153 |
# File 'lib/tenderloin/commands.rb', line 149 def provision Env.load! Env.require_persisted_vm Env.persisted_vm.execute!(Actions::VM::Provision) end |
.reload ⇒ Object
Reload the environment. This is almost equivalent to the up command except that it doesn’t import the VM and do the initialize bootstrapping of the instance. Instead, it forces a shutdown (if its running) of the VM, updates the metadata (shared folders, forwarded ports), restarts the VM, and then reruns the provisioning if enabled.
60 61 62 63 64 |
# File 'lib/tenderloin/commands.rb', line 60 def reload Env.load! Env.require_persisted_vm Env.persisted_vm.execute!(Actions::VM::Reload) end |
.show_ip ⇒ Object
Gets the IP
156 157 158 159 160 |
# File 'lib/tenderloin/commands.rb', line 156 def show_ip Env.load! Env.require_persisted_vm puts Env.persisted_vm.fusion_vm.ip end |
.ssh(command) ⇒ Object
SSH into the tenderloin instance. This will setup an SSH connection into the tenderloin instance, replacing the running ruby process with the SSH connection.
This command requires that an instance already be brought up with ‘tenderloin up`.
Command: shell command to run on the remote host
74 75 76 77 78 |
# File 'lib/tenderloin/commands.rb', line 74 def ssh(command) Env.load! Env.require_persisted_vm SSH.connect Env.persisted_vm.fusion_vm.ip, command end |
.up(provision = nil) ⇒ Object
Bring up a tenderloin instance. This handles everything from importing the base VM, setting up shared folders, forwarded ports, etc to provisioning the instance with chef. up also starts the instance, running it in the background.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tenderloin/commands.rb', line 31 def up(provision = nil) Env.load! if Env.persisted_vm logger.info "VM already created. Starting VM if its not already running..." Env.persisted_vm.start else Env.require_box VM.execute!(Actions::VM::Up, provision) end end |