Sha256: 70c8223eb82ff3e6114b6a2975cca7802472370791178531a1d7145ecc3fafc8

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

require 'ipaddr'
require 'tempfile'

module VagrantPlugins
  module GuestVyOS
    module Cap
      class ConfigureNetworks

        def self.configure_networks(machine, networks)
          machine.communicate.tap do |comm|

            commands = <<-EOS
source /opt/vyatta/etc/functions/script-template
            EOS

            networks.each do |network|
              commands << "delete interfaces ethernet eth#{network[:interface]}\n"
              if network[:type].to_sym == :static
                subnet = IPAddr.new(network[:netmask]).to_i.to_s(2).count("1")
                commands << "set interfaces ethernet eth#{network[:interface]} address #{network[:ip]}/#{subnet}\n"
              elsif network[:type].to_sym == :dhcp
                commands << "set interfaces ethernet eth#{network[:interface]} address dhcp\n"
              end
            end

            commands << <<-EOS
 commit
 save
            EOS

            temp = Tempfile.new("vagrant")
            temp.binmode
            temp.write(commands)
            temp.close

            comm.upload(temp.path, "/tmp/vagrant-configure-network")
            comm.execute("bash /tmp/vagrant-configure-network")
            comm.execute("rm -f /tmp/vagrant-configure-network")
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-vyos-1.1.1 lib/vagrant-vyos/cap/configure_networks.rb
vagrant-vyos-1.1.0 lib/vagrant-vyos/cap/configure_networks.rb
vagrant-vyos-1.0.0 lib/vagrant-vyos/cap/configure_networks.rb