From ebe22519c473dd73125dd9e4efa72c989668cf70 Mon Sep 17 00:00:00 2001 From: bia1708 Date: Thu, 17 Oct 2024 16:18:49 +0300 Subject: [PATCH] netbox.py: Update script to support latest Netbox Starting with v3.3, several Netbox API fields have been modified, including ones for power outlets (change introduced in netbox-community/netbox#9615). Update script to reflect those changes Signed-off-by: bia1708 --- nebula/netbox.py | 9 ++++++--- nebula/resources/template_gen.yaml | 2 +- nebula/usbmux.py | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/nebula/netbox.py b/nebula/netbox.py index 5941b37a..7b864f7c 100644 --- a/nebula/netbox.py +++ b/nebula/netbox.py @@ -299,12 +299,15 @@ def __init__( # noqa: C901 self.data["devices"].update({"power_ports": dict()}) for pow in pow_raw: # get associated oulet - outlet_id = pow["connected_endpoint"]["id"] + outlet_id = pow["connected_endpoints"][0]["id"] outlet = self.nbi.get_power_outlets(id=outlet_id) - pow["connected_endpoint"]["outlet"] = outlet[0]["custom_fields"]["outlet"] + outlet_number = outlet[0]["custom_fields"]["outlet"] + pow["connected_endpoints"][0]["outlet"] = outlet_number # get ip of pdu - pdu_raw = self.nbi.get_devices(id=pow["connected_endpoint"]["device"]["id"]) + pdu_raw = self.nbi.get_devices( + id=pow["connected_endpoints"][0]["device"]["id"] + ) pow["pdus"] = list() for pdu in pdu_raw: pow["pdus"].append(pdu) diff --git a/nebula/resources/template_gen.yaml b/nebula/resources/template_gen.yaml index 33de488c..cff3051d 100644 --- a/nebula/resources/template_gen.yaml +++ b/nebula/resources/template_gen.yaml @@ -113,7 +113,7 @@ pdu-config: help: "Outlet number on PDU for dev board" optional: True type: int - netbox_field: devices.power_ports.input.connected_endpoint.outlet + netbox_field: devices.power_ports.input.connected_endpoints[0].outlet field_4: name: username default: "username" diff --git a/nebula/usbmux.py b/nebula/usbmux.py index ca02050b..1998ca0b 100644 --- a/nebula/usbmux.py +++ b/nebula/usbmux.py @@ -83,6 +83,8 @@ def find_muxed_sdcard(self): time.sleep(5) context = pyudev.Context() for device in context.list_devices(subsystem="block"): + print("WHAT") + print(device.get("ID_SERIAL_SHORT")) if device.get("ID_SERIAL_SHORT") == os.path.basename( self._mux_in_use ).strip("id-"):