Sha256: 15ae80f1515b51f1b7496bf87dccdccb89d098892af76809b3163939528b4991

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 KB

Contents

module Clusterfuck
  class QuaggaBGPRouter < BGPPeer
    def build(config)
      super(config)

      config.vm.define(name) do |box|
        box.vm.provision :shell, inline: <<-EOS
  mkdir -p /tmp/quagga
  chown -R vagrant /tmp/quagga

  apt-get update
  apt-get -y install quagga
  EOS

        # TODO should be configured from BGP module if enabled
        # TODO have to move to /tmp/ first and then later to /etc/quagga because
        # Vagrant doens't copy as root.
        box.vm.provision :file,
          source: tmp_daemons_config,
          destination: "/tmp/quagga/daemons"

        box.vm.provision :file,
          source: tmp_zebra_config,
          destination: "/tmp/quagga/zebra.conf"

        box.vm.provision :file,
          source: tmp_bgp_config,
          destination: "/tmp/quagga/bgpd.conf"

        box.vm.provision :shell, inline: <<-EOS
  echo net.ipv4.ip_forward=1 > /etc/sysctl.d/60-clusterfuck.conf
  sysctl -p /etc/sysctl.d/60-clusterfuck.conf

  mv /tmp/quagga/* /etc/quagga
  chown quagga.quagga /etc/quagga/*.conf
  chmod 640 /etc/quagga/*.conf

  service quagga restart
EOS
      end
    end

    private
    # TODO clean up these messy functions
    def tmp_zebra_config
      File.expand_path("../../../templates/quagga.zebra.conf", __FILE__)
    end

    def tmp_daemons_config
      File.expand_path("../../../templates/quagga.daemons", __FILE__)
    end

    def tmp_bgp_config
      temp = Tempfile.new("routes")
      ObjectSpace.undefine_finalizer(temp) # finalizer removes it, nthx
      temp.write(bgp_config)
      temp.flush
      temp.path
    end

    def bgp_config
      path = File.expand_path("../../../templates/quagga.bgpd.conf.erb", __FILE__)
      ERB.new(File.read(path)).result(binding)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-clusterfuck-0.0.3 lib/clusterfuck/quagga_bgp_router.rb