Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions plugins/guests/suse/cap/configure_networks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions plugins/guests/suse/cap/flavor.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion plugins/guests/suse/cap/network_scripts_dir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ module GuestSUSE
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
Expand Down
33 changes: 33 additions & 0 deletions plugins/guests/suse/guest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,39 @@ class Guest < Vagrant.plugin("2", :guest)
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
5 changes: 5 additions & 0 deletions plugins/guests/suse/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class Plugin < Vagrant.plugin("2")
require_relative "cap/rsync"
Cap::RSync
end

guest_capability(:suse, :flavor) do
require_relative "cap/flavor"
Cap::Flavor
end
end
end
end