Sha256: 6ef92ffc675b0d1e0cbe3f71e6b2e7b46b177978d1ed1c901b862ac18c3071b6

Contents?: true

Size: 1.83 KB

Versions: 21

Compression:

Stored size: 1.83 KB

Contents

require "tempfile"

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

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

        def self.configure_networks(machine, networks)
          networks.each do |network|
            entry = TemplateRenderer.render("guests/openbsd/network_#{network[:type]}",
                                            options: network)

            Tempfile.open("vagrant-openbsd-configure-networks") do |f|
              f.binmode
              f.write(entry)
              f.fsync
              f.close
              machine.communicate.upload(f.path, "/tmp/vagrant-network-entry")
            end

            # Determine the interface prefix...
            command = "ifconfig -a | grep -o ^[0-9a-z]*"
            result = ""
            ifname = ""
            machine.communicate.execute(command) do |type, data|
              result << data if type == :stdout
              if result.split(/\n/).any?{|i| i.match(/vio*/)}
                ifname = "vio#{network[:interface]}"
              else
                ifname = "em#{network[:interface]}"
              end
            end

            machine.communicate.sudo("mv /tmp/vagrant-network-entry /etc/hostname.#{ifname}")

            # remove old configurations
            machine.communicate.sudo("sudo ifconfig #{ifname} inet delete", { error_check: false })
            machine.communicate.sudo("pkill -f 'dhclient: #{ifname}'", { error_check: false })

            if network[:type].to_sym == :static
              machine.communicate.sudo("ifconfig #{ifname} inet #{network[:ip]} netmask #{network[:netmask]}")
            elsif network[:type].to_sym == :dhcp
              machine.communicate.sudo("dhclient #{ifname}")
            end
          end
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 3 rubygems

Version Path
vagrant-unbundled-2.0.2.0 plugins/guests/openbsd/cap/configure_networks.rb
vagrant-unbundled-2.0.1.0 plugins/guests/openbsd/cap/configure_networks.rb
vagrant-aws-mkubenka-0.7.2.pre.22 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-f3fdbf414272/plugins/guests/openbsd/cap/configure_networks.rb
vagrant-aws-mkubenka-0.7.2.pre.16 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-1ee58c40e3f5/plugins/guests/openbsd/cap/configure_networks.rb
vagrant-unbundled-2.0.0.1 plugins/guests/openbsd/cap/configure_networks.rb
vagrant-unbundled-1.9.8.1 plugins/guests/openbsd/cap/configure_networks.rb
vagrant-unbundled-1.9.7.1 plugins/guests/openbsd/cap/configure_networks.rb
vagrant-aws-mkubenka-0.7.2.pre.14 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/guests/openbsd/cap/configure_networks.rb
vagrant-aws-mkubenka-0.7.2.pre.11 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/guests/openbsd/cap/configure_networks.rb
vagrant-aws-mkubenka-0.7.2.pre.10 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/guests/openbsd/cap/configure_networks.rb
vagrant-aws-mkubenka-0.7.2.pre.9 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/guests/openbsd/cap/configure_networks.rb
vagrant-unbundled-1.9.5.1 plugins/guests/openbsd/cap/configure_networks.rb
vagrant-unbundled-1.9.1.1 plugins/guests/openbsd/cap/configure_networks.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/guests/openbsd/cap/configure_networks.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/guests/openbsd/cap/configure_networks.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/guests/openbsd/cap/configure_networks.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/guests/openbsd/cap/configure_networks.rb
vagrant-unbundled-1.8.5.2 plugins/guests/openbsd/cap/configure_networks.rb
vagrant-unbundled-1.8.5.1 plugins/guests/openbsd/cap/configure_networks.rb
vagrant-unbundled-1.8.4.2 plugins/guests/openbsd/cap/configure_networks.rb