Sha256: 00d0068eacae416407e8766a72b3f32d23733129de69a07883fb0976d3e3a61f

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

require "tempfile"

require "vagrant/util/template_renderer"

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

        def self.configure_networks(machine, networks)

          # setup a new rc.conf file
          newrcconf = "/tmp/rc.conf.vagrant_configurenetworks"
          machine.communicate.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/rc.conf > #{newrcconf}")

          networks.each do |network|

            # create an interface configuration file fragment
            entry = TemplateRenderer.render("guests/netbsd/network_#{network[:type]}",
                                            options: network)

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

            # upload it and append it to the new rc.conf file
            machine.communicate.upload(temp.path, "/tmp/vagrant-network-entry")
            machine.communicate.sudo("cat /tmp/vagrant-network-entry >> #{newrcconf}")
            machine.communicate.sudo("rm /tmp/vagrant-network-entry")

            ifname = "wm#{network[:interface]}"
            # remove old configuration
            machine.communicate.sudo("/sbin/dhcpcd -x #{ifname}", { error_check: false })
            machine.communicate.sudo("/sbin/ifconfig #{ifname} inet delete", { error_check: false })

            # live new configuration
            if network[:type].to_sym == :static
              machine.communicate.sudo("/sbin/ifconfig #{ifname} media autoselect up;/sbin/ifconfig #{ifname} inet #{network[:ip]} netmask #{network[:netmask]}")
            elsif network[:type].to_sym == :dhcp
              machine.communicate.sudo("/sbin/dhcpcd -n -q #{ifname}")
            end
          end

          # install new rc.conf
          machine.communicate.sudo("install -c -o 0 -g 0 -m 644 #{newrcconf} /etc/rc.conf")

        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/bundler/gems/vagrant-1e28f1ac31e7/plugins/guests/netbsd/cap/configure_networks.rb