mirror of
https://github.com/hashicorp/vagrant.git
synced 2026-05-28 04:36:05 -04:00
Merge 3e345ba272 into f9e2630d69
This commit is contained in:
commit
b12b3d1f14
5 changed files with 90 additions and 1 deletions
|
|
@ -4,15 +4,34 @@
|
|||
require "tempfile"
|
||||
|
||||
require_relative "../../../../lib/vagrant/util/template_renderer"
|
||||
require_relative "../../../../lib/vagrant/util/guest_inspection"
|
||||
require_relative "../../../../lib/vagrant/util/guest_networks"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestSUSE
|
||||
module Cap
|
||||
class ConfigureNetworks
|
||||
extend Vagrant::Util::Retryable
|
||||
extend Vagrant::Util::GuestInspection::Linux
|
||||
extend Vagrant::Util::GuestNetworks::Linux
|
||||
include Vagrant::Util
|
||||
|
||||
def self.configure_networks(machine, networks)
|
||||
@logger = Log4r::Logger.new("vagrant::guest::suse::configurenetworks")
|
||||
|
||||
# Determine which configuration method to use
|
||||
if VagrantPlugins::GuestSUSE::Guest.leap_16_or_newer?(machine) &&
|
||||
VagrantPlugins::GuestSUSE::Guest.network_manager_available?(machine)
|
||||
@logger.info("Using NetworkManager for OpenSUSE Leap 16+")
|
||||
configure_network_manager(machine, networks)
|
||||
else
|
||||
@logger.info("Using legacy ifup/ifdown for OpenSUSE")
|
||||
configure_networks_legacy(machine, networks)
|
||||
end
|
||||
end
|
||||
|
||||
# Legacy network configuration using ifup/ifdown
|
||||
def self.configure_networks_legacy(machine, networks)
|
||||
comm = machine.communicate
|
||||
|
||||
network_scripts_dir = machine.guest.capability(:network_scripts_dir)
|
||||
|
|
|
|||
25
plugins/guests/suse/cap/flavor.rb
Normal file
25
plugins/guests/suse/cap/flavor.rb
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# Copyright IBM Corp. 2010, 2025
|
||||
# SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestSUSE
|
||||
module Cap
|
||||
class Flavor
|
||||
# Detect the flavor of SUSE for version-specific capabilities
|
||||
# @return [Symbol] Flavor symbol (:leap_16_plus, :leap_legacy, :suse)
|
||||
def self.flavor(machine)
|
||||
version = VagrantPlugins::GuestSUSE::Guest.detect_version(machine)
|
||||
if version
|
||||
major_version = version.split(".").first.to_i
|
||||
if major_version >= 16
|
||||
return :leap_16_plus
|
||||
else
|
||||
return :leap_legacy
|
||||
end
|
||||
end
|
||||
:suse
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -6,7 +6,14 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class NetworkScriptsDir
|
||||
def self.network_scripts_dir(machine)
|
||||
"/etc/sysconfig/network"
|
||||
# For OpenSUSE Leap 16+ with NetworkManager, use NetworkManager path
|
||||
if VagrantPlugins::GuestSUSE::Guest.leap_16_or_newer?(machine) &&
|
||||
VagrantPlugins::GuestSUSE::Guest.network_manager_available?(machine)
|
||||
"/etc/NetworkManager/system-connections"
|
||||
else
|
||||
# For older versions or when NetworkManager is not available, use legacy path
|
||||
"/etc/sysconfig/network"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,6 +7,39 @@ module VagrantPlugins
|
|||
def detect?(machine)
|
||||
machine.communicate.test("test -f /etc/SuSE-release || grep -q SUSE /etc/os-release")
|
||||
end
|
||||
|
||||
# Detect the SUSE version from /etc/os-release
|
||||
# @return [String, nil] Version string (e.g., "15.6", "16.0") or nil if not detected
|
||||
def self.detect_version(machine)
|
||||
version = nil
|
||||
if machine.communicate.test("test -f /etc/os-release")
|
||||
machine.communicate.execute("source /etc/os-release && printf $VERSION_ID") do |type, data|
|
||||
if type == :stdout
|
||||
version = data.strip
|
||||
end
|
||||
end
|
||||
end
|
||||
version
|
||||
end
|
||||
|
||||
# Check if the system is OpenSUSE Leap 16 or newer
|
||||
# @return [Boolean] True if Leap 16+ or newer
|
||||
def self.leap_16_or_newer?(machine)
|
||||
version = detect_version(machine)
|
||||
return false unless version
|
||||
# Parse version like "15.5", "16.0", etc.
|
||||
major_version = version.split(".").first.to_i
|
||||
major_version >= 16
|
||||
end
|
||||
|
||||
# Check if NetworkManager is available and active on the system
|
||||
# @return [Boolean] True if NetworkManager is available
|
||||
def self.network_manager_available?(machine)
|
||||
comm = machine.communicate
|
||||
nmcli_installed = comm.test("command -v nmcli", sudo: true)
|
||||
nm_active = comm.test("systemctl -q is-active NetworkManager.service", sudo: true)
|
||||
nmcli_installed && nm_active
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -48,6 +48,11 @@ module VagrantPlugins
|
|||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
|
||||
guest_capability(:suse, :flavor) do
|
||||
require_relative "cap/flavor"
|
||||
Cap::Flavor
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue