1
- From dd1512513b407e23155f58400cacecac8576d6f9 Mon Sep 17 00:00:00 2001
1
+ From 7382c63bb2c90a1173393faf093002341f830a09 Mon Sep 17 00:00:00 2001
2
2
From: Krzesimir Nowak <knowak@microsoft.com>
3
3
Date: Mon, 27 Feb 2023 15:59:21 +0100
4
4
Subject: [PATCH] flatcar changes
5
5
6
+ Signed-off-by: Jeremi Piotrowski <jpiotrowski@microsoft.com>
6
7
---
7
- azurelinuxagent/common/osutil/coreos.py | 39 +-----
8
- azurelinuxagent/common/osutil/coreoscommon.py | 57 ++++++++
8
+ azurelinuxagent/common/osutil/coreos.py | 40 +-----
9
+ azurelinuxagent/common/osutil/coreoscommon.py | 59 + ++++++++
9
10
azurelinuxagent/common/osutil/factory.py | 3 +
10
- azurelinuxagent/common/osutil/flatcar.py | 60 +++++++++
11
+ azurelinuxagent/common/osutil/flatcar.py | 78 +++++++++++
12
+ .../common/persist_firewall_rules.py | 1 +
11
13
config/flatcar/waagent.conf | 122 ++++++++++++++++++
12
14
init/flatcar/10-waagent-sysext.conf | 2 +
13
15
init/flatcar/waagent.service | 30 +++++
14
16
setup.py | 20 ++-
15
- 8 files changed, 291 insertions(+), 42 deletions(-)
17
+ 9 files changed, 312 insertions(+), 43 deletions(-)
16
18
create mode 100644 azurelinuxagent/common/osutil/coreoscommon.py
17
19
create mode 100644 azurelinuxagent/common/osutil/flatcar.py
18
20
create mode 100644 config/flatcar/waagent.conf
19
21
create mode 100644 init/flatcar/10-waagent-sysext.conf
20
22
create mode 100644 init/flatcar/waagent.service
21
23
22
24
diff --git a/azurelinuxagent/common/osutil/coreos.py b/azurelinuxagent/common/osutil/coreos.py
23
- index fc0a6604..314008f0 100644
25
+ index 373727e2..63578932 100644
24
26
--- a/azurelinuxagent/common/osutil/coreos.py
25
27
+++ b/azurelinuxagent/common/osutil/coreos.py
26
- @@ -17,11 +17,10 @@
27
- #
28
+ @@ -18,10 +18,10 @@
28
29
29
30
import os
30
- - import azurelinuxagent.common.utils.shellutil as shellutil
31
+ from azurelinuxagent.common.utils import shellutil
31
32
- from azurelinuxagent.common.osutil.default import DefaultOSUtil
32
33
+ from azurelinuxagent.common.osutil.coreoscommon import CoreosCommonUtil
33
34
@@ -37,7 +38,7 @@ index fc0a6604..314008f0 100644
37
38
38
39
def __init__(self):
39
40
super(CoreOSUtil, self).__init__()
40
- @@ -46,40 +45 ,6 @@ class CoreOSUtil(DefaultOSUtil):
41
+ @@ -46,42 +46 ,6 @@ class CoreOSUtil(DefaultOSUtil):
41
42
def get_agent_bin_path():
42
43
return "/usr/share/oem/bin"
43
44
@@ -73,17 +74,19 @@ index fc0a6604..314008f0 100644
73
74
- return shellutil.run("systemctl stop {0}".format(self.service_name), chk_err=False)
74
75
-
75
76
- def get_dhcp_pid(self):
76
- - return self._get_dhcp_pid(["systemctl", "show", "-p", "MainPID", "systemd-networkd"])
77
+ - return self._get_dhcp_pid(
78
+ - ["systemctl", "show", "-p", "MainPID", "systemd-networkd"],
79
+ - transform_command_output=lambda o: o.replace("MainPID=", ""))
77
80
-
78
81
def conf_sshd(self, disable_password):
79
82
# In CoreOS, /etc/sshd_config is mount readonly. Skip the setting.
80
83
pass
81
84
diff --git a/azurelinuxagent/common/osutil/coreoscommon.py b/azurelinuxagent/common/osutil/coreoscommon.py
82
85
new file mode 100644
83
- index 00000000..fde9a456
86
+ index 00000000..66eae16e
84
87
--- /dev/null
85
88
+++ b/azurelinuxagent/common/osutil/coreoscommon.py
86
- @@ -0,0 +1,57 @@
89
+ @@ -0,0 +1,59 @@
87
90
+ #
88
91
+ # Copyright 2023 Microsoft Corporation
89
92
+ #
@@ -140,20 +143,22 @@ index 00000000..fde9a456
140
143
+ return shellutil.run("systemctl stop {0}".format(self.service_name), chk_err=False)
141
144
+
142
145
+ def get_dhcp_pid(self):
143
- + return self._get_dhcp_pid(["systemctl", "show", "-p", "MainPID", "systemd-networkd"])
146
+ + return self._get_dhcp_pid(
147
+ + ["systemctl", "show", "-p", "MainPID", "systemd-networkd"],
148
+ + transform_command_output=lambda o: o.replace("MainPID=", ""))
144
149
diff --git a/azurelinuxagent/common/osutil/factory.py b/azurelinuxagent/common/osutil/factory.py
145
- index b5ee0b09..9280c645 100644
150
+ index 83123e3f..b9257a9b 100644
146
151
--- a/azurelinuxagent/common/osutil/factory.py
147
152
+++ b/azurelinuxagent/common/osutil/factory.py
148
- @@ -27,6 +27,7 @@ from .clearlinux import ClearLinuxUtil
149
- from .coreos import CoreOSUtil
153
+ @@ -28,6 +28,7 @@ from .coreos import CoreOSUtil
150
154
from .debian import DebianOSBaseUtil, DebianOSModernUtil
151
155
from .default import DefaultOSUtil
156
+ from .devuan import DevuanOSUtil
152
157
+ from .flatcar import FlatcarUtil
153
158
from .freebsd import FreeBSDOSUtil
154
159
from .gaia import GaiaOSUtil
155
160
from .iosxe import IosxeOSUtil
156
- @@ -82 ,6 +83 ,8 @@ def _get_osutil(distro_name, distro_code_name, distro_version, distro_full_name)
161
+ @@ -88 ,6 +89 ,8 @@ def _get_osutil(distro_name, distro_code_name, distro_version, distro_full_name)
157
162
return DebianOSBaseUtil()
158
163
159
164
if distro_name in ("flatcar", "coreos") or distro_code_name in ("flatcar", "coreos"):
@@ -164,10 +169,10 @@ index b5ee0b09..9280c645 100644
164
169
if distro_name in ("suse", "sle_hpc", "sles", "opensuse"):
165
170
diff --git a/azurelinuxagent/common/osutil/flatcar.py b/azurelinuxagent/common/osutil/flatcar.py
166
171
new file mode 100644
167
- index 00000000..bf739a8e
172
+ index 00000000..e31b2923
168
173
--- /dev/null
169
174
+++ b/azurelinuxagent/common/osutil/flatcar.py
170
- @@ -0,0 +1,60 @@
175
+ @@ -0,0 +1,78 @@
171
176
+ #
172
177
+ # Copyright 2023 Microsoft Corporation
173
178
+ #
@@ -194,14 +199,15 @@ index 00000000..bf739a8e
194
199
+ import azurelinuxagent.common.conf as conf
195
200
+ import azurelinuxagent.common.logger as logger
196
201
+ import azurelinuxagent.common.utils.fileutil as fileutil
202
+ + import azurelinuxagent.common.utils.shellutil as shellutil
197
203
+
198
204
+ from azurelinuxagent.common.osutil.coreoscommon import CoreosCommonUtil
199
205
+
200
206
+ class FlatcarUtil(CoreosCommonUtil):
201
207
+
202
208
+ @staticmethod
203
209
+ def get_systemd_unit_file_install_path():
204
- + return "/usr/lib /systemd/system"
210
+ + return "/etc /systemd/system"
205
211
+
206
212
+ def conf_sshd(self, disable_password):
207
213
+ ssh_dir = conf.get_ssh_dir()
@@ -228,6 +234,35 @@ index 00000000..bf739a8e
228
234
+ os.remove(conf_file_path)
229
235
+ os.rename(conf_file_path2, conf_file_path)
230
236
+ super(CoreosCommonUtil, self).conf_sshd(disable_password)
237
+ +
238
+ + def restart_if(self, ifname, retries=3, wait=5):
239
+ + """
240
+ + Restart an interface by bouncing the link. systemd-networkd observes
241
+ + this event, and forces a renew of DHCP.
242
+ + """
243
+ + retry_limit = retries + 1
244
+ + for attempt in range(1, retry_limit):
245
+ + return_code = shellutil.run("ip link set {0} down && ip link set {0} up".format(ifname))
246
+ + if return_code == 0:
247
+ + return
248
+ + logger.warn("failed to restart {0}: return code {1}".format(ifname, return_code))
249
+ + if attempt < retry_limit:
250
+ + logger.info("retrying in {0} seconds".format(wait))
251
+ + time.sleep(wait)
252
+ + else:
253
+ + logger.warn("exceeded restart retries")
254
+ diff --git a/azurelinuxagent/common/persist_firewall_rules.py b/azurelinuxagent/common/persist_firewall_rules.py
255
+ index 74b878ce..22562c96 100644
256
+ --- a/azurelinuxagent/common/persist_firewall_rules.py
257
+ +++ b/azurelinuxagent/common/persist_firewall_rules.py
258
+ @@ -35,6 +35,7 @@ class PersistFirewallRulesHandler(object):
259
+ # Do not edit.
260
+ [Unit]
261
+ Description=Setup network rules for WALinuxAgent
262
+ + After=systemd-sysext.service
263
+ Before=network-pre.target
264
+ Wants=network-pre.target
265
+ DefaultDependencies=no
231
266
diff --git a/config/flatcar/waagent.conf b/config/flatcar/waagent.conf
232
267
new file mode 100644
233
268
index 00000000..b453c634
@@ -401,10 +436,10 @@ index 00000000..d0d6f7c8
401
436
+ [Install]
402
437
+ WantedBy=multi-user.target
403
438
diff --git a/setup.py b/setup.py
404
- index d38d74d6..57b0edb9 100755
439
+ index 8f5d92b4..35400e09 100755
405
440
--- a/setup.py
406
441
+++ b/setup.py
407
- @@ -125 ,12 +125 ,22 @@ def get_data_files(name, version, fullname): # pylint: disable=R0912
442
+ @@ -135 ,12 +135 ,22 @@ def get_data_files(name, version, fullname): # pylint: disable=R0912
408
443
src=["init/arch/waagent.service"])
409
444
elif name in ('coreos', 'flatcar'):
410
445
set_bin_files(data_files, dest=agent_bin_path)
@@ -433,5 +468,5 @@ index d38d74d6..57b0edb9 100755
433
468
set_bin_files(data_files, dest=agent_bin_path)
434
469
set_conf_files(data_files, dest="/usr/share/defaults/waagent",
435
470
- -
436
- 2.25.1
471
+ 2.39.2
437
472
0 commit comments