Class: Lbspec::Util
- Inherits:
-
Object
- Object
- Lbspec::Util
- Defined in:
- lib/lbspec/util.rb
Overview
Lbspec::Util provides some utilities
Class Method Summary collapse
- .add_string(target, addition) ⇒ Object
- .create_prove ⇒ Object
- .exec_command(command, node = nil) ⇒ Object
- .split_addr_port_path(addr_port_path) ⇒ Object
Class Method Details
.add_string(target, addition) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/lbspec/util.rb', line 6 def self.add_string(target, addition) if target.nil? target = addition else target << addition end end |
.create_prove ⇒ Object
14 15 16 17 |
# File 'lib/lbspec/util.rb', line 14 def self.create_prove t = Time.now t.to_i.to_s + t.nsec.to_s end |
.exec_command(command, node = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lbspec/util.rb', line 27 def self.exec_command(command, node = nil) output = command + "\n" if node # if there is no user for the node in .~/ssh/ssh_config # use current user name for login user = Net::SSH::Config.for(node)[:user] user = `whoami`.chomp unless user Net::SSH.start(node, user, config: true) do |ssh| output << ssh.exec!(command).to_s end else output << `#{command}`.to_s end end |
.split_addr_port_path(addr_port_path) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/lbspec/util.rb', line 19 def self.split_addr_port_path(addr_port_path) splits = addr_port_path.split(/[:\/]/) addr = splits[0] port = (/\d+/ =~ splits[1]) ? splits[1].to_i : nil path = (/\d+/ =~ splits[1]) ? '/' + splits[2].to_s : '/' + splits[1].to_s [addr, port, path] end |