Blob Blame History Raw
From 845e4647f72d27fc9aeaee5cd69d40a052d85f62 Mon Sep 17 00:00:00 2001
From: Vitaly Kuznetsov <vkuznets@redhat.com>
Date: Wed, 11 Jan 2017 16:40:59 +0100
Subject: [PATCH 1/2] RHEL-7 hostname (#533)

RH-Author: Vitaly Kuznetsov <vkuznets@redhat.com>
Message-id: <20170111164100.436-2-vkuznets@redhat.com>
Patchwork-id: 73240
O-Subject: [RHEL-7.4/7.3.z WALinuxAgent PATCH 1/2] RHEL-7 hostname (#533)
Bugzilla: 1413674
RH-Acked-by: Cathy Avery <cavery@redhat.com>

From: Hans Krijger <hglkrijger@users.noreply.github.com>

* use hostnamectl for redhat 7.x

* create directory if it is missing

(cherry picked from commit 8f91a15cd59b6ed81cdfa28e6014a226ce613c9e)
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 azurelinuxagent/common/osutil/redhat.py | 5 ++---
 azurelinuxagent/ga/exthandlers.py       | 3 +++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/azurelinuxagent/common/osutil/redhat.py b/azurelinuxagent/common/osutil/redhat.py
index 80370a2..f8372f0 100644
--- a/azurelinuxagent/common/osutil/redhat.py
+++ b/azurelinuxagent/common/osutil/redhat.py
@@ -96,10 +96,9 @@ class RedhatOSUtil(Redhat6xOSUtil):
 
     def set_hostname(self, hostname):
         """
-        Set /etc/hostname
-        Unlike redhat 6.x, redhat 7.x will set hostname to /etc/hostname
+        Unlike redhat 6.x, redhat 7.x will set hostname via hostnamectl
         """
-        DefaultOSUtil.set_hostname(self, hostname)
+        shellutil.run("hostnamectl {0}".format(hostname))
 
     def publish_hostname(self, hostname):
         """
diff --git a/azurelinuxagent/ga/exthandlers.py b/azurelinuxagent/ga/exthandlers.py
index 192300e..5b35f45 100644
--- a/azurelinuxagent/ga/exthandlers.py
+++ b/azurelinuxagent/ga/exthandlers.py
@@ -798,6 +798,9 @@ class ExtHandlerInstance(object):
     def set_handler_state(self, handler_state):
         state_dir = self.get_conf_dir()
         try:
+            if not os.path.exists(state_dir):
+                fileutil.mkdir(state_dir, mode=0o700)
+
             state_file = os.path.join(state_dir, "HandlerState")
             fileutil.write_file(state_file, handler_state)
         except IOError as e:
-- 
1.8.3.1