Sha256: 464465e63c478be04839a45fdb79bff9db9dc0c18d59231af5c85ec6d6264313
Contents?: true
Size: 1.59 KB
Versions: 1
Compression:
Stored size: 1.59 KB
Contents
module Clusterfuck::TestHelpers::CommandHelpers def machine(host_name) host_name = host_name.to_sym Clusterfuck::Cluster.all.each do |cluster| if machine = cluster[host_name] return machine end end end def run_command(host, cmd) cmd = "#{ssh_command(host)} -- #{cmd}" `#{cmd}` end def ssh_command(host) port = machine(host).ssh_port cmd = <<-CMD ssh vagrant@localhost -p #{port} -i ~/.vagrant.d/insecure_private_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o IdentitiesOnly=yes -o LogLevel=quiet CMD cmd.gsub("\n", ' ').squeeze(" ").strip end def iptables_drop_port(host, port, direction, action: "-D", device: "eth1") @hosts_with_iptables ||= [] @hosts_with_iptables << host ['tcp', 'udp'].each do |proto| run_command(host, "sudo iptables #{action} #{direction} -p #{proto} --dport #{port} -o #{device} -j DROP > /dev/null" ) end end def flush_iptables(host) run_command(host, "sudo iptables -F") end def block_traffic(host, port, direction = "INPUT") iptables_drop_port(host, port, direction, action: "-A") end def unblock_traffic(host, port, direction = "INPUT") iptables_drop_port(host, port, direction) end def sv(host, cmd, service) if cmd == 'stop' @hosts_with_stopped_services ||= {} @hosts_with_stopped_services[host] ||= [] @hosts_with_stopped_services[host] << service end run_command(host, "sudo sv #{cmd} #{service}") end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
vagrant-clusterfuck-0.0.6 | lib/clusterfuck/test_helpers/command_helpers.rb |