Sha256: cf8870679051bcc95be9065cf899fff1707136188c94a0c6bf7f0d4e35636e65

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

module Clusterfuck
  module TestHelper
    SSHCommandFailedError = Class.new(StandardError)

    def self.included(base)
      require "./cluster"
    end

    # We do not check exit status, don't want to control people.
    def ssh_command(host, command, cluster: nil)
      `ssh -i .vagrant/machines/#{host}/virtualbox/private_key vagrant@127.0.0.1 -p #{host(host, cluster: cluster).ssh_port} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o IdentitiesOnly=yes -o LogLevel=fatal "#{command}"`
    end

    def host(name, cluster: nil)
      cluster(cluster).nodes.find { |node| node.name == name }
    end

    def ip_to_host(ip, cluster: nil)
      cluster(cluster).nodes.find { |host|
        host.subnets.find { |subnet|
          subnet == ip
        }
      }
    end

    # TODO add iptables(1) and nc(1) wrappers to cause ~chaos~
    private
    def cluster(name)
      if name
        Clusterfuck::Cluster[name]
      else
        Clusterfuck::Cluster.all.first
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-clusterfuck-0.0.1 lib/clusterfuck/test_helper.rb