Skip to content

Commit

Permalink
netbox.py: Update script to support latest Netbox
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bia1708 committed Oct 18, 2024
1 parent 83bf5ee commit ebe2251
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions nebula/netbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion nebula/resources/template_gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions nebula/usbmux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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-"):
Expand Down

0 comments on commit ebe2251

Please sign in to comment.