Repository: cobbler/cobbler

Issue:
DNS update breaks
### Describe the bug

<!--- A clear and concise description of what the bug is. -->
Adding a system with:
cobbler system add --name=th-test-17 --hostname=th-test-17 --profile=rhel8u4-x86_64 --kernel-options="ksdevice=eth0" --interface=eth0 --mac=01:02:03:04:05:07 dns-name=th-test-17.testlab.my

gives:
exception on server: 'NetworkInterface' object is not subscriptable

<!--- HINT: You can paste gist.github.com links for long logs or larger files -->

### Steps to reproduce

1.
2.
3.

### Expected behavior

<!--- A clear and concise description of what you expected to happen. -->

### Cobbler version

<!--- Paste output from `cobbler version` -->
````paste below
````
cobbler -3.3.0.50+git.c1d81950 (Tumbleweed version)

### Operating system

<!--- On which operating system do you use Cobbler? -->
openSUSE Leap 15.3

### Cobbler log

<!--- Paste (partial) output from `/var/log/cobbler/cobbler.log` -->
````paste below
````
[Thread-116] 2021-11-11T09:10:34 - DEBUG | running python trigger cobbler.modules.nsupdate_add_system_post
[Thread-116] 2021-11-11T09:10:34 - INFO | Exception occurred: <class 'TypeError'>
[Thread-116] 2021-11-11T09:10:34 - INFO | Exception value: 'NetworkInterface' object is not subscriptable
[Thread-116] 2021-11-11T09:10:34 - INFO | Exception Info:
  File "/usr/lib/python3.6/site-packages/cobbler/remote.py", line 3625, in _dispatch
    return method_handle(*params)

  File "/usr/lib/python3.6/site-packages/cobbler/remote.py", line 2032, in xapi_object_edit
    self.save_item(object_type, handle, token)

  File "/usr/lib/python3.6/site-packages/cobbler/remote.py", line 2087, in save_item
    self.api.add_item(what, obj)

  File "/usr/lib/python3.6/site-packages/cobbler/api.py", line 762, in add_item
    self.get_items(what).add(ref, check_for_duplicate_names=check_for_duplicate_names, save=save)

  File "/usr/lib/python3.6/site-packages/cobbler/cobbler_collections/collection.py", line 434, in add
    [])

  File "/usr/lib/python3.6/site-packages/cobbler/utils.py", line 919, in run_triggers
    rc = m.run(api, arglist)

  File "/usr/lib/python3.6/site-packages/cobbler/modules/nsupdate_add_system_post.py", line 95, in run
    host = interface["dns_name"]

### Screenshots

<!--- If applicable, add screenshots to help explain your problem. -->

### Additional information

<!--- Add any other context about the problem here. -->



Discussion:
The solution is similiar to Adjust DNS settings #2712

Around line 94 in modules/nsupdate_[add|delete]_system_pre.py the list() has to replaced and then 2 lines with variables

Corrected lines:

    # process all interfaces and perform dynamic update for those with --dns-name
    for (name, interface) in system.interfaces.items():
        host = interface.dns_name
        host_ip = interface.ip_address


Resolving patch:
diff --git a/cobbler/modules/nsupdate_add_system_post.py b/cobbler/modules/nsupdate_add_system_post.py
--- a/cobbler/modules/nsupdate_add_system_post.py
+++ b/cobbler/modules/nsupdate_add_system_post.py
@@ -91,9 +91,9 @@ def run(api, args):
     system = api.find_system(args[0])
 
     # process all interfaces and perform dynamic update for those with --dns-name
-    for (name, interface) in list(system.interfaces.items()):
-        host = interface["dns_name"]
-        host_ip = interface["ip_address"]
+    for (name, interface) in system.interfaces.items():
+        host = interface.dns_name
+        host_ip = interface.ip_address
 
         if not system.is_management_supported(cidr_ok=False):
             continue
diff --git a/cobbler/modules/nsupdate_delete_system_pre.py b/cobbler/modules/nsupdate_delete_system_pre.py
--- a/cobbler/modules/nsupdate_delete_system_pre.py
+++ b/cobbler/modules/nsupdate_delete_system_pre.py
@@ -91,9 +91,9 @@ def run(api, args):
     system = api.find_system(args[0])
 
     # process all interfaces and perform dynamic update for those with --dns-name
-    for (name, interface) in list(system.interfaces.items()):
-        host = interface["dns_name"]
-        host_ip = interface["ip_address"]
+    for (name, interface) in system.interfaces.items():
+        host = interface.dns_name
+        host_ip = interface.ip_address
 
         if not system.is_management_supported(cidr_ok=False):
             continue


Test patch: