With the REST API, how do I create and add a device to a device bay at the same time? #18649
Replies: 3 comments
-
Did you ever figure this out? I am currently trying to get this to work with postman but I cannot get anything to work... |
Beta Was this translation helpful? Give feedback.
-
I created python scripts to create the device and then use call to add the modules to the device. This might be your only option, unless some one else has a better idea. I have my scripts that I created functions with in the script then I can call them as needed |
Beta Was this translation helpful? Give feedback.
-
Hi @deliciouslytyped! You need to create child device and create device bay. # Create device (with child device type)
new_device = self.nb.dcim.devices.create(device_data)
# Create device bay and assign child device to parent device
new_device_bay = self.nb.dcim.device_bays.create(
"name": "BAY-01",
"device": 5 # parent device id
"installed_device": 8 # child device id
) |
Beta Was this translation helpful? Give feedback.
-
With the (REST) API, is there a way to create a device and have it be assigned to a parent device bay at the same time? - or do I have to create the device and then assign it to a bay later? (I assume the same applies to modules.)
If this isn't possible, then it's not sufficient to use create operations to set up a configuration from a clean slate. Update operations are needed because first, device bays are created from device templates that have device bay components added to them.
This makes it messier to try to set up netbox from a prerendered configuration and makes it harder to make things look declarative.
The device bulk import page has
device_bay — name Device bay in which this device is installed (for child devices)
as a field, but I don't remember if that actually works. And that's not what the API looks like.Edit: ...Oh, hm... I guess this is a problem with any kind of component that is instantiated from device template components.
Beta Was this translation helpful? Give feedback.
All reactions