Class: App::VM
- Inherits:
-
Object
- Object
- App::VM
- Defined in:
- lib/core/vm.rb
Class Method Summary collapse
-
.command(commands, verbose = true) ⇒ Object
Runs a series of commands on the VM.
- .run_on_vm(script_name, args = []) ⇒ Object
Class Method Details
.command(commands, verbose = true) ⇒ Object
Runs a series of commands on the VM.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/core/vm.rb', line 32 def self.command(commands, verbose = true) unless commands.is_a?(Array) commands = [commands] end if commands.any? commands.each do |command| if verbose puts "\x1B[48;5;136m Executing \x1B[0m \x1B[0m\xe2\x86\x92\x1B[0m #{App::Terminal::format_command("#{command}")}" end system("sshpass -p#{App::Config.param(ConfigUnique::VM_USER)} ssh #{App::Config.param(ConfigUnique::VM_USER)}@#{App::Config.param(ConfigUnique::VM_IP)} -t \"#{command}\"") end end end |
.run_on_vm(script_name, args = []) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/core/vm.rb', line 5 def self.run_on_vm(script_name, args = []) unless args.is_a? Array raise RuntimeError, 'args (to run_on_vm) must be an Array' end script_name_vm = "#{App::Config.param(ConfigUnique::VM_USER)}-#{script_name}" scripts = get_all_scripts.keys unless scripts.include?(script_name) App::Terminal::error("Script doesn't exist: #{App::Terminal::format_invalid(script_name)}", nil, true) end commands = [ "scp #{App::Enum::get_base_path}/vm-scripts/#{script_name} #{App::Config.param(ConfigUnique::VM_USER)}@#{App::Config.param(ConfigUnique::VM_IP)}:/tmp/#{script_name_vm}", ] App::Terminal::command(commands, nil, false, false) command("chmod 0755 /tmp/#{script_name_vm}") command("/tmp/#{script_name_vm} #{args.join(' ')}") command("rm /tmp/#{script_name_vm}") end |