From fb5fc0e657a10ee1eaf046980827cc1802c4d0f9 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 20 Sep 2018 16:42:39 -0700 Subject: [PATCH] Update guest inspection utility module Use sudo option for communicator test command instead of inline sudo to properly use configured sudo value. Use command for checking availability of hostnamectl. Use is-active for determining if a service is being actively managed by systemd. --- lib/vagrant/util/guest_inspection.rb | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/vagrant/util/guest_inspection.rb b/lib/vagrant/util/guest_inspection.rb index 86ab1dc69..5a1902d8d 100644 --- a/lib/vagrant/util/guest_inspection.rb +++ b/lib/vagrant/util/guest_inspection.rb @@ -12,27 +12,39 @@ module Vagrant # # @return [Boolean] def systemd?(comm) - comm.test("sudo ps -o comm= 1 | grep systemd") + comm.test("ps -o comm= 1 | grep systemd") end # systemd-networkd.service is in use # + # @param [Vagrant::Plugin::V2::Communicator] comm Guest communicator # @return [Boolean] def systemd_networkd?(comm) - comm.test("sudo systemctl status systemd-networkd.service") + comm.test("systemctl -q is-active systemd-networkd.service", sudo: true) + end + + # Check if given service is controlled by systemd + # + # @param [Vagrant::Plugin::V2::Communicator] comm Guest communicator + # @param [String] service_name Name of the service to check + # @return [Boolean] + def systemd_controlled?(comm, service_name) + comm.test("systemctl -q is-active #{service_name}", sudo: true) end # systemd hostname set is via hostnamectl # + # @param [Vagrant::Plugin::V2::Communicator] comm Guest communicator # @return [Boolean] def hostnamectl?(comm) - comm.test("hostnamectl") + comm.test("command -v hostnamectl") end ## netplan helpers # netplan is installed # + # @param [Vagrant::Plugin::V2::Communicator] comm Guest communicator # @return [Boolean] def netplan?(comm) comm.test("netplan -h") @@ -42,6 +54,7 @@ module Vagrant # nmcli is installed # + # @param [Vagrant::Plugin::V2::Communicator] comm Guest communicator # @return [Boolean] def nmcli?(comm) comm.test("nmcli -t") @@ -49,7 +62,7 @@ module Vagrant # NetworkManager currently controls device # - # @param comm [Communicator] + # @param [Vagrant::Plugin::V2::Communicator] comm Guest communicator # @param device_name [String] # @return [Boolean] def nm_controlled?(comm, device_name)