Sha256: f28c54a17428e82fd6d4b8b68a9c09a540b8f483b68fad9d5d1cd2ae9b37b132

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

require 'ipaddr'
require 'tempfile'

module VagrantPlugins
  module GuestVyatta
    module Cap
      class ConfigureNetworks

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

            commands = <<-EOS
WRAPPER=/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper
. /etc/bash_completion
$WRAPPER begin
            EOS

            networks.each do |network|
              commands << "$WRAPPER 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 << "$WRAPPER set interfaces ethernet eth#{network[:interface]} address #{network[:ip]}/#{subnet}\n"
              elsif network[:type].to_sym == :dhcp
                commands << "$WRAPPER set interfaces ethernet eth#{network[:interface]} address dhcp\n"
              end
            end

            commands << <<-EOS
$WRAPPER commit
$WRAPPER save
$WRAPPER end
            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-vyatta-0.0.5 lib/vagrant-vyatta/cap/configure_networks.rb
vagrant-vyatta-0.0.4 lib/vagrant-vyatta/cap/configure_networks.rb
vagrant-vyatta-0.0.3 lib/vagrant-vyatta/cap/configure_networks.rb