Sha256: 98766456a2cd22d5ebdff98c016ff50e99b825d11eb53ce1ee8988ede678ae57

Contents?: true

Size: 1.47 KB

Versions: 6

Compression:

Stored size: 1.47 KB

Contents

require "tempfile"

require_relative "../../../../lib/vagrant/util/template_renderer"

module VagrantPlugins
  module GuestSlackware
    module Cap
      class ConfigureNetworks
        include Vagrant::Util

        def self.configure_networks(machine, networks)
          comm = machine.communicate

          commands   = []
          interfaces = []

          comm.sudo("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |_, result|
            interfaces = result.split("\n")
          end

          # Remove any previous configuration
          commands << "sed -i'' -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/rc.d/rc.inet1.conf"

          networks.each.with_index do |network, i|
            network[:device] = interfaces[network[:interface]]

            entry = TemplateRenderer.render("guests/slackware/network_#{network[:type]}",
              i: i+1,
              options: network,
            )

            remote_path = "/tmp/vagrant-network-#{network[:device]}-#{Time.now}-#{i}"
            Tempfile.open("vagrant-slackware-configure-networks") do |f|
              f.binmode
              f.write(entry)
              f.fsync
              f.close
              comm.upload(f.path, remote_path)
            end

            commands << "cat '#{remote_path}' >> /etc/rc.d/rc.inet1.conf"
          end

          # Restart networking
          commands << "/etc/rc.d/rc.inet1"

          comm.sudo(commands.join("\n"))
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/guests/slackware/cap/configure_networks.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/guests/slackware/cap/configure_networks.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/guests/slackware/cap/configure_networks.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/guests/slackware/cap/configure_networks.rb
vagrant-unbundled-1.8.4.2 plugins/guests/slackware/cap/configure_networks.rb
vagrant-unbundled-1.8.4.1 plugins/guests/slackware/cap/configure_networks.rb