Repository: cobbler/cobbler

Issue:
CLI: Unable to set values other than strings
### Describe the bug

At the moment it is **not posibble** to set anything other than a string via the CLI.

### Steps to reproduce

1. Create a distro and a profile
2. Create a system
3. Try to set e.g. the Baud rate or the # of virt CPUs of the system

````bash
❯ cobbler system add --name stest2 --profile ptest --serial-baud-rate=240 
Usage: cobbler [options]

cobbler: error: option --serial-baud-rate: invalid choice: '240' (choose from '', '2400', '4800', '9600', '19200', '38400', '57600', '115200')

❯ cobbler system add --name stest2 --profile ptest --serial-baud-rate=2400
exception on server: serial baud rate needs to be of type int or enums.BaudRates

❯ cobbler system add --name stest2 --profile ptest --virt-cpus=1            
exception on server: virt_cpus needs to be an integer

````

### Expected behavior
All values should be settable via the CLI.

### Cobbler version

Current master branch.
<!--- Paste output from `cobbler version` -->
````bash
$ cobbler version
 source: ab950916, Mon Jul 26 17:27:06 2021 +0200
  build time: Wed Jul 28 09:19:45 2021
````

### Operating system
openSUSE Tumbleweed, SLES 15-SP3

### Cobbler log

<!--- Paste (partial) output from `/var/log/cobbler/cobbler.log` -->
````bash
(...)
[Thread-173] 2021-07-29T09:44:33 - INFO | Exception occurred: <class 'TypeError'>
[Thread-173] 2021-07-29T09:44:33 - INFO | Exception value: serial baud rate needs to be of type int or enums.BaudRates
[Thread-173] 2021-07-29T09:44:33 - INFO | Exception Info:
  File "/usr/local/lib/python3.8/site-packages/cobbler/remote.py", line 3514, in _dispatch
    return method_handle(*params)

  File "/usr/local/lib/python3.8/site-packages/cobbler/remote.py", line 1942, in xapi_object_edit
    self.modify_item(object_type, handle, key, value, token)

  File "/usr/local/lib/python3.8/site-packages/cobbler/remote.py", line 1696, in modify_item
    setattr(obj, attribute, arg)

  File "/usr/local/lib/python3.8/site-packages/cobbler/items/system.py", line 1760, in serial_baud_rate
    self._serial_baud_rate = validate.validate_serial_baud_rate(baud_rate)

  File "/usr/local/lib/python3.8/site-packages/cobbler/validate.py", line 530, in validate_serial_baud_rate
    raise TypeError("serial baud rate needs to be of type int or enums.BaudRates")
(...)
[Thread-193] 2021-07-29T09:49:02 - INFO | Exception occurred: <class 'TypeError'>
[Thread-193] 2021-07-29T09:49:02 - INFO | Exception value: virt_cpus needs to be an integer
[Thread-193] 2021-07-29T09:49:02 - INFO | Exception Info:
  File "/usr/local/lib/python3.8/site-packages/cobbler/remote.py", line 3514, in _dispatch
    return method_handle(*params)

  File "/usr/local/lib/python3.8/site-packages/cobbler/remote.py", line 1942, in xapi_object_edit
    self.modify_item(object_type, handle, key, value, token)

  File "/usr/local/lib/python3.8/site-packages/cobbler/remote.py", line 1696, in modify_item
    setattr(obj, attribute, arg)

  File "/usr/local/lib/python3.8/site-packages/cobbler/items/system.py", line 1380, in virt_cpus
    self._virt_cpus = validate.validate_virt_cpus(num)

  File "/usr/local/lib/python3.8/site-packages/cobbler/validate.py", line 497, in validate_virt_cpus
    raise TypeError("virt_cpus needs to be an integer")
````



Discussion:
TODO: 

- fix the problem for enums like the Baud rate from above.
Reopen because only partly fixed.

Resolving patch:
diff --git a/cobbler/remote.py b/cobbler/remote.py
--- a/cobbler/remote.py
+++ b/cobbler/remote.py
@@ -1990,6 +1990,8 @@ def __interface_edits(self, handle, attributes, object_name):
                     self.logger.debug("Field %s was not an interface field.", attribute_key)
             system_to_edit.interfaces.update({interface_name: interface})
         elif "delete_interface" in attributes:
+            if attributes.get("interface") is None:
+                raise ValueError("Interface is required for deletion.")
             system_to_edit = self.__get_object(handle)
             system_to_edit.delete_interface(attributes.get("interface"))
         elif "rename_interface" in attributes:
diff --git a/cobbler/validate.py b/cobbler/validate.py
--- a/cobbler/validate.py
+++ b/cobbler/validate.py
@@ -529,7 +529,7 @@ def validate_serial_device(value: Union[str, int]) -> int:
     return int(value)
 
 
-def validate_serial_baud_rate(baud_rate: Union[int, enums.BaudRates]) -> enums.BaudRates:
+def validate_serial_baud_rate(baud_rate: Union[int, str, enums.BaudRates]) -> enums.BaudRates:
     """
     The baud rate is very import that the communication between the two devices can be established correctly. This is
     the setter for this parameter. This effectively is the speed of the connection.
@@ -537,10 +537,10 @@ def validate_serial_baud_rate(baud_rate: Union[int, enums.BaudRates]) -> enums.B
     :param baud_rate: The baud rate to set.
     :return: The validated baud rate.
     """
-    if not isinstance(baud_rate, (int, enums.BaudRates)):
+    if not isinstance(baud_rate, (int, str, enums.BaudRates)):
         raise TypeError("serial baud rate needs to be of type int or enums.BaudRates")
-    # Convert the baud rate which came in as an int
-    if isinstance(baud_rate, int):
+    # Convert the baud rate which came in as an int or str
+    if isinstance(baud_rate, (int, str)):
         try:
             baud_rate = enums.BaudRates["B" + str(baud_rate)]
         except KeyError as key_error:


Test patch: