From ae34127906643c08aa17838ec13f75fca5c1ae05 Mon Sep 17 00:00:00 2001 From: Robert Schweikert Date: Thu, 5 May 2022 07:40:38 -0400 Subject: [PATCH 1/2] Reset dhcp config to send host information on SUSE distros - Reset the dhcp configuration to send the host information when an instance is being deprovisioned. This ensures that instances from a managed VM created from a running instance send the proper information to the DHCP server. Thanks Joao Silva. --- azurelinuxagent/pa/deprovision/factory.py | 3 +++ azurelinuxagent/pa/deprovision/suse.py | 33 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 azurelinuxagent/pa/deprovision/suse.py diff --git a/azurelinuxagent/pa/deprovision/factory.py b/azurelinuxagent/pa/deprovision/factory.py index 2caedc8da..80627a0e6 100644 --- a/azurelinuxagent/pa/deprovision/factory.py +++ b/azurelinuxagent/pa/deprovision/factory.py @@ -22,6 +22,7 @@ from .clearlinux import ClearLinuxDeprovisionHandler from .coreos import CoreOSDeprovisionHandler from .default import DeprovisionHandler +from .suse import SUSEDeprovisionHandler from .ubuntu import UbuntuDeprovisionHandler, Ubuntu1804DeprovisionHandler @@ -39,6 +40,8 @@ def get_deprovision_handler(distro_name=DISTRO_NAME, return CoreOSDeprovisionHandler() if "Clear Linux" in distro_full_name: return ClearLinuxDeprovisionHandler() # pylint: disable=E1120 + if distro_name in ("suse", "sle_hpc", "sles", "opensuse"): + return SUSEDeprovisionHandler() return DeprovisionHandler() diff --git a/azurelinuxagent/pa/deprovision/suse.py b/azurelinuxagent/pa/deprovision/suse.py new file mode 100644 index 000000000..de8a92713 --- /dev/null +++ b/azurelinuxagent/pa/deprovision/suse.py @@ -0,0 +1,33 @@ +# Microsoft Azure Linux Agent +# +# Copyright 2022 Microsoft Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Requires Python 2.6+ and Openssl 1.0+ +# + +import azurelinuxagent.common.utils.fileutil as fileutil +from azurelinuxagent.pa.deprovision.default import DeprovisionHandler, \ + DeprovisionAction + +class SUSEDeprovisionHandler(DeprovisionHandler): + def __init__(self): + super(SUSEDeprovisionHandler, self).__init__() + + def reset_hostname(self, warnings, actions): + localhost = ["AUTO"] + actions.append(DeprovisionAction(self.osutil.set_hostname, + localhost)) + actions.append(DeprovisionAction(self.osutil.set_dhcp_hostname, + localhost)) From b7081dfbe1991951ddfadf9b796029b5b0686680 Mon Sep 17 00:00:00 2001 From: Robert Schweikert Date: Thu, 5 May 2022 13:58:57 -0400 Subject: [PATCH 2/2] Fix lint errors --- azurelinuxagent/pa/deprovision/suse.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/azurelinuxagent/pa/deprovision/suse.py b/azurelinuxagent/pa/deprovision/suse.py index de8a92713..3bac75867 100644 --- a/azurelinuxagent/pa/deprovision/suse.py +++ b/azurelinuxagent/pa/deprovision/suse.py @@ -17,12 +17,11 @@ # Requires Python 2.6+ and Openssl 1.0+ # -import azurelinuxagent.common.utils.fileutil as fileutil from azurelinuxagent.pa.deprovision.default import DeprovisionHandler, \ DeprovisionAction class SUSEDeprovisionHandler(DeprovisionHandler): - def __init__(self): + def __init__(self): # pylint: disable=W0235 super(SUSEDeprovisionHandler, self).__init__() def reset_hostname(self, warnings, actions):