Tabs must die.

This commit is contained in:
Brian Johnson 2013-08-05 18:07:45 -07:00
parent 3611ff39f4
commit e5ce19ff11
3 changed files with 92 additions and 92 deletions

View File

@ -3,55 +3,55 @@ require "tempfile"
require "vagrant/util/template_renderer" require "vagrant/util/template_renderer"
module VagrantPlugins module VagrantPlugins
module GuestDarwin module GuestDarwin
module Cap module Cap
class ConfigureNetworks class ConfigureNetworks
include Vagrant::Util include Vagrant::Util
def self.configure_networks(machine, networks) def self.configure_networks(machine, networks)
# Slightly different than other plugins, using the template to build commands # Slightly different than other plugins, using the template to build commands
# rather than templating the files. # rather than templating the files.
machine.communicate.sudo("networksetup -detectnewhardware") machine.communicate.sudo("networksetup -detectnewhardware")
machine.communicate.sudo("networksetup -listnetworkserviceorder > /tmp/vagrant.interfaces") machine.communicate.sudo("networksetup -listnetworkserviceorder > /tmp/vagrant.interfaces")
tmpints = File.join(Dir.tmpdir, File.basename("#{machine.id}.interfaces")) tmpints = File.join(Dir.tmpdir, File.basename("#{machine.id}.interfaces"))
machine.communicate.download("/tmp/vagrant.interfaces",tmpints) machine.communicate.download("/tmp/vagrant.interfaces",tmpints)
devlist = [] devlist = []
ints = IO.read(tmpints) ints = IO.read(tmpints)
ints.split(/\n\n/m).each do |i| ints.split(/\n\n/m).each do |i|
if i.match(/Hardware/) and not i.match(/Ethernet/).nil? if i.match(/Hardware/) and not i.match(/Ethernet/).nil?
devmap = {} devmap = {}
# Ethernet, should be 2 lines, # Ethernet, should be 2 lines,
# (3) Thunderbolt Ethernet # (3) Thunderbolt Ethernet
# (Hardware Port: Thunderbolt Ethernet, Device: en1) # (Hardware Port: Thunderbolt Ethernet, Device: en1)
# multiline, should match "Thunderbolt Ethernet", "en1" # multiline, should match "Thunderbolt Ethernet", "en1"
devicearry = i.match(/\([0-9]+\) (.+)\n.*Device: (.+)\)/m) devicearry = i.match(/\([0-9]+\) (.+)\n.*Device: (.+)\)/m)
devmap[:interface] = devicearry[2] devmap[:interface] = devicearry[2]
devmap[:service] = devicearry[1] devmap[:service] = devicearry[1]
devlist << devmap devlist << devmap
end end
end end
puts devlist puts devlist
networks.each do |network| networks.each do |network|
intnum = network[:interface] intnum = network[:interface]
puts network[:interface] puts network[:interface]
puts network[:type] puts network[:type]
if network[:type].to_sym == :static if network[:type].to_sym == :static
# network seems 1 indexed - skip NAT interface (en0) also en1 because it seems to not *really* exist on virtualbox? # network seems 1 indexed - skip NAT interface (en0) also en1 because it seems to not *really* exist on virtualbox?
command = "networksetup -setmanual \"#{devlist[intnum+1][:service]}\" #{network[:ip]} #{network[:netmask]}" command = "networksetup -setmanual \"#{devlist[intnum+1][:service]}\" #{network[:ip]} #{network[:netmask]}"
elsif network[:type].to_sym == :dhcp elsif network[:type].to_sym == :dhcp
command = "networksetup -setdhcp \"#{devlist[intnum+1][:service]}\"" command = "networksetup -setdhcp \"#{devlist[intnum+1][:service]}\""
end end
machine.communicate.sudo(command) machine.communicate.sudo(command)
end end
end end
end end
end end
end end
end end

View File

@ -1,25 +1,25 @@
require "vagrant/util/retryable" require "vagrant/util/retryable"
module VagrantPlugins module VagrantPlugins
module GuestDarwin module GuestDarwin
module Cap module Cap
class MountNFSFolder class MountNFSFolder
extend Vagrant::Util::Retryable extend Vagrant::Util::Retryable
def self.mount_nfs_folder(machine, ip, folders) def self.mount_nfs_folder(machine, ip, folders)
folders.each do |name, opts| folders.each do |name, opts|
# Expand the guest path so we can handle things like "~/vagrant" # Expand the guest path so we can handle things like "~/vagrant"
expanded_guest_path = machine.guest.capability( expanded_guest_path = machine.guest.capability(
:shell_expand_guest_path, opts[:guestpath]) :shell_expand_guest_path, opts[:guestpath])
machine.communicate.sudo("if [ ! -d #{expanded_guest_path} ]; then mkdir -p #{expanded_guest_path};fi") machine.communicate.sudo("if [ ! -d #{expanded_guest_path} ]; then mkdir -p #{expanded_guest_path};fi")
mount_command = "mount -t nfs '#{ip}:#{opts[:hostpath]}' '#{expanded_guest_path}'" mount_command = "mount -t nfs '#{ip}:#{opts[:hostpath]}' '#{expanded_guest_path}'"
retryable(:on => Vagrant::Errors::DarwinNFSMountFailed, :tries => 10, :sleep => 5) do retryable(:on => Vagrant::Errors::DarwinNFSMountFailed, :tries => 10, :sleep => 5) do
machine.communicate.sudo(mount_command, :error_class => Vagrant::Errors::DarwinNFSMountFailed) machine.communicate.sudo(mount_command, :error_class => Vagrant::Errors::DarwinNFSMountFailed)
end end
end end
end end
end end
end end
end end
end end

View File

@ -1,40 +1,40 @@
require "vagrant" require "vagrant"
module VagrantPlugins module VagrantPlugins
module GuestDarwin module GuestDarwin
class Plugin < Vagrant.plugin("2") class Plugin < Vagrant.plugin("2")
name "Darwin guest" name "Darwin guest"
description "Darwin guest support." description "Darwin guest support."
guest("darwin") do guest("darwin") do
require File.expand_path("../guest", __FILE__) require File.expand_path("../guest", __FILE__)
Guest Guest
end end
guest_capability("darwin", "change_host_name") do guest_capability("darwin", "change_host_name") do
require_relative "cap/change_host_name" require_relative "cap/change_host_name"
Cap::ChangeHostName Cap::ChangeHostName
end end
guest_capability("darwin", "configure_networks") do guest_capability("darwin", "configure_networks") do
require_relative "cap/configure_networks" require_relative "cap/configure_networks"
Cap::ConfigureNetworks Cap::ConfigureNetworks
end end
guest_capability("darwin", "halt") do guest_capability("darwin", "halt") do
require_relative "cap/halt" require_relative "cap/halt"
Cap::Halt Cap::Halt
end end
guest_capability("darwin", "mount_nfs_folder") do guest_capability("darwin", "mount_nfs_folder") do
require_relative "cap/mount_nfs_folder" require_relative "cap/mount_nfs_folder"
Cap::MountNFSFolder Cap::MountNFSFolder
end end
guest_capability("darwin", "shell_expand_guest_path") do guest_capability("darwin", "shell_expand_guest_path") do
require_relative "cap/shell_expand_guest_path" require_relative "cap/shell_expand_guest_path"
Cap::ShellExpandGuestPath Cap::ShellExpandGuestPath
end end
end end
end end
end end