|
38 | 38 | NM_CONTROLLED=no |
39 | 39 | """ |
40 | 40 |
|
| 41 | +NMCONNECTION_TEMPLATE = """[connection] |
| 42 | +id=%(device_name)s |
| 43 | +uuid=%(uuid)s |
| 44 | +type=ethernet |
| 45 | +interface-name=%(device_name)s |
| 46 | +
|
| 47 | +[ethernet] |
| 48 | +
|
| 49 | +[ipv4] |
| 50 | +method=auto |
| 51 | +
|
| 52 | +[ipv6] |
| 53 | +addr-gen-mode=eui64 |
| 54 | +method=auto |
| 55 | +
|
| 56 | +[proxy] |
| 57 | +""" |
| 58 | + |
41 | 59 |
|
42 | 60 | class BaseRedHatMorphingTools(base.BaseLinuxOSMorphingTools): |
43 | 61 | _NETWORK_SCRIPTS_PATH = "etc/sysconfig/network-scripts" |
| 62 | + _NMCONNECTION_PATH = "etc/NetworkManager/system-connections" |
44 | 63 | BIOS_GRUB_LOCATION = "/boot/grub2" |
45 | 64 | UEFI_GRUB_LOCATION = "/boot/efi/EFI/redhat" |
46 | 65 |
|
@@ -126,6 +145,29 @@ def _write_nic_configs(self, nics_info): |
126 | 145 | "device_name": dev_name, |
127 | 146 | }) |
128 | 147 |
|
| 148 | + def _write_nmconnection_configs(self, nics_info): |
| 149 | + nmconn_dir = self._NMCONNECTION_PATH |
| 150 | + self._exec_cmd_chroot("mkdir -p /%s" % nmconn_dir) |
| 151 | + |
| 152 | + for idx, _ in enumerate(nics_info): |
| 153 | + dev_name = "eth%d" % idx |
| 154 | + connection_uuid = str(uuid.uuid4()) |
| 155 | + cfg_path = "%s/%s.nmconnection" % (nmconn_dir, dev_name) |
| 156 | + |
| 157 | + if self._test_path(cfg_path): |
| 158 | + self._exec_cmd_chroot( |
| 159 | + "cp %s %s.bak" % (cfg_path, cfg_path) |
| 160 | + ) |
| 161 | + |
| 162 | + self._write_file_sudo( |
| 163 | + cfg_path, |
| 164 | + NMCONNECTION_TEMPLATE % { |
| 165 | + "device_name": dev_name, |
| 166 | + "uuid": connection_uuid, |
| 167 | + }) |
| 168 | + |
| 169 | + self._exec_cmd_chroot("chmod 600 /%s" % cfg_path) |
| 170 | + |
129 | 171 | def _comment_keys_from_ifcfg_files( |
130 | 172 | self, keys, interfaces=None, backup_file_suffix=".bak"): |
131 | 173 | """ Comments the provided list of keys from all 'ifcfg-*' files. |
@@ -160,10 +202,25 @@ def _comment_keys_from_ifcfg_files( |
160 | 202 | "Commented all %s references from '%s'" % ( |
161 | 203 | keys, fullpath)) |
162 | 204 |
|
| 205 | + def _get_os_version(self): |
| 206 | + try: |
| 207 | + version_str = self._detected_os_info.get('release_version', '0') |
| 208 | + major_version = int(version_str.split('.')[0]) |
| 209 | + return major_version |
| 210 | + except (ValueError, AttributeError): |
| 211 | + LOG.warning( |
| 212 | + "Could not parse OS version from detected_os_info: %s", |
| 213 | + self._detected_os_info) |
| 214 | + return |
| 215 | + |
163 | 216 | def set_net_config(self, nics_info, dhcp): |
164 | 217 | if dhcp: |
165 | 218 | self.disable_predictable_nic_names() |
166 | | - self._write_nic_configs(nics_info) |
| 219 | + os_version = self._get_os_version() |
| 220 | + if os_version < 9: |
| 221 | + self._write_nic_configs(nics_info) |
| 222 | + else: |
| 223 | + self._write_nmconnection_configs(nics_info) |
167 | 224 | return |
168 | 225 |
|
169 | 226 | LOG.info("Setting static IP configuration") |
|
0 commit comments