Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified Vagrant source under MIT license
- Loading branch information
Karl Isenberg
committed
Dec 13, 2016
1 parent
0130f00
commit 101238d
Showing
6 changed files
with
168 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License | ||
|
||
Copyright (c) 2016 Mesosphere | ||
Copyright (c) 2010-2016 Mitchell Hashimoto | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Monkey patch for network interface detection bug in Vagrant 1.9.1 | ||
# https://github.com/mitchellh/vagrant/issues/8115 | ||
# | ||
# This file is a Derivative Work of Vagrant source, covered by the MIT license. | ||
|
||
require Vagrant.source_root.join('plugins/guests/redhat/cap/change_host_name.rb') | ||
|
||
module VagrantPlugins | ||
module GuestRedHat | ||
module Cap | ||
class ChangeHostName | ||
def self.change_host_name(machine, name) | ||
comm = machine.communicate | ||
|
||
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false) | ||
basename = name.split('.', 2)[0] | ||
comm.sudo <<-EOH.gsub(/^ {14}/, '') | ||
# Update sysconfig | ||
sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network | ||
# Update DNS | ||
sed -i 's/\\(DHCP_HOSTNAME=\\).*/\\1\"#{basename}\"/' /etc/sysconfig/network-scripts/ifcfg-* | ||
# Set the hostname - use hostnamectl if available | ||
echo '#{name}' > /etc/hostname | ||
if command -v hostnamectl; then | ||
hostnamectl set-hostname --static '#{name}' | ||
hostnamectl set-hostname --transient '#{name}' | ||
else | ||
hostname -F /etc/hostname | ||
fi | ||
# Remove comments and blank lines from /etc/hosts | ||
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts | ||
# Prepend ourselves to /etc/hosts | ||
grep -w '#{name}' /etc/hosts || { | ||
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts | ||
} | ||
# Restart network | ||
service network restart | ||
EOH | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
Vagrant::UI::Colored.new.info 'Vagrant Patch Loaded: GuestRedHat change_host_name (1.9.1)' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Monkey patch for network interface detection bug in Vagrant 1.9.1 | ||
# https://github.com/mitchellh/vagrant/issues/8115 | ||
# | ||
# This file is a Derivative Work of Vagrant source, covered by the MIT license. | ||
|
||
require Vagrant.source_root.join('plugins/guests/redhat/cap/configure_networks.rb') | ||
|
||
module VagrantPlugins | ||
module GuestRedHat | ||
module Cap | ||
class ConfigureNetworks | ||
include Vagrant::Util | ||
|
||
def self.configure_networks(machine, networks) | ||
comm = machine.communicate | ||
|
||
network_scripts_dir = machine.guest.capability(:network_scripts_dir) | ||
|
||
commands = [] | ||
interfaces = machine.guest.capability(:network_interfaces) | ||
|
||
networks.each.with_index do |network, i| | ||
network[:device] = interfaces[network[:interface]] | ||
|
||
# Render a new configuration | ||
entry = TemplateRenderer.render("guests/redhat/network_#{network[:type]}", | ||
options: network, | ||
) | ||
|
||
# Upload the new configuration | ||
remote_path = "/tmp/vagrant-network-entry-#{network[:device]}-#{Time.now.to_i}-#{i}" | ||
Tempfile.open("vagrant-redhat-configure-networks") do |f| | ||
f.binmode | ||
f.write(entry) | ||
f.fsync | ||
f.close | ||
machine.communicate.upload(f.path, remote_path) | ||
end | ||
|
||
# Add the new interface and bring it back up | ||
final_path = "#{network_scripts_dir}/ifcfg-#{network[:device]}" | ||
commands << <<-EOH.gsub(/^ {14}/, '') | ||
# Down the interface before munging the config file. This might | ||
# fail if the interface is not actually set up yet so ignore | ||
# errors. | ||
/sbin/ifdown '#{network[:device]}' | ||
# Move new config into place | ||
mv -f '#{remote_path}' '#{final_path}' | ||
# attempt to force network manager to reload configurations | ||
nmcli c reload || true | ||
EOH | ||
end | ||
|
||
commands << <<-EOH.gsub(/^ {12}/, '') | ||
# Restart network | ||
service network restart | ||
EOH | ||
|
||
comm.sudo(commands.join("\n")) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
Vagrant::UI::Colored.new.info 'Vagrant Patch Loaded: GuestRedHat configure_networks (1.9.1)' |