Sha256: eeb840a9bbc1c51227c5c36d8953b8b3ad3a8f2345c0e9a8a094029d931c431a

Contents?: true

Size: 1.83 KB

Versions: 6

Compression:

Stored size: 1.83 KB

Contents

require "tempfile"

require "vagrant/util/template_renderer"

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

        def self.configure_networks(machine, networks)
          # Slightly different than other plugins, using the template to build commands 
          # rather than templating the files.

          machine.communicate.sudo("networksetup -detectnewhardware")
          machine.communicate.sudo("networksetup -listnetworkserviceorder > /tmp/vagrant.interfaces")
          tmpints = File.join(Dir.tmpdir, File.basename("#{machine.id}.interfaces"))
          machine.communicate.download("/tmp/vagrant.interfaces",tmpints)

          devlist = []
          ints = IO.read(tmpints)
          ints.split(/\n\n/m).each do |i|
            if i.match(/Hardware/) and not i.match(/Ethernet/).nil?
              devmap = {}
              # Ethernet, should be 2 lines, 
              # (3) Thunderbolt Ethernet
              # (Hardware Port: Thunderbolt Ethernet, Device: en1)

              # multiline, should match "Thunderbolt Ethernet", "en1"
              devicearry = i.match(/\([0-9]+\) (.+)\n.*Device: (.+)\)/m)
              devmap[:interface] = devicearry[2]
              devmap[:service] = devicearry[1]
              devlist << devmap
            end
          end
          File.delete(tmpints)

          networks.each do |network|
            service_name = devlist[network[:interface]][:service]
            if network[:type].to_sym == :static
              command = "networksetup -setmanual \"#{service_name}\" #{network[:ip]} #{network[:netmask]}"
            elsif network[:type].to_sym == :dhcp
              command = "networksetup -setdhcp \"#{service_name}\""
            end

            machine.communicate.sudo(command)
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
tamtam-vagrant-reload-1.1.3 vendor/cache/vagrant-0ac2a8738841/plugins/guests/darwin/cap/configure_networks.rb
tamtam-vagrant-reload-1.1.2 vendor/cache/vagrant-0ac2a8738841/plugins/guests/darwin/cap/configure_networks.rb
tamtam-vagrant-reload-1.1.1 vendor/cache/vagrant-0ac2a8738841/plugins/guests/darwin/cap/configure_networks.rb
tamtam-vagrant-reload-1.1 vendor/cache/vagrant-0ac2a8738841/plugins/guests/darwin/cap/configure_networks.rb
tnargav-1.3.6 plugins/guests/darwin/cap/configure_networks.rb
tnargav-1.3.3 plugins/guests/darwin/cap/configure_networks.rb