How-to: Import an additional second MAC address using the UCS@school computer import

How-to: Import an additional second MAC address using the UCS@school computer import

Prerequisites

We will be using an import hook for this How-to. Support for hooks during the import_computers script was added with Bug #55014 as a package update for UCS@school 5.0 v3, the package ucs-school-import therefore needs to be updated to version 18.0.28A~5.0.0.202301121201 at least.

General documentation for this feature can be found here (German only): 4. Verwaltung von Schulen über Importskripte — UCS@school - Handbuch für Administratoren

Step 1: Add the second MAC address to the import data

As documented following the link above the input data for the computer import must be a CSV separated by tabs. The second MAC address must be added to every line as the last argument:

windows	winDMEOSCHOOL-02	10:00:ee:ff:cc:03	DEMOSCHOOL	10.0.5.5	inventar	10:00:ee:ff:cc:04

Step 2: Create an import hook

The functional code for adding the second address must be written as a hook for the import, f.e. into a file called /usr/share/ucs-school-import/pyhooks/add_extra_mac.py:

from ucsschool.lib.models.computer import SchoolComputer
from ucsschool.importer.utils.computer_pyhook import ComputerPyHook


class AddExtraMacSchoolComputer(ComputerPyHook):
    model = SchoolComputer
    priority = {
        "pre_create": 10,
    }

    def pre_create(self, obj, line):
        obj.mac_address.append(line[-1])

add_extra_mac.py (331 Bytes)

Step 3: Conduct the import

The import should be conducted as usual:

/usr/share/ucs-school-import/scripts/import_computer <INPUT-FILE>.csv

Step 4 (optional): Check the MAC address

The verify the hook the MAC address can be checked like this:

udm computers/windows list --filter name=winDMEOSCHOOL-02 | grep mac

  mac: 10:00:ee:ff:cc:03
  mac: 10:00:ee:ff:cc:04

Limitations

The simple implementation shown here expects the input data to always contain a second MAC address. The hook will fail if this is omitted for some or all computers listed in the input file.

Secondly the input data is not validated or checked. If the MAC address is malformed an error will occur, if it is already taken it will still be assigned.