Skip to content
Edit this page

ictdesigntools.identifiers

Identifiers for spaces, racks, panels, ports, cables and cords, in the ANSI/TIA-606 forms.

Every badge, net flag, schedule row and NetBox label made by the library takes its name from here, so they agree. The forms are those of ANSI/TIA-606-B, table 1 and annex A; check them against the edition a project names (606-C and 606-D keep the same delimiters):

  • telecommunications space [[c-]b-]fs: 1DC
  • cabinet or rack fs.xy: 1DC.AD02
  • patch panel fs.xy-r: 1DC.AD02-35
  • port fs.xy-r:p: 1DC.AD02-35:01
  • cable between panels, near / far: AD02-35:01 / AG13-07:A1
  • patch cord, near \ far: AD07-37:01 \ AD07-07:A1

f is the floor (left out in a one-floor building) and s the space, together one code such as 1DC or 3TR; c and b are the campus and building, needed from administration class 3 and 4. x and y are the rack's floor-grid coordinates, letters then digits. r is the panel's top-most unit counted from the bottom of the rack's usable space (horizontal cable managers are not counted), with an optional _r2 for a panel or module inside it. p is the port, and -p2 closes a range of ports. A cable is named from the end where the label is read: the near end first.

Only ASCII letters, digits and the delimiters -, ., :, _, / and \ are used, so the names pass through CSV and DCIM imports intact. Where a panel unit uses letters, I, O and Q are left out as the standard asks.

>>> port = Port(Panel(Rack("AD", "02", Space("1DC")), "35"), "01")
>>> str(port)
'1DC.AD02-35:01'
>>> Port.parse("1DC.AD02-35:01") == port
True
>>> str(Cable(port, Port.parse("1DC.AG13-07:A1")).short())
'AD02-35:01 / AG13-07:A1'

Space dataclass

Space(code: str, building: str = '', campus: str = '')

A telecommunications space: code is the floor and space together (1DC, 3TR, 405), building and campus the prefixes administration classes 3 and 4 need.

Rack dataclass

Rack(x: str, y: str, space: Space | None = None)

A cabinet or rack by its floor-grid tile: x letters and y digits (AD, 02). space is left out when every rack named is in the same space.

Panel dataclass

Panel(rack: Rack, unit: str, sub: str = '')

A patch panel (or termination block) by unit, its top-most unit as a fixed number of digits (35, 07); sub names a panel or module within it.

short

short() -> Panel

The same panel without its space, for a drawing of one space.

Source code in src/ictdesigntools/identifiers.py
def short(self) -> Panel:
    """The same panel without its space, for a drawing of one space."""
    return replace(self, rack=replace(self.rack, space=None))

Port dataclass

Port(panel: Panel, port: str, last: str = '')

A port on a panel; last closes a range (:01-24).

Cable dataclass

Cable(near: Port, far: Port, cord: bool = False)

A cable between two panels (/), or a patch cord (\) when cord is set. The near end is where the label is read; flipped() gives the label for the far end.

panel_unit

panel_unit(
    position: float,
    u_height: float,
    starting_unit: int = 1,
    desc_units: bool = False,
    digits: int = 2,
) -> str

The unit a panel is named by: its top-most unit, counted from the bottom of the rack's usable space. position is NetBox's, the lowest-numbered unit the panel takes. A rack numbered from the top down (desc_units) names it by the top-most unit's own number, so the labels match the rails; say so on the drawing.

>>> panel_unit(35, 1), panel_unit(10, 2), panel_unit(10.5, 1), panel_unit(1, 2, desc_units=True)
('35', '11', '11', '01')
Source code in src/ictdesigntools/identifiers.py
def panel_unit(
    position: float,
    u_height: float,
    starting_unit: int = 1,
    desc_units: bool = False,
    digits: int = 2,
) -> str:
    """The unit a panel is named by: its top-most unit, counted from the bottom of the rack's
    usable space. ``position`` is NetBox's, the lowest-numbered unit the panel takes. A rack
    numbered from the top down (``desc_units``) names it by the top-most unit's own number, so
    the labels match the rails; say so on the drawing.

    >>> panel_unit(35, 1), panel_unit(10, 2), panel_unit(10.5, 1), panel_unit(1, 2, desc_units=True)
    ('35', '11', '11', '01')
    """
    if desc_units:
        top = math.floor(position)
    else:
        top = math.ceil(position + u_height) - 1
    n = top - starting_unit + 1
    if n < 1:
        raise ValueError(f"A panel at U{position} is below the rack's first unit.")
    return f"{n:0{digits}d}"

panel_of

panel_of(
    rack: Rack, device, rack_type, digits: int = 2
) -> Panel

The identifier of a panel mounted in a rack: device is a spaces.racks.Device with a position and rack_type the RackType it is in.

>>> from ictdesigntools.spaces.racks import Device, device_type, rack_type
>>> pp = Device(device_type("patch-panel-24-1u"), 42)
>>> str(panel_of(Rack("AD", "02"), pp, rack_type("generic-cabinet-42u-600x1070")))
'AD02-42'
Source code in src/ictdesigntools/identifiers.py
def panel_of(rack: Rack, device, rack_type, digits: int = 2) -> Panel:
    """The identifier of a panel mounted in a rack: ``device`` is a ``spaces.racks.Device``
    with a position and ``rack_type`` the ``RackType`` it is in.

    >>> from ictdesigntools.spaces.racks import Device, device_type, rack_type
    >>> pp = Device(device_type("patch-panel-24-1u"), 42)
    >>> str(panel_of(Rack("AD", "02"), pp, rack_type("generic-cabinet-42u-600x1070")))
    'AD02-42'
    """
    if device.position is None:
        raise ValueError(f"{device.label} is not racked, so it has no panel unit.")
    unit = panel_unit(device.position, device.device_type.u_height, rack_type.starting_unit,
                      rack_type.desc_units, digits)  # fmt: skip
    return Panel(rack, unit)

grid_rack

grid_rack(
    x: str,
    y: int,
    space: Space | None = None,
    digits: int = 2,
) -> Rack

A rack on a floor grid from a column of letters and a row number, the row padded to digits so the names sort (grid_rack("AD", 2) is AD02).

Source code in src/ictdesigntools/identifiers.py
def grid_rack(x: str, y: int, space: Space | None = None, digits: int = 2) -> Rack:
    """A rack on a floor grid from a column of letters and a row number, the row padded to
    ``digits`` so the names sort (``grid_rack("AD", 2)`` is ``AD02``)."""
    return Rack(x, f"{y:0{digits}d}", space)

check_class

check_class(admin_class: int, space: Space) -> list[str]

What a space's identifier lacks for an administration class: a building from class 3, a campus from class 4. An empty list when it is complete.

Source code in src/ictdesigntools/identifiers.py
def check_class(admin_class: int, space: Space) -> list[str]:
    """What a space's identifier lacks for an administration class: a building from class 3,
    a campus from class 4. An empty list when it is complete."""
    if admin_class not in ADMINISTRATION_CLASSES:
        raise ValueError(f"Administration classes are 1 to 4, not {admin_class}.")
    out = []
    if admin_class >= 3 and not space.building:
        out.append(f"Class {admin_class} names the building: {space.code} has none.")
    if admin_class == 4 and not space.campus:
        out.append(f"Class 4 names the campus: {space.code} has none.")
    return out